Skip to main content

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

Finding how many processors

I wanted to find out the processor details in my laptop and I found out that there are several ways to check. For example, see The RedHat community discussion on  Figuring out CPUs and Sockets . In this blog post, I'm listing few commands to find out details about CPUs. I'm using Ubuntu in my Lenovo ThinkPad T530 laptop and following commands should be working any Linux system. Display information about CPU architecture $ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 58 Model name: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz Stepping: 9 CPU MHz: 1199.988 CPU max MHz: 3600.0000 CPU min MHz: 1200.0000 BogoMIPS: 5787.1...

Flame Graphs with Java Flight Recordings

Flame Graphs Brendon D. Gregg , who is a computer performance analyst , has created  Flame Graphs to visualize stack traces in an interactive way. You must watch his talk at USENIX/LISA13 , titled Blazing Performance with Flame Graphs , which explains Flame Graphs in detail. There can be different types of flame graphs and I'm focusing on  CPU Flame Graphs  with Java in this blog post. Please look at the Flame Graphs Description  to understand the Flame Graph visualization. CPU Flame Graphs and Java Stack Traces As  Brendon  mentioned in his talk, understanding why CPUs are busy is very important when analyzing performance.  CPU Flame Graphs  is a good way to identify hot methods from sampled stack traces. In order to generate CPU Flame Graphs for Java Stack Traces , we need a way to get sample stack traces. Brendon has given examples to use jstack  and Google's lightweight-java-profiler . Please refer to his perl program on g...