org.eclipse.mat.snapshot.query
Class PieFactory

java.lang.Object
  extended by org.eclipse.mat.snapshot.query.PieFactory

public final class PieFactory
extends java.lang.Object

Helper class to create pie chart results for heap objects.

Usage:

 public class PieQuery implements IQuery
 {
     @Argument
     public ISnapshot snapshot;
 
     public IResult execute(IProgressListener listener) throws Exception
     {
         PieFactory f = new PieFactory(snapshot);
 
         int[] topDominators = snapshot.getImmediateDominatedIds(-1);
 
         for (int ii = 0; ii < 5 && ii < topDominators.length; ii++)
             f.addSlice(topDominators[ii]);
 
         return f.build();
     }
 
 }
 

Since:
0.8

Constructor Summary
PieFactory(ISnapshot snapshot)
          Create a pie factory for the given snapshot.
PieFactory(ISnapshot snapshot, long pieSize)
          Create a pie factory for the given snapshot.
PieFactory(long pieSize)
          Create a pie factory for objects.
 
Method Summary
 IResultPie.Slice addSlice(int objectId)
          Create and add a new slice for the given object.
 IResultPie.Slice addSlice(int objectId, java.lang.String label, long usedHeapSize, long retainedHeapSize)
          Create and add a new slice for the given object.
 IResultPie.Slice addSlice(IObject object)
          Create and add a new slice for the given object.
 IResultPie build()
          Create and return the pie result object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PieFactory

public PieFactory(ISnapshot snapshot)
Create a pie factory for the given snapshot. The size of the pie is the total heap size SnapshotInfo.getUsedHeapSize().

Parameters:
snapshot -

PieFactory

public PieFactory(ISnapshot snapshot,
                  long pieSize)
Create a pie factory for the given snapshot.

Parameters:
snapshot - snapshot containing the objects
pieSize - total size of the pie

PieFactory

public PieFactory(long pieSize)
Create a pie factory for objects. Objects must be added either via addSlice(IObject) or addSlice(int, String, long, long) methods.

Parameters:
pieSize - total size of the pie
Method Detail

addSlice

public IResultPie.Slice addSlice(int objectId)
                          throws SnapshotException
Create and add a new slice for the given object. The size of the slice is determined by the retained size.

To use this method, one needs to pass a ISnapshot to the constructor.

Parameters:
objectId - object id
Returns:
a new slice
Throws:
SnapshotException

addSlice

public IResultPie.Slice addSlice(IObject object)
Create and add a new slice for the given object. The size of the slice is determined by the retained size.

Parameters:
object -
Returns:
a new slice

addSlice

public IResultPie.Slice addSlice(int objectId,
                                 java.lang.String label,
                                 long usedHeapSize,
                                 long retainedHeapSize)
Create and add a new slice for the given object.

Parameters:
objectId - object id
label - (optionally) a label describing the object (for display)
usedHeapSize - (optionally) the used heap size (for display)
retainedHeapSize - the retained size which determines the size of the slice
Returns:
a new slice

build

public IResultPie build()
Create and return the pie result object.

Returns:
the pie result object