- Red Hat Enterprise Linux (RHEL)
- Red Hat build of OpenJDK
- OpenJDK 8 u262+
- OpenJDK 11
- How to use JDK Flight Recorder ?
- Heap dump can not be provided because it contains sensitive information.
- Heap dump from a production system can not be provided due to application performance impact.
JDK Flight Recorder (JFR) is a diagnostic and profiling tool for a running Java application.
Use one of the three approaches below, either at the start of the process with it, or using java diagnostics (jcmd), or via JMX client (Cryostat):
First option: Enable recording and specify recording options with the following JVM options when starting the application:
To specify a full path to the jfr recording (e.g.
Second option: Start/Stop the recording with Java Diagnostic tool (
$ jcmd PID JFR.start filename=flight.jfr
This will start a recording called flight.jfr without limit of duration so use jcmd JFR.stop to stop the recording
Third option: For instance on OCP, use JMX on JMC or Cryostat Operator (via cryostat CRD) to attach.
|JFR.check||Check the status of all recordings running for the specified process, including the recording identification number, file name, duration, and so on.|
|JFR.stop||Stop a recording with a specific identification number (by default, recording 1 is stopped).|
|JFR.dump||Dump the data collected so far by the recording with a specific identification number (by default, data from recording 1 is dumped)|
jcmd PID help for a list of commands. For example:
$ jcmd 12345 help | grep JFR JFR.check JFR.configure JFR.dump JFR.start JFR.stop
jcmd help on command
jcmd PID help to get more information on a command. For example:
$ jcmd 123456 help JFR.start 123456: JFR.start Starts a new JFR recording Impact: Medium: Depending on the settings for a recording, the impact can range from low to high. Permission: java.lang.management.ManagementPermission(monitor) Syntax : JFR.start [options] Options: (options must be specified using the <key> or <key>=<value> syntax) name : [optional] Name that can be used to identify recording, e.g. \"My Recording\" (STRING, no default value) settings : [optional] Settings file(s), e.g. profile or default. See JRE_HOME/lib/jfr (STRING SET, no default value) delay : [optional] Delay recording start with (s)econds, (m)inutes), (h)ours), or (d)ays, e.g. 5h. (NANOTIME, 0) duration : [optional] Duration of recording in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 300s. (NANOTIME, 0) disk : [optional] Recording should be persisted to disk (BOOLEAN, no default value) filename : [optional] Resulting recording filename, e.g. \"/home/user/My Recording.jfr\" (STRING, no default value) ...
Limit the duration
To limit the duration of the recording, to for 4 hours for example, use run:
$JAVA_HOME/bin/jcmd $JBOSS_PID JFR.start duration=4h
- The flag
FlightRecorderis unnecessary after 8u240 JDK-8225312 and the record can be done without it.
- The flag
UnlockCommercialFeaturesis also unnecessary when recording flight recording data.
- The flag
FlightRecorderOptions=maxagewas deprecated. Use
StartFlightRecording=maxageinstead. Be careful with
StartFlightRecordingdepending on the JDK version.
Increasing fidelity of JFR
The flag DebugNonSafepoints can be used to increase/improve the profiler data, however it must be combined with
Example usage for JDK 11:
For JDK 11 (or JDK 1.8.240+) it is not required to use the flags
UnlockCommercialFeatures one can just start a process and record, full example below:
#start java process $ export JAVA_HOME=/path/java-11-openjdk-22.214.171.124.7-0.portable.jdk.el.x86_64 $ ./bin/standalone.sh <--------------- eap for example #jcmd to get PID $ ./jcmd 28416 /PATH/jboss-eap-7.4/jboss-modules.jar -mp /path/jboss-eap-7.4/modules org.jboss.as.standalone -Djboss.home.dir=/jboss-eap-7.4 -Djboss.server.base.dir=/jboss-eap-7.4/standalone 28608 jdk.jcmd/sun.tools.jcmd.JCmd #start $ ./jcmd PID JFR.start filename=/path/flight.jfr PID: Started recording 1. No limit specified, using maxsize=250MB as default. Use jcmd PID JFR.dump name=1 to copy recording data to file. <----- use this name to stop it #check $ ./jcmd PID JFR.check 23735: Recording 1: name=1 maxsize=250.0MB (running) #dump $ ./jcmd PID JFR.dump filename=/path/flight.jfr 23735: Dumped recording, 1.1 MB written to: /path/flight.jfr # stop $ ./jcmd 23735 JFR.stop name=1 <------------------ name 1 == default 23735: Stopped recording "1".
JFR has very low overhead (normally < 1%) because it's built into the runtime (c/c++ code). The default settings are suitable for both development and production environments.
jcmdshould be run as the same user as the Java process. Running
LOCAL SYSTEMaccount and JFR as the currently logged in user will result in an "Insufficient Privileges" error. Use the PsExec Tool from Microsoft to escalate to the proper user.
Depending on the option required, the usage of
StartFlightRecordingis preferred than
Use Java Mission Control (
jmc) to analyze the data from the
jmc is included in the Windows distro (
JAVA_HOME/missioncontrol portable build,
C:\jdk\missioncontrol msi install) and is available as a separate rpm on RHEL.
- Performance tune
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.