Tool for creating reports from Java Flight Recorder dumps

Overview

jfr-report-tool

Build Status

Tool for creating reports from Java Flight Recorder dumps.

Influenced by https://github.com/chrishantha/jfr-flame-graph . Kudos to @chrishantha for the great work.

Uses Java Flight Recorder internal API to read JFR dump files.

Uses flamegraph.pl from FlameGraph for creating flamegraphs in SVG format.

Requirements

JAVA_HOME environment variable must point to Oracle JDK 1.7.0_40+.

Usage with provided shell script (requires bash)

./jfr-report-tool [dump_file.jfr]

The script will build the tool on first access using ./gradlew shadowJar command. It will also use curl to download flamegraph.pl if it's not available on PATH.

usage: jfr-report-tool [-abcdefghilmnorsw] [jfrFile]
 -a,--action <action>                   Tool action. Valid choices:
                                        flameGraph, stacks, topframes,
                                        dumpinfo, recordtypes
    --allocations                       Allocation flamegraph
 -b,--begin <seconds>                   Begin time
 -c,--cutoff <pattern>                  Cut off frame pattern
 -d,--duration <seconds>                Duration of time window, splits
                                        output in to multiple files
 -e,--exclude <filter>                  Regexp exclude filter for methods
 -f,--first-split                       First window duration half of
                                        given duration
    --flamegraph-command <cmd>          flamegraph.pl path
 -g,--grep <filter>                     Regexp to include all stacks with
                                        match in any frame
 -h,--help                              Help
 -i,--include <filter>                  Regexp include filter for methods
 -l,--length <seconds>                  Length of selected time
 -m,--min <value>                       Minimum number of samples
    --min-samples-frame-depth <value>   Minimum samples sum taken at frame
                                        depth
 -n,--no-compress                       Don't compress package names
 -o,--output <file>                     Output file
 -r,--reverse                           Process stacks in reverse order
 -s,--sort                              Sort frames
 -w,--width <pixels>                    Width of flamegraph
Supported actions:
flameGraph                       creates flamegraph in svg format, default action
stacks                           creates flamegraph input file
topframes                        shows top methods
dumpinfo                         dump info
recordtypes                      dump record types

Examples

Flamegraph

This creates a file jfr_dump_file.jfr.svg that is the flamegraph in SVG format. SVG files can be opened with most web browsers.

./jfr-report-tool jfr_dump_file.jfr

Disabling default filtering

./jfr-report-tool -e none -m 1 jfr_dump_file.jfr

By default, the tool removes all methods matching ^(java\.|sun\.|com\.sun\.|org\.codehaus\.groovy\.|groovy\.|org\.apache\.) so that you can view hotspots in your own code. Use "-e none" to disable method filtering. By default, all stacks with 1 or 2 samples will be filtered. You can disable this be setting the min parameter to 1.

Allocations flamegraph

To visualize allocations, there is a new feature to render a flamegraph where each stacktrace is weighted with the allocation size made in each method. It uses the JFR java/object_alloc_in_new_TLAB and java/object_alloc_outside_TLAB events to get allocation data. These events are enabled when using settings=profile in FlightRecorderOptions.

See Allocation Profiling in Java Mission Control blog post for explanation of the events.

Note that we, in the case of the (inside) TLAB allocation events, are not emitting an event for each and every location – that would be way too expensive. We are instead creating an event for the first allocation in a new TLAB. This means that we get a sampling of sorts of the thread local allocations taking place.

Since java/object_alloc_in_new_TLAB only capture the first allocation in a new TLAB, the events won't show all allocations. It's possible to pass -XX:-UseTLAB to record all allocations, but this adds a lot of overhead to JFR profiling.

example of visualizing allocations with a flamegraph

./jfr-report-tool --allocations jfr_dump_file.jfr

Java Flight Recorder

Enabling Java Flight Recorder

Add these JVM startup parameters

-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:FlightRecorderOptions=stackdepth=1024

Use this FlightRecorderOptions parameter to start recording from the start and create a dump on exit to the current directory:

-XX:FlightRecorderOptions=defaultrecording=true,settings=profile,disk=true,maxsize=500M,stackdepth=1024,dumponexit=true

This uses $JAVA_HOME/jre/lib/jfr/profile.jfc settings which has method sampling enabled.

Controlling Java Flight Recorder at runtime from command line

jcmd is used to control JFR.

Help for all jcmd commands:

jcmd <PID> help

You can use jps to find the process id (PID) of the java process you want to profile.

The available commands are JFR.stop, JFR.start, JFR.dump, JFR.check

Help for JFR.start

jcmd <PID> help JFR.start

Creating a recording by jcmd

starting recording with setting from $JAVA_HOME/jre/lib/jfr/profile.jfc

jcmd <PID> JFR.start name=myrecording settings=profile

dumping to file and continuing recording

jcmd <PID> JFR.dump name=myrecording filename=$PWD/mydump.jfr

Customizing profiling settings

It's recommended to create a custom JFR settings file with highest sampling rate (10ms). profiling.jfc example. You can use the Java Mission Control UI to edit JFR setting files. The feature is called "Java Flight Recording Template Manager".

Controlling Java Flight Recorder at runtime from graphical user interface

Use jmc command to start the Java Mission Control UI. The UI can be used to do recordings.

You might also like...

Java Agent for Memory Measurements

Overview Jamm provides MemoryMeter, a Java agent for all Java versions to measure actual object memory use including JVM overhead. Use To use MemoryMe

Dec 28, 2022

Log analyser / visualiser for Java HotSpot JIT compiler. Inspect inlining decisions, hot methods, bytecode, and assembly. View results in the JavaFX user interface.

JITWatch Log analyser and visualiser for the HotSpot JIT compiler. Video introduction to JITWatch video Slides from my LJC lightning talk on JITWatch

Jan 3, 2023

Java monitoring for the command-line, profiler included

jvmtop is a lightweight console application to monitor all accessible, running jvms on a machine. In a top-like manner, it displays JVM internal metri

Jan 6, 2023

PerfJ is a wrapper of linux perf for java programs.

PerfJ is a wrapper of linux perf for java programs.

PerfJ PerfJ is a wrapper of linux perf for java programs. As Brendan Gregg's words In order to profile java programs, you need a profiler that can sam

Jan 2, 2023

OOM diagnostics for Java.

Polarbear A tool to help diagnose OutOfMemoryError conditions. Polarbear helps track down the root cause of OutOfMemoryError exceptions in Java. When

May 14, 2019

Inline raw ASM instructions in Java

asm-inline At first I thought: Oh, I can make an optimization transformer for Proguard And then this happened. Example: public class Test { public

Dec 8, 2022

Some utility classes around java records

record-util Some utility classes around java records On the menu MapTrait Transform any record to a java.util.Map just by implementing the interface M

Apr 6, 2022

Terminal UI JMX (Java management extension) viewer

Terminal UI JMX (Java management extension) viewer

JMXViewer Terminal UI JMX (Java management extension) viewer Usage java -jar jmxviewer.jar [pid] The PID is optional. If it is not provided, the appli

Sep 15, 2022

The Java agent for Apache SkyWalking

Apache SkyWalking Java Agent SkyWalking-Java: The Java Agent for Apache SkyWalking, which provides the native tracing/metrics/logging abilities for Ja

Jan 5, 2023
Owner
Lari Hotari
My passion is to assist others to tame complexity and make great impacts.
Lari Hotari
Get Method Sampling from Java Flight Recorder Dump and convert to FlameGraph compatible format.

Note: Travis has removed the support for Oracle JDK 8. Therefore the build status is removed temporarily. Converting JFR Method Profiling Samples to F

M. Isuru Tharanga Chrishantha Perera 248 Dec 16, 2022
Generate flame graph in HTML format from jfr(Java Flight Recorder) file

jfr-flamegraph-generator Generate Flame Graph from .jfr file. Get Started Executable jar and executable binary for Linux, Windows and macOS are provid

Lawrence Ching 3 Sep 22, 2022
Simple, Scalable. Trace-Recorder is a trace recorder.

Trace-Recorder It's Scalable. Simple, Scalable, High-Powered. Trace-Recorder is a trace recorder, mainly in order to better record the source code flo

WangCai 40 Dec 24, 2022
BTrace - a safe, dynamic tracing tool for the Java platform

btrace A safe, dynamic tracing tool for the Java platform Version 2.1.0 Quick Summary BTrace is a safe, dynamic tracing tool for the Java platform. BT

btrace.io 5.3k Jan 9, 2023
A java agent to generate method mappings to use with the linux `perf` tool

perf-map-agent A java agent to generate /tmp/perf-<pid>.map files for just-in-time(JIT)-compiled methods for use with the Linux perf tools. Build Make

null 1.5k Jan 1, 2023
JVM Explorer is a Java desktop application for browsing loaded class files inside locally running Java Virtual Machines.

JVM Explorer JVM Explorer is a Java desktop application for browsing loaded class files inside locally running Java Virtual Machines. Features Browse

null 109 Nov 30, 2022
A Java agent that rewrites bytecode to instrument allocation sites

The Allocation Instrumenter is a Java agent written using the java.lang.instrument API and ASM. Each allocation in your Java program is instrumented;

Google 438 Dec 19, 2022
Java memory allocation profiler

Aprof - Java Memory Allocation Profiler What is it? The Aprof project is a Java Memory Allocation Profiler with very low performance impact on profile

Devexperts 211 Dec 15, 2022
Sampling CPU and HEAP profiler for Java featuring AsyncGetCallTrace + perf_events

async-profiler This project is a low overhead sampling profiler for Java that does not suffer from Safepoint bias problem. It features HotSpot-specifi

null 5.8k Jan 3, 2023
Fork of tagtraum industries' GCViewer. Tagtraum stopped development in 2008, I aim to improve support for Sun's / Oracle's java 1.6+ garbage collector logs (including G1 collector)

GCViewer 1.36 GCViewer is a little tool that visualizes verbose GC output generated by Sun / Oracle, IBM, HP and BEA Java Virtual Machines. It is free

null 4.1k Jan 4, 2023