Skip to content
Jie Kang edited this page May 4, 2020 · 1 revision

JFR

Intro to JDK Flight Recorder

JDK Flight Recorder manages data gathered from the JVM. Data is written in memory, first to thread local buffers and then promoted to a fixed-size global ring buffer. Traditionally, this data is eventually flushed to JFR files (*.jfr) on disk, which is then consumed for analysis, for example by JDK Mission Control. With JFR streaming (OpenJDK 14+), API is provided to access the data in the buffer.

JDK Flight Recorder has a number of options for configuration on start. For a list of options, see the Oracle java documentation

Recordings

Users manage the system’s recordings. Individual recordings have unique configuration and can be started, stopped, and dumped to disk on demand.

Continuous recordings run until the process stops. Time-fixed recordings end after their duration has elapsed.

Events

Events are the basic unit of JFR data. The JVM has pre-existing events and there is API for users to supply both static and dynamic custom events. Every event can be enabled or disabled when recording to minimize overhead.

JFR profiles (*.jfc) can be used to configure the events for a recording. The JDK distribution comes with two profiles: 'default' and 'profile'.

default: Low overhead configuration safe for continuous use in production environments, typically less than 1 % overhead.

profile: Low overhead configuration for profiling, typically around 2 % overhead.

Events & Multiple Recordings

When multiple recordings are running, each with their own event configuration, the system emits events that are the union of all event configurations. In this way, recordings may have more events than expected. There are no other negative implications.

Using JFR with OpenJDK

Starting Java processes with FlightRecording

To start a process with JFR active, run:

java -XX:StartFlightRecording
java -XX:StartFlightRecording=<options>

Options are comma delimited key-value pairs. For a list of options, see the Oracle java documentation

Using jcmd to manage recordings

Start a recording:

jcmd <pid> JFR.start <option>

Stop a recording:

jcmd <pid> JFR.stop <options>

Dump a recording:

jcmd <pid> JFR.dump <options>

Options are comma delimited key-value pairs. With command being e.g. JFR.start or JFR.stop for a list of options run:

jcmd <pid> help <command>

To see availability of jmcd commands, run

jmcd <pid> help

For more information, see Oracle jcmd documentation

Examining JFR files

Via jfr tool

The JDK comes with binary tool 'jfr' that is able to examine JFR files.

It’s documentation is straightforward, see the output of:

jfr

jfr help

Via JDK Mission Control

JDK Mission Control supports opening flight recordings (*.jfr) and provides a Flight Recorder view for the opened files.