Java Mission Control & Java Flight Recorder

Last year, I got two opportunities to talk about Java Mission Control & Java Flight Recorder.

I first talked about "Using Java Mission Control & Java Flight Recorder" as an internal tech talk at WSO2. I must thank Srinath for giving me that opportunity.

After that, Prabath also invited me to do a talk at Java Colombo Meetup. Prabath, Thank you for inviting me and giving me the opportunity to talk at the Java Colombo Meetup!

I'm also very excited to see that Marcus Hirt, the Team Lead for Java Mission Control has mentioned about the Java Colombo Meetup in his blog post: "My Favourite JMC Quotes". It's so nice to see "Sri Lanka" was mentioned in his blog post! :)

Not to mention that there were recently JMC presentations from Houston to Sri Lanka.
From Marcus' Blog

Here are the slides used at the meetup.




Marcus Hirt's blog posts really helped me to understand JMC & JFR concepts and his tutorials were very helpful for the demonstrations.

In this blog post, I want to note down important instructions on using JFR and other tools.

Java Experimental Tools


I first started the talk by mentioning the various tools provided in the JDK.

Examples of using some Monitoring Toolsjstat

# List java processes.
jps

# Print a summary of garbage collection statistics.
jstat -gcutil <pid>

Examples of using some Troubleshooting Tools: jmap, jhat, jstack

# Print a summary of heap
sudo jmap -heap <pid>

# Dump the Java heap in hprof binary format
sudo jmap -F -dump:format=b,file=/tmp/dump.hprof <pid>

# Analyze the heap dump
jhat /tmp/dump.hprof

# Print java stack traces
jstack <pid>


Java Flight Recorder


We need to use following options to enable Java Flight Recorder.

-XX:+UnlockCommercialFeatures -XX:+FlightRecorder

To produce a Flight Recording from the command line, you can use “- XX:StartFlightRecording” option. For example

-XX:StartFlightRecording=delay=20s,duration=60s,name=Test,filename=recording.jfr,settings=profile

The relevant settings are in $JAVA_HOME/jre/lib/jfr.

Note that above command will start a "Time Fixed Recording"

You can also use following to change log levels in JFR.


-XX:FlightRecorderOptions=loglevel=info

Use the default recording option to start a "Continuous Recording"

-XX:FlightRecorderOptions=defaultrecording=true

Default recording can be dumped on exit. Only the default recording can be used with the dumponexit and dumponexitpath parameters.

-XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true,dumponexitpath=/tmp/dumponexit.jfr

The "jcmd" command


The "jcmd" is a JVM Diagnostic Commands tool. This is a very useful command and we can send various diagnostics commands to a java process.

# View Diagnostic Commands
jcmd <pid> help

As you can see, we can use this "jcmd" command to start a flight recording

# Start Recording
jcmd <pid> JFR.start delay=20s duration=60s name=MyRecording filename=/tmp/recording.jfr settings=profile

#Check recording
jcmd <pid> JFR.check

#Dump Recording
jcmd <pid> JFR.dump filename=/tmp/dump.jfr name=MyRecording 

Comments

Popular posts from this blog

Specifying a custom Event Settings file for Java Flight Recorder

Flame Graphs with Java Flight Recordings

Java CPU Flame Graphs