Package org.eclipse.mat.snapshot

## Class Histogram

- java.lang.Object
- - org.eclipse.mat.snapshot.HistogramRecord
  - - org.eclipse.mat.snapshot.Histogram

All Implemented Interfaces:
  `Serializable`, `IIconProvider`, `IResult`, `IResultTable`, `IStructuredResult`

    public class Histogram
    extends HistogramRecord
    implements IResultTable, IIconProvider

Class histogram - heap objects aggregated by their class. It holds the number and consumed memory of the objects aggregated per class and aggregated per class loader.

See Also:
  Serialized Form

### Nested Class Summary

Nested Classes
`static class` `Histogram.ClassLoaderTree`
`static class` `Histogram.PackageTree`
`static class` `Histogram.SuperclassTree`

### Field Summary

### Fields inherited from class org.eclipse.mat.snapshot.HistogramRecord

`COMPARATOR_FOR_LABEL, COMPARATOR_FOR_NUMBEROFOBJECTS, COMPARATOR_FOR_RETAINEDHEAPSIZE, COMPARATOR_FOR_USEDHEAPSIZE`

### Fields inherited from interface org.eclipse.mat.query.IIconProvider

`EMPTY`

### Constructor Summary

Constructors
`Histogram​(String label, ArrayList<ClassHistogramRecord> classHistogramRecords, ArrayList<ClassLoaderHistogramRecord> classLoaderHistogramRecords, long numberOfObjects, long usedHeapSize, long retainedHeapSize)` Construct a histogram
`Histogram​(String label, ArrayList<ClassHistogramRecord> classHistogramRecords, ArrayList<ClassLoaderHistogramRecord> classLoaderHistogramRecords, long numberOfObjects, long usedHeapSize, long retainedHeapSize, boolean isDefaultHistogram)` Construct a histogram

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`Histogram` `diffWithBaseline​(Histogram baseline)` Compute a new histogram as difference of this histogram compared to (minus) the given baseline histogram.
`static String` `generateClassHistogramRecordCsvReport​(Histogram histogram, Comparator<HistogramRecord> comparator)` Generate machine/human readable comma separated report from an histogram.
`static String` `generateClassHistogramRecordTextReport​(Histogram histogram, Comparator<HistogramRecord> comparator)` Generate human readable text based report from a histogram.
`static String` `generateClassLoaderHistogramRecordCsvReport​(Histogram histogram, Comparator<HistogramRecord> comparator)` Generate machine/human readable comma separated report from an histogram.
`Collection<ClassHistogramRecord>` `getClassHistogramRecords()` Get collection of all the classes for all the objects which were found in the set of objects on which the class histogram was computed.
`Collection<ClassLoaderHistogramRecord>` `getClassLoaderHistogramRecords()` Get collection of all the class loaders for all the classes for all the objects which were found in the set of objects on which the class histogram was computed.
`Column[]` `getColumns()` The columns of the tree or table.
`Object` `getColumnValue​(Object row, int columnIndex)` Returns the (unformatted) value of a table/tree cell.
`IContextObject` `getContext​(Object row)` The default context of the row which is used to display information in the object inspector.
`URL` `getIcon​(Object row)`
`ResultMetaData` `getResultMetaData()` (Optionally) Return meta data of the result needed to fine-tune the display of the result.
`Object` `getRow​(int rowId)` Returns the object of the row with the given row number.
`int` `getRowCount()` Returns the number of rows in the result table.
`IResultTree` `groupByClassLoader()` implementation as result tree grouped by class loader
`IResultTree` `groupByPackage()` implementation as result tree grouped by package
`IResultTree` `groupBySuperclass​(ISnapshot snapshot)` implementation as result tree grouped by superclass
`Histogram` `intersectWithAnother​(Histogram another)` Compute a new histogram as intersection of this histogram compared to (equals) the given another histogram.
`boolean` `isDefaultHistogram()`
`String` `toString()`

### Methods inherited from class org.eclipse.mat.snapshot.HistogramRecord

`getLabel, getNumberOfObjects, getRetainedHeapSize, getUsedHeapSize, incNumberOfObjects, incNumberOfObjects, incRetainedHeapSize, incUsedHeapSize, reverseComparator, setLabel, setNumberOfObjects, setRetainedHeapSize, setUsedHeapSize`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### Histogram

    public Histogram​(String label,
                     ArrayList<ClassHistogramRecord> classHistogramRecords,
                     ArrayList<ClassLoaderHistogramRecord> classLoaderHistogramRecords,
                     long numberOfObjects,
                     long usedHeapSize,
                     long retainedHeapSize)

Construct a histogram

Parameters:
  `label` - the name of the whole histogram
  `classHistogramRecords` - the classes
  `classLoaderHistogramRecords` - the class loaders
  `numberOfObjects` - the total number of objects
  `usedHeapSize` - the shallow size of all the objects
  `retainedHeapSize` - the retained size of all the objects, or 0 if unknown

#### Histogram

    public Histogram​(String label,
                     ArrayList<ClassHistogramRecord> classHistogramRecords,
                     ArrayList<ClassLoaderHistogramRecord> classLoaderHistogramRecords,
                     long numberOfObjects,
                     long usedHeapSize,
                     long retainedHeapSize,
                     boolean isDefaultHistogram)

Construct a histogram

Parameters:
  `label` - the name of the whole histogram
  `classHistogramRecords` - the classes
  `classLoaderHistogramRecords` - the class loaders
  `numberOfObjects` - the total number of objects
  `usedHeapSize` - the shallow size of all the objects
  `retainedHeapSize` - the retained size of all the objects, or 0 if unknown
  `isDefaultHistogram` - a histogram of the whole snapshot

### Method Detail

#### getClassHistogramRecords

    public Collection<ClassHistogramRecord> getClassHistogramRecords()

Get collection of all the classes for all the objects which were found in the set of objects on which the class histogram was computed.

Returns:
  collection of all the classes for all the objects which were found in the set of objects on which the class histogram was computed

#### getClassLoaderHistogramRecords

    public Collection<ClassLoaderHistogramRecord> getClassLoaderHistogramRecords()

Get collection of all the class loaders for all the classes for all the objects which were found in the set of objects on which the class histogram was computed.

Returns:
  collection of all the class loaders for all the classes for all the objects which were found in the set of objects on which the class histogram was computed

#### diffWithBaseline

    public Histogram diffWithBaseline​(Histogram baseline)

Compute a new histogram as difference of this histogram compared to (minus) the given baseline histogram.

This method can be used to check what has changed from one histogram to another, to compute a delta.

Parameters:
  `baseline` - baseline histogram
Returns:
  difference histogram between this histogram compared to (minus) the given baseline histogram

#### intersectWithAnother

    public Histogram intersectWithAnother​(Histogram another)

Compute a new histogram as intersection of this histogram compared to (equals) the given another histogram.

This method can be used to check what remains the same within two histograms, e.g. if you have two histograms it shows what hasn't changed, e.g. if you have two difference histograms it shows what remained the same change (increase or decrease; used in gradient memory leak analysis).

Note: Heap space is not taken into account in this analysis, only the number of objects, i.e. when the number of objects is the same, you will see this number of objects, otherwise or if there are no objects of a particular class you won't get a histogram record for it!

Parameters:
  `another` - another histogram
Returns:
  intersection histogram of this histogram compared to (equals) the given another histogram

#### isDefaultHistogram

    public boolean isDefaultHistogram()

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### generateClassHistogramRecordTextReport

    public static String generateClassHistogramRecordTextReport​(Histogram histogram,
                                                                Comparator<HistogramRecord> comparator)

Generate human readable text based report from a histogram.

Parameters:
  `histogram` - histogram you want a human reable text based report for
  `comparator` - comparator to be used for sorting the histogram records ( `HistogramRecord` provides some default comparators)
Returns:
  human redable text based report for the given histogram

#### generateClassHistogramRecordCsvReport

    public static String generateClassHistogramRecordCsvReport​(Histogram histogram,
                                                               Comparator<HistogramRecord> comparator)

Generate machine/human readable comma separated report from an histogram.

Parameters:
  `histogram` - histogram you want a machine/human readable comma separated report for
  `comparator` - comparator to be used for sorting the histogram records ( `HistogramRecord` provides some default comparators)
Returns:
  machine/human readable comma separated report for the given histogram

#### generateClassLoaderHistogramRecordCsvReport

    public static String generateClassLoaderHistogramRecordCsvReport​(Histogram histogram,
                                                                     Comparator<HistogramRecord> comparator)

Generate machine/human readable comma separated report from an histogram.

Parameters:
  `histogram` - histogram you want a machine/human readable comma separated report for
  `comparator` - comparator to be used for sorting the histogram records ( `HistogramRecord` provides some default comparators)
Returns:
  machine/human readable comma separated report for the given histogram

#### getResultMetaData

    public ResultMetaData getResultMetaData()

Description copied from interface: `IResult`
(Optionally) Return meta data of the result needed to fine-tune the display of the result. This could include an additional context, an additional query to run on selected data from the result , additional calculated columns, or an indication that the results are already presorted.

Specified by:
  `getResultMetaData` in interface `IResult`
Returns:
  the metadata for the result, used to obtain extra data

#### getColumns

    public Column[] getColumns()

Description copied from interface: `IStructuredResult`
The columns of the tree or table.

Specified by:
  `getColumns` in interface `IStructuredResult`
Returns:
  an array of all the columns

#### getRowCount

    public int getRowCount()

Description copied from interface: `IResultTable`
Returns the number of rows in the result table.

Specified by:
  `getRowCount` in interface `IResultTable`
Returns:
  the number of rows

#### getRow

    public Object getRow​(int rowId)

Description copied from interface: `IResultTable`
Returns the object of the row with the given row number.

Specified by:
  `getRow` in interface `IResultTable`
Parameters:
  `rowId` - The row number.
Returns:
  an opaque row object representing this row which can be passed to `IStructuredResult.getContext(Object)` or `IStructuredResult.getColumnValue(Object, int)`.

#### getColumnValue

    public Object getColumnValue​(Object row,
                                 int columnIndex)

Description copied from interface: `IStructuredResult`
Returns the (unformatted) value of a table/tree cell.

Specified by:
  `getColumnValue` in interface `IStructuredResult`
Parameters:
  `row` - The row object as returned by the `IResultTable.getRow(int)` or `IResultTree.getElements()` or `IResultTree.getChildren(Object)` methods
  `columnIndex` - The index of the column.
Returns:
  the cell value

#### getContext

    public IContextObject getContext​(Object row)

Description copied from interface: `IStructuredResult`
The default context of the row which is used to display information in the object inspector. Unless no context provider is given via the `ResultMetaData`, it is also used for the context menu on a row.

Specified by:
  `getContext` in interface `IStructuredResult`
Parameters:
  `row` - The row object as returned by the `IResultTable.getRow(int)` or `IResultTree.getElements()` or `IResultTree.getChildren(Object)` methods.
Returns:
  a context object holding details about that row

#### getIcon

    public URL getIcon​(Object row)

Specified by:
  `getIcon` in interface `IIconProvider`

#### groupByClassLoader

    public IResultTree groupByClassLoader()

implementation as result tree grouped by class loader

#### groupByPackage

    public IResultTree groupByPackage()

implementation as result tree grouped by package

#### groupBySuperclass

    public IResultTree groupBySuperclass​(ISnapshot snapshot)

implementation as result tree grouped by superclass

Since:
  1.0