[HOWTO] Use Java Mission Control 5.2 with jruby 1.6.x and 1.7.x

Hi,

If you’ve installed JDK 7u40, it has Oracle Java Mission Control 5.2
bundle
in it. The following HOWTO works only with this JDK, not on a JRE. I’ve
tested it on Win7 Enterprise, but it should definitely work on linux
too!

JMC (in short) can be used as a monitoring system live (like jvisualvm)
but
has a more interesting feature, allowing you to monitor and save a
‘flight
record’ even without starting jmc.

In order to do so, please add the following 3 options to JRUBY_OPTS:

-J-XX:+UnlockCommercialFeatures -J-XX:+FlightRecorder
-J-XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true

And start the script you wish to monitor. The overhead of creating the
flight record report is supposed to be ~2%. I did not measure it on my
system, but it’s definitely low.

For Windows users, you can create such a script to add temporarily the 3
needed options without polluting your JRUBY_OPTS generic settings:

@echo off
setlocal
set JRUBY_OPTS=-J-XX:+UnlockCommercialFeatures -J-XX:+FlightRecorder
-J-XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true
%JRUBY_OPTS%
jruby %1
endlocal

Once the script has completed, in the same directory containing the
jruby
script you monitored, you’ll get a file like this
one: hotspot-2013_10_08_07_48_58.jfr

Next steps are very simple: start JMC (type ‘jmc’ on your prompt,
provided
you configured the JDK path properly), then use the JMC menus to open
the
above mentioned *.jfr file.

You’ll get a nice dashboard view, allowing (even days later or on a
different machine) you to monitor the cpu, memory, gc, classes, etc…
metrics saved during that particular run.

Hope this small HOWTO will help you detecting code or memory
bottlenecks.

BR,
Christian