In my previous post on heap histograms, I missed another way to view histogram. Thanks to Alan Bateman for pointing out the same in his comment! Here it is:
The fifth way! Use the heapViewer demo JVM TI agent shipped with JDK.
On Windows:
java -agentpath:%JAVA_HOME%\demo\jvmti\heapViewer\lib\heapViewer.dll MainClass
On Unix:
java -agentpath:$JAVA_HOME/demo/jvmti/heapViewer/lib/libheapViewer.so MainClass
where JAVA_HOME is the directory where your JDK is installed. This heapViewer agent prints histogram whenever SIGQUIT signal is sent to the Java process or when the Java process exits (normal exit or Ctrl-C). Sample output of the heapViewer agent is in this blog entry by Alan.
You can look at the source code of this heapViewer agent under $JAVA_HOME/demo/jvmti/heapViewer/src directory. If you want to learn about JVM TI agents, you may want to read Kelly's blog on agents.
If you sort the classes and counts by descending count then you end up with a class-wise histogram. Does this qualify as a 6th way :-)
Posted by Alan on February 17, 2006 at 09:46 PM IST #
Posted by A. Sundararajan on February 18, 2006 at 09:19 PM IST #