sip-of-java

View the Project on GitHub wkorando/sip-of-java

JDK Flight Recorder

The JDK Flight Recorder, open sourced in JDK 11 (JEP 328), is a lightweight HotSpot JVM tool for collecting diagnostic and profiling data about a Java application and the HotSpot JVM.

Using JFR

To use JFR you need to set the -XX:StartFlightRecording JVM argument, like in the example below:

java -XX:StartFlightRecording=disk=true,filename=recording.jfr,settings=profile,dumponexit=true <application>

Configuring JFR

When enabling JFR, -XX:StartFlightRecording can take several arguments like seen above that modify its behavior, below is the full list of arguments can take:

        recording.jfr
        /home/user/recordings/recording.jfr
        c:\recordings\recording.jfr

Source: https://docs.oracle.com/en/java/javase/16/docs/specs/man/java.html

Retrieving JFR Recordings

There are a couple of options for retrieving JFR recordings

From Running Application

Recordings can be retrieved from a still running Java application using jcmd like this:

jcmd <pid> JFR.dump name=<name>

After Application Terminates

JFR can also automatically generate a recording file on application exit by setting 1 dumponexit=true with -XX:StartFlightRecording

Analyzing JFR Recordings

JFR recordings can be inspected with tools like JDK Mission Control.

JDK Mission Control offers many options for inspecting results; memory usage, I/O, GC behavior, and more, which can be seen here:

Picture of the many views that JDK mission control offers for inspecting JFR recordings

Further Learning

Video: Monitoring and Troubleshooting Tools in the JDK with Poonam Parhar

Inside Java Podcast: “JDK Flight Recorder” with Markus Grönlund

Official Documentation: JDK Mission Control

More: https://inside.java/tag/jfr

Happy Coding!