Java Flight Recorder Cheat Sheet

This story lists various ways to get Java Flight Recordings. This is basically a shortened form of my “Using Java Flight Recorder” story.

Java Flight Recorder Options

Start a Profiling Recording, which is a Time Fixed Recording with profile settings

-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=delay=10s,duration=10m,name=Profiling,filename=recording.jfr,settings=profile -XX:FlightRecorderOptions=loglevel=info

Start a Time Fixed Recording with default settings

-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=delay=10s,duration=10m,name=Default,filename=recording.jfr,settings=default -XX:FlightRecorderOptions=loglevel=info

Start a Continuous Recording (The Default Recording)

-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,repository=/tmp,maxage=2h,loglevel=info

The Default Recording with Dump on Exit

-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,repository=/tmp,maxage=2h,dumponexit=true,dumponexitpath=dumponexit.jfr,loglevel=info

Java Flight Recorder using Diagnostic Commands

The “jcmd” utility in JDK is used to send diagnostic command requests to the JVM. For example:

jcmd <process id/main class> <command> [options]

In following commands, <process id/main class> is replaced with <p>.

Note: It’s recommended to add -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints flags to improve the accuracy of JFR Method Profiler

Help command

jcmd <p> help

Dynamically Enable JFR from diagnostic commands (Since Java 8 update 40)

jcmd <p> VM.unlock_commercial_features

If this is command is not working, you have to use -XX:+UnlockCommercialFeatures -XX:+FlightRecorder flags.

Start a Profiling Recording, which is a Time Fixed Recording with profile settings

jcmd <p> JFR.start settings=profile delay=10s duration=10m name=Profiling filename=recording.jfr

Start a Time Fixed Recording with default settings

jcmd <p> JFR.start settings=default delay=10s duration=10m name=Default filename=recording.jfr

Start a Continuous Recording (The Default Recording)

jcmd <p> JFR.start defaultrecording=true

Check running Java Flight Recordings

jcmd <p> JFR.check

Dump named Flight Recording

jcmd <p> JFR.dump name=Profiling filename=profiling.jfr

Dump Flight Recording using recording number

Find the recording number using JFR.check.

jcmd <p> JFR.dump recording=1 filename=profiling.jfr

Dump the Default Recording

jcmd <p> JFR.dump recording=0 filename=default.jfr

Stop a recording

using the name

jcmd <p> JFR.stop name=Profiling

or using recording number

jcmd <p> JFR.stop recording=1

Stop the Default Recording

jcmd <p> JFR.stop recording=0