JFR Configuration ImprovementsBilly Korando on June 13, 2022
JDK Flight Recorder, JFR, is an event-based diagnostic and profiling tool built into the JDK! JFR can provide detailed information on both what is happening in your application and in the JVM itself. This can be a great way to debug issues and find ways to improve performance. However, the data JFR is returning might not always match your needs. Luckily, JFR is highly configurable, and several changes introduced in JDK 17 have made configuring JFR easier than ever.
Added in JDK 17 was a new interactive wizard that can walk you through creating a new JFR configuration file (
.jfc). To start the wizard, run
jfr configure --interactive from a terminal. This starts a guided 12-step process for creating a new configuration. The prompts guide what the default collection profile looks like, as well as the potential performance impacts of increasing the amount of data collected:
============== .jfc Configuration Wizard ============ This wizard will generate a JFR configuration file by asking 12 questions. Press ENTER to use the default value, or type Q to abort the wizard. Garbage Collector: Normal (default) 1. Off 2. Normal 3. Detailed 4. High, incl. TLABs/PLABs (may cause many events) 5. All, incl. Heap Statistics (may cause long GCs)
Submitting Configurations Directly
For newer users of JFR, the interactive wizard can be helpful, but for more advanced users, walking through a 12-step process might be a burden, especially if you are only interested in changing a few settings. Luckily you can pass configuration values directly:
jfr configure <configuration values>
Values not provided will be set to the default.
If you need help using
jfr configure, run
jfr configure help for a help message to be printed to the console.
Configuring and Adding Events
Individual events can be configured, as well as custom events added.
To configure an event, you’d reference the event name,
# the field to change, and the value to set it to, like in the example below:
jfr configure jdk.JavaMonitorEnter#threshold=1ms
If you want to add and configure a custom JFR event, append the above with a
jfr configure +my.events.MyEvent#threshold=1ms
Configuring with -XX:StartFlightRecording
You can also set these configurations at JVM startup with
-XX:StartFlightRecording, like in these examples below:
$ java -XX:StartFlightRecording:allocation-profiling=high $ java -XX:StartFlightRecording:+com.company.HttpGetRequest#enabled=true
Note that the JFR target of <1% overhead was measured using JFR’s default settings. Changing the configuration of JFR can lead to increased overhead.