tags:

views:

484

answers:

5

What are some good end to end CPU profilers that exist for Java?

Quick list of things I'm looking for:

  1. Offline profiling - No user interaction or GUI required during program execution. Dumping the profile data to a file and then requiring viewing afterwards with a GUI is fine, I just don't want to have to babysit it as the job runs
  2. End to End recording - Profiler should be able to start recording immediately after entering the main call for a J2SE application. It should stop recording immediately before the JVM exits.
  3. Call graph generation - After profiling, it'd be nice to turn the data into a visual call graph.

Google has a nice profiler for C/C++ - http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html

If the Java equivalent of this exists, it'd be exactly what I'm looking for.

I'm not including HProf in my list of prospective profilers because it performs badly compared to other commercial profilers I've looked at when you use accurate CPU call profiling (Usually done via Byte Code Injection, which is slow, but HProf appears at least an order of magnitude slower than other profilers, and when a single sampling profile run takes 1-2 hours, waiting more than a day for the same run is unacceptable)

A: 

Please see my similar question.

Yuval F
I've looked over the answers in your question already, and many of them do not do what I'm looking for above. The one that I've had the best luck with so far from your question is JProfiler, but up until the most recent release, it did not have end to end snapshots for offline projects.
Tulenian
+2  A: 

I am not familiar with offline profiling. Isn't it what hprof is for?. Otherwise I've had very good experience with YourKit profiler.

Peter Severin
Hprof appears to have bad performance issues. I might have missed it, but I could not figure out how to do end-to-end profiling, or how to do profile on a remote machine without attaching a GUI with YourKit
Tulenian
A: 

I've been very happy with NetBeans Profiler; I believe it also satisfies all your requirements.

Michael Myers
+2  A: 

My favorite, by far, is JProfiler. I didn't realize it until just now (because I always use the interactive profiling GUI), but it does in fact support offline profiling, exactly like you described.

A few other cool features:

  • It profiles all your SQL statements, so you can see which DB queries are slowing you down.

  • It keeps track of which methods (in which classes & packages) are allocating the most memory, for which types of objects & arrays, and the longevity of those objects. So, if you're leaking memory, it's easy to track down which types of class instances are outliving their usefullness, and to find the methods where those objects were originally allocated (and who's holding the references that are keeping the objects alive).

  • You can keep track of the VM growth, monitoring the frequency of GC full collections, and determining how many objects (of which type) were freed during each collection cycle.

  • And of course, you get a hierarchical breakdown of all method invocations, with the number of calls and mean execution time (exclusive or inclusive) of the whole call stack. You can also view this hierarchy from the perspective of "worst bottleneck" functions, ordered either by execution time or memory allocation.

For me, JProfiler is one of the most important tools in my development process (second only to Eclipse).


Also: there's a free 10-day trial. Download it and check it out. And, btw, I'm not affiliated with the company or anything. I've just been a happy customer for the last five or six years.

benjismith
My only major complaint with JProfiler was that I could not do a true end-to-end snapshot with offline profiling. It appears that with their 12-17 update, they added JVM Start and JVM Exit as valid trigger targets, so I might be able to get it working now!
Tulenian
A: 

You could try the runtime analyzer that comes with JRockit Mission Control. It produces recording files that you can open up in the GUI later on. The overhead is very low, usually less than 1-2%, and it's very easy to use.

You can start a recording from the command line like this:

JROCKIT_HOME\bin>java -XXjra:recordingtime=2000s,filename=myrecording.jra,sampletime=1

and if the JVM exits, before the recording has finished, the profiling data will be flushed to disc.

Kire Haglin