Monday 6 August 2018

JFR: Java Flight Recorder

JFR is a tool for collecting diagnostic and profiling data about a running Java application. By using JFR, you can collect data about JVM and java application running on it.

Enabling Java Flight Recorder
By default, JFR is disabled in the JVM.

How to enable Java Flight Recorder?
Enable commercial features using -XX:+UnlockCommercialFeatures option and launch your Java application with the -XX:+FlightRecorder option.

Syntax
java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder {APPLICATION_CLASS_NAME}

Example
java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -classpath . HelloWorld

Above statement launch HelloWorld application and enables flight recorder.

How to run Java Flight Recorder?
You can run multiple recordings and each recording can have its own settings. You can get the recording data in couple of ways.
a.   At the time of launching application
b.   Using jcmd command

Specifying jfr details at the time of launching the application.
Below command collects the jfr information of the application HelloWorld.java for 60 seconds and store the information in ‘myrecordings.jfr file.

java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=60s,filename=myrecording.jfr -classpath . HelloWorld

jfr file is created like below.


Double click myrecording.jfr file.

It launches below application.



 It launches below UI, where you can analyze the jfr recording information.

In my next post, I am going to explain how to collect the JFR information using jcmd command.

Previous                                                 Next                                                 Home

No comments:

Post a Comment