Java – JVM calltree snapshot for VisualVM

javajvmvisualvm

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 (http://java.sun.com/developer/technicalArticles/Programming/HPROF.html) 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) http://www.yourkit.com/docs/80/help/additional_agent_options.jsp

Programmatically http://www.yourkit.com/docs/80/api/index.html

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 https://japex.dev.java.net/ around your core code ?