com.yourkit.api
Class MemorySnapshot

java.lang.Object
  extended by com.yourkit.api.MemorySnapshot

public final class MemorySnapshot
extends java.lang.Object

The class supports analysis of captured memory snapshots.


Constructor Summary
MemorySnapshot(java.io.File snapshotFile)
          Loads memory snapshot for analysis.
MemorySnapshot(java.io.File snapshotFile, ObfuscatorType obfuscatorType, java.io.File obfuscationLog)
          Loads memory snapshot for analysis, automaticaly restoring obfuscated class, method and field names.
 
Method Summary
 void dispose()
          Deprecated. This method does nothing and must not be called. Allocated resources are released in the finalizer.
 int getObjectCount(java.lang.String xmlSetDescription)
          Calculates number of objects that correspond to the given description.
 long getShallowSize(java.lang.String xmlSetDescription)
          Calculates shallow size of objects that correspond to the given description.
 void saveIndexFile()
           Save snapshot index file (read about snapshot index in the Help.)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemorySnapshot

public MemorySnapshot(java.io.File snapshotFile)
               throws java.lang.Exception
Loads memory snapshot for analysis.

Throws:
java.lang.Exception - if snapshot cannot be loaded for some reason

MemorySnapshot

public MemorySnapshot(java.io.File snapshotFile,
                      ObfuscatorType obfuscatorType,
                      java.io.File obfuscationLog)
               throws java.lang.Exception
Loads memory snapshot for analysis, automaticaly restoring obfuscated class, method and field names.

Parameters:
snapshotFile - memory snapshot file to be loaded
obfuscatorType - obfuscator type; if profiled application was not obfuscated, specify ObfuscatorType.NONE or use constructor with one parameter MemorySnapshot(File) instead.
obfuscationLog - obfuscation log file created obfuscating the profiled application; if obfuscatorType is ObfuscatorType.NONE, specify null.
Throws:
java.lang.Exception - if snapshot cannot be loaded for some reason
Method Detail

getObjectCount

public int getObjectCount(java.lang.String xmlSetDescription)
                   throws java.lang.Exception
Calculates number of objects that correspond to the given description. For example

getObjectCount("<objects class=\"java.lang.Strings\">")

returns number of Strings in the snapshot. Please refer to the Help for details on object set description language.

Throws:
java.lang.Exception

dispose

public void dispose()
             throws java.lang.Exception
Deprecated. This method does nothing and must not be called. Allocated resources are released in the finalizer.

Throws:
java.lang.Exception

getShallowSize

public long getShallowSize(java.lang.String xmlSetDescription)
                    throws java.lang.Exception
Calculates shallow size of objects that correspond to the given description. For example

getShallowSize("<objects class=\"java.lang.Object\"/>")

returns size of all objects in the snapshot.
The second example shows calculation of memory retained by all strings:

    getShallowSize(
      "<retained-objects>" +
      "<objects class=\"java.lang.String\"/>" +
      "</retained-objects>"
    )
 

Please refer to the Help for details on object set description language.

Throws:
java.lang.Exception

saveIndexFile

public void saveIndexFile()
                   throws java.lang.Exception

Save snapshot index file (read about snapshot index in the Help.)

The index file will be created in the same directory as the snapshot file, and its name will be formed from the snapshot file name with ".index" postfix added.

For example:
Snapshot file name: foo.snapshot -- index file name: foo.snapshot.index
Snapshot file name: bar.hprof -- index file name: bar.hprof.index

If the index file already exists, it will be overwritten.

Make sure the directory where snapshot is located is writeable and there is enough disk space (the index size can be comparable with the size of the snapshot.)

Throws:
java.lang.Exception - java.lang.Exception if index file cannot be saved for some reason


Copyright © 2003-2010 YourKit, LLC. All Rights Reserved.