Java performance profiling on Mac for free using Shark

shark.jpgI’ve evaluated a number of tools for Java performance profiling like JProfiler, YourKit, etc. which are all great, but $500 is expensive for a South African, and the Eclipse Test & Performance Tools don’t run on Mac OS X yet. So what’s a cheapskate to do? Use the free application that comes with Mac OS X 10.3+: Shark. Install it off the Apple optional installs on your DVD, then follow these instructions to get Shark to profile your JVM instead of the process itself.

1. Run your Java application with this command line added:

  • JVM 1.4: Add the following flag to your Java VM command line options: –XrunShark.
  • JVM 1.5 or later: Add the following flag to your Java VM command line options: -agentlib:Shark.

2. Start Shark at /Developer/Applications/Performance Tools/Shark
3. Select one of ‘Java Time Profile’, ‘Java Alloc Trace’, etc. in the first dropdown.

sharkrocks.jpg

4. Select your java process in the last dropdown
5. Click start and run through your program.
6. Click stop and view the analysis and be glad you haven’t coughed up $500 on a commercial tool.

More information on Sharks analysis can be found on Apple’s website.

p.s. You need to use the -XrunShark option if you want to do a Java Alloc Trace, else you get the error message “The JVM Tools Interface cannot record allocation events [JavaTraceDataSource].”

2008.02.21