Analyzing Your Application With JFR
Java Flight Recorder (JFR) is a profiling and event collection framework built into the Java Virtual Machine (JVM). With JFR, you can collect detailed runtime information about various aspects of a Java application, such as method execution, memory allocation, garbage collection, and more. This information is valuable for performance analysis, troubleshooting, and optimization of Java applications.
Making a JFR Recording
At Application Startup
To enable recording from startup of an application, use the following command-line options based on your use-case:
-XX:StartFlightRecording=dumponexit=true,disk=true,filename=/tmp/rec.jfr,duration=600s,settings=my-config.jfc
-
dumponexit=true
: Instructs JFR to save the recording upon JVM exit. Keep in mind, when you use this option, that this might impact the performance of your application. You should only use it, when you need to analyze the state of the application at the end of its execution. -
disk=true
: Indicates that the recording should be saved to disk. -
filename=/tmp/rec.jfr
: The file that will be used to store the recording. -
duration=600s
: Specifies the maximum duration for a flight recording. It determines how long the recording will continue capturing events and metrics before automatically stopping. You can use this option to limit the duration of a recording to avoid capturing an excessive amount of data and to control the impact on the application’s performance. -
settings=my-config.jfc
: By default, Flight Recorder uses the settings defined in<java_home>/lib/jfr/default.jfc
which gives a good balance between data and performance. In the same directory, you can find a second configurationprofile.jfc
which records more events and is useful while profiling an application. You can also create a copy of one these files and create your own configuration, e.g.my-config.jfc
.
From a Running Application
On the same host and userid as the Java process under analysis, run the following command to start a recording:
$ jcmd JVMID JFR.start filename=rec.jfr
Where JVMID
is either the process ID or the classname assigned with the java process as shown when running jcmd
without parameters.
To stop a recording, use:
$ jcmd JVMID JFR.stop name=1
To start a recording with more detailed metrics, use the following with extra options as explained above:
$ jcmd JVMID JFR.start filename=rec.jfr settings=profile
Analyzing a JFR Recording
JFR recordings are most easily viewed in Azul Mission Control, and you can connect to a running application from within Azul Mission Control to create a recording. More info is available in the Azul Mission Control documentation.