Java Flight Recorder
Java Flight Recorder (JFR) is a tool for collecting diagnostic and profiling data about a running Java application. It is integrated into the Java Virtual Machine (JVM) and causes almost no performance overhead, so it can be used even in production environments.
JFR is free since Java 11.
How to use JFR
JFR allows to collect performance data from a live Java process without restarting it or adding some custom configuration parameters.
To start collecting data, you need to run the following command:
jcmd 1 JFR.start duration=300s settings=profile filename=/var/lib/emberwork/recording_01.jfr
duration
specifies the duration of the recording in seconds. Recording file will be created after that time.filename
specifies the output file name. It can be any path on the machine where the process is running.settings
specifies the recording settings template. There are few templates available:default
(predefined template) - contains basic info and is expected to add less than 1% overhead.profile
(predefined template) - contains basic info and is expected to add around 2% overhead.- Custom path - a path to the "*.jfc" file with JFR settings. You can create your own template using JMC (Java Mission Control).
note
It's recommended to change recording file name to something unique (lFiike add current timestamp), otherwise it will be overwritten on the next run.
Custom JFR profile
We have created a custom JFR profile with a bit extra focus on memory usage. See it here: j11_mem_01.jfc
Usage:
- Upload it to Ember pod (if in Docker) to an accessible place like
/var/lib/emberwork/
- Run it with:
jcmd 1 JFR.start duration=300s settings=/var/lib/emberwork/j11_mem_01.jfc filename=/var/lib/emberwork/recording_01.jfr