The concept of the memory profiler is almost the same as the runtime profiler. The only difference is that you can take several snapshots of your memory during an execution.
You can extract a snapshot by using the MBean( ???)
The CPU is frozen while the snapshot is being extracted, what usually takes
Steps to extract a snapshot:
- Add jbossAgent.dll to your path or libjbossAgent.so to your LD_LIBRARY_PATH
- Add -agentlib:jbossAgent to your JVM 5 command line. (Java 5 at least is required as JVMTI was introduced on Java 5)
- Go to JMX Console (http://localhost:8080/jmx-console) and look for JBossProfiler:JVMTI MBean (mbean=JVMTIClass)
- Call heapSnapshot from JVMTIClass MBean. use P1 as a prefix, and P2 as the extension. For instance P1=/tmp/log, and P2=mem. This will create three files starting with log under /tmp, with extension=.mem
- Use the JbossProfiler application (http://localhost:8080/jboss-profiler) after you have installed jboss-profiler.war to your /deploy directory.
All the files used in the memory profiler are simple text files, CVS like.
This way you can write your own tool to analyze the snapshot generated.
tagClass – An unique count id for the class
signature – The JNI signature for the class
tagClassLoader – The unique object id for the classLoader
Example:
tagClass,signature,tagClassLoader
1,Ljava/io/BufferedWriter;,0
2,Ljava/util/Collections$ReverseComparator;,0
3,Ljava/lang/StringCoding$StringDecoder;,0
ObjectTag – The Unique Count Id of an object
ClassTag – The Unique Count Id of the declaring class for this object
Size – The size in bytes for this object
Example:
objectTag,classTag,size
1338,59,480
1339,106,88
1340,106,88
1341,106,88