Java – JVM calltree snapshot for VisualVM


I am trying to use VisualVM to profile a Java (Sun JDK 1.6) standalone application. I have a scripted performance test environment, where I can run my application and get it to report some metrics I care about.

Is there some way to get JVM to collect some CPU profiling snapshot which I can later analyze with VisualVM?

I am looking for something similar to -XX:+HeapDumpOnOutOfMemoryError flag which writes a heap dump to disk just before an OutOfMemoryError is thrown.

Best Solution

There is the hprof tool built into the JVM ( which allows you to capture basic profiling information, its dog slow and produces massive files.

VisualVM AFAIK does not yet have these abilities, but yourkit has the ability to do what you want though its agent, and programmatically.

Yourkit via agent line (-agentlib:yjpagent=onexit=snapshot)


As an aside I would suggest that you are careful with measuring CPU along with performance testing as it will definatly skew your results, have you considered looking at something like around your core code ?