Chapter 3. Memory Profiler

3.1. Concept

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

3.2. Capturing a Snapshot

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.

3.3. File formats

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.

3.3.1. Classes

  • 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

3.3.2. Objects

  • 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

3.3.3. References

  • tagReferrer – ObjectTag for the object owning a reference

  • tagReferred – ObjectTag for the object referenced

  • index – JVMTI sends this count that I didn't find any usage for this. It’s here for future usage.

Example:

tagReferrer, tagReferee,index
0,134,0
0,168,0
0,16,0
0,270,0