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


If you’ve installed JDK 7u40, it has Oracle Java Mission Control 5.2
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

JMC (in short) can be used as a monitoring system live (like jvisualvm)
has a more interesting feature, allowing you to monitor and save a
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

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
set JRUBY_OPTS=-J-XX:+UnlockCommercialFeatures -J-XX:+FlightRecorder
jruby %1

Once the script has completed, in the same directory containing the
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,
you configured the JDK path properly), then use the JMC menus to open
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