Top Description Inners Fields Constructors Methods
org.HdrHistogram

public Class Recorder

extends Object
implements ValueRecorder
Class Inheritance
All Implemented Interfaces
org.HdrHistogram.ValueRecorder
Imports
java.util.concurrent.atomic.AtomicLong

Records integer values, and provides stable interval Histogram samples from live recorded data without interrupting or stalling active recording of values. Each interval histogram provided contains all value counts accumulated since the previous interval histogram was taken.

This pattern is commonly used in logging interval histogram information while recording is ongoing.

Recorder supports concurrent Recorder#recordValue or Recorder#recordValueWithExpectedInterval calls. Recording calls are wait-free on architectures that support atomic increment operations, and are lock-free on architectures that do not.

A common pattern for using a Recorder looks like this:


Recorder recorder = new Recorder(2); // Two decimal point accuracy
Histogram intervalHistogram = null;
...
[start of some loop construct that periodically wants to grab an interval histogram]
  ...
  // Get interval histogram, recycling previous interval histogram:
  intervalHistogram = recorder.getIntervalHistogram(intervalHistogram);
  histogramLogWriter.outputIntervalHistogram(intervalHistogram);
  ...
[end of loop construct]

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private volatile Histogram
private Histogram
private final long
private static AtomicLong
private final WriterReaderPhaser

Constructor Summary

AccessConstructor and Description
public
Recorder(final int
Specifies the precision to use. This is the number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.
numberOfSignificantValueDigits
,
boolean
Specifies whether the recorder will uses a packed internal representation or not.
packed
)

Construct an auto-resizing Recorder with a lowest discernible value of 1 and an auto-adjusting highestTrackableValue.

public
Recorder(final int
Specifies the precision to use. This is the number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.
numberOfSignificantValueDigits
)

Construct an auto-resizing Recorder with a lowest discernible value of 1 and an auto-adjusting highestTrackableValue.

public
Recorder(final long
The highest value to be tracked by the histogram. Must be a positive integer that is >= 2.
highestTrackableValue
,
final int
Specifies the precision to use. This is the number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.
numberOfSignificantValueDigits
)

Construct a Recorder given the highest value to be tracked and a number of significant decimal digits.

public
Recorder(final long
The lowest value that can be tracked (distinguished from 0) by the histogram. Must be a positive integer that is >= 1. May be internally rounded down to nearest power of 2.
lowestDiscernibleValue
,
final long
The highest value to be tracked by the histogram. Must be a positive integer that is >= (2 * lowestDiscernibleValue).
highestTrackableValue
,
final int
Specifies the precision to use. This is the number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.
numberOfSignificantValueDigits
)

Construct a Recorder given the Lowest and highest values to be tracked and a number of significant decimal digits.

Method Summary

Modifier and TypeMethod and Description
public synchronized Histogram

Returns:

a histogram containing the value counts accumulated since the last interval histogram was taken.
getIntervalHistogram
()

Get a new instance of an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.

public synchronized Histogram

Returns:

a histogram containing the value counts accumulated since the last interval histogram was taken.
getIntervalHistogram
(Histogram
a previously returned interval histogram (from this instance of Recorder) that may be recycled to avoid allocation and copy operations.
histogramToRecycle
)

Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.

public synchronized Histogram

Returns:

a histogram containing the value counts accumulated since the last interval histogram was taken.
getIntervalHistogram
(Histogram
a previously returned interval histogram that may be recycled to avoid allocation and copy operations.
histogramToRecycle
,
boolean
if true, will only allow recycling of histograms previously returned from this instance of Recorder. If false, will allow recycling histograms previously returned by other instances of Recorder.
enforeContainingInstance
)

Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.

public synchronized void
getIntervalHistogramInto(Histogram
the histogram into which the interval histogram's data should be copied
targetHistogram
)

Place a copy of the value counts accumulated since accumulated (since the last interval histogram was taken) into targetHistogram.

private void
public void
recordValue(final long
the value to record
value
)

Implements org.HdrHistogram.ValueRecorder.recordValue.

Record a value
public void
recordValueWithCount(final long
The value to be recorded
value
,
final long
The number of occurrences of this value to record
count
)

Implements org.HdrHistogram.ValueRecorder.recordValueWithCount.

Record a value in the histogram (adding to the value's current count)
public void
recordValueWithExpectedInterval(final long
The value to record
value
,
final long
If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples
expectedIntervalBetweenValueSamples
)

Implements org.HdrHistogram.ValueRecorder.recordValueWithExpectedInterval.

Record a value

To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, Histogram will auto-generate an additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records.

public synchronized void
reset()

Implements org.HdrHistogram.ValueRecorder.reset.

Reset any value counts accumulated thus far.
private void
validateFitAsReplacementHistogram(Histogram replacementHistogram, boolean enforeContainingInstance)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeHistogramback to summary
private volatile Histogram activeHistogram
inactiveHistogramback to summary
private Histogram inactiveHistogram
instanceIdback to summary
private final long instanceId
instanceIdSequencerback to summary
private static AtomicLong instanceIdSequencer
recordingPhaserback to summary
private final WriterReaderPhaser recordingPhaser

Constructor Detail

Recorderback to summary
public Recorder(final int numberOfSignificantValueDigits, boolean packed)

Construct an auto-resizing Recorder with a lowest discernible value of 1 and an auto-adjusting highestTrackableValue. Can auto-resize up to track values up to (Long.MAX_VALUE / 2).

Depending on the valuer of the packed parameter Recorder can be configuired to track value counts in a packed internal representation optimized for typical histogram recoded values are sparse in the value range and tend to be incremented in small unit counts. This packed representation tends to require significantly smaller amounts of stoarge when compared to unpacked representations, but can incur additional recording cost due to resizing and repacking operations that may occur as previously unrecorded values are encountered.

Parameters
numberOfSignificantValueDigits:int

Specifies the precision to use. This is the number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.

packed:boolean

Specifies whether the recorder will uses a packed internal representation or not.

Recorderback to summary
public Recorder(final int numberOfSignificantValueDigits)

Construct an auto-resizing Recorder with a lowest discernible value of 1 and an auto-adjusting highestTrackableValue. Can auto-resize up to track values up to (Long.MAX_VALUE / 2).

Parameters
numberOfSignificantValueDigits:int

Specifies the precision to use. This is the number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.

Recorderback to summary
public Recorder(final long highestTrackableValue, final int numberOfSignificantValueDigits)

Construct a Recorder given the highest value to be tracked and a number of significant decimal digits. The histogram will be constructed to implicitly track (distinguish from 0) values as low as 1.

Parameters
highestTrackableValue:long

The highest value to be tracked by the histogram. Must be a positive integer that is >= 2.

numberOfSignificantValueDigits:int

Specifies the precision to use. This is the number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.

Recorderback to summary
public Recorder(final long lowestDiscernibleValue, final long highestTrackableValue, final int numberOfSignificantValueDigits)

Construct a Recorder given the Lowest and highest values to be tracked and a number of significant decimal digits. Providing a lowestDiscernibleValue is useful is situations where the units used for the histogram's values are much smaller that the minimal accuracy required. E.g. when tracking time values stated in nanosecond units, where the minimal accuracy required is a microsecond, the proper value for lowestDiscernibleValue would be 1000.

Parameters
lowestDiscernibleValue:long

The lowest value that can be tracked (distinguished from 0) by the histogram. Must be a positive integer that is >= 1. May be internally rounded down to nearest power of 2.

highestTrackableValue:long

The highest value to be tracked by the histogram. Must be a positive integer that is >= (2 * lowestDiscernibleValue).

numberOfSignificantValueDigits:int

Specifies the precision to use. This is the number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.

Method Detail

getIntervalHistogramback to summary
public synchronized Histogram getIntervalHistogram()

Get a new instance of an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.

Calling getIntervalHistogram() will reset the value counts, and start accumulating value counts for the next interval.

Returns:Histogram

a histogram containing the value counts accumulated since the last interval histogram was taken.

getIntervalHistogramback to summary
public synchronized Histogram getIntervalHistogram(Histogram histogramToRecycle)

Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.

getIntervalHistogram(histogramToRecycle) accepts a previously returned interval histogram that can be recycled internally to avoid allocation and content copying operations, and is therefore significantly more efficient for repeated use than Recorder#getIntervalHistogram() and getIntervalHistogramInto(). The provided histogramToRecycle must be either be null or an interval histogram returned by a previous call to getIntervalHistogram(histogramToRecycle) or Recorder#getIntervalHistogram().

Note

The caller is responsible for not recycling the same returned interval histogram more than once. If the same interval histogram instance is recycled more than once, behavior is undefined.

Calling getIntervalHistogram(histogramToRecycle) will reset the value counts, and start accumulating value counts for the next interval

Parameters
histogramToRecycle:Histogram

a previously returned interval histogram (from this instance of Recorder) that may be recycled to avoid allocation and copy operations.

Returns:Histogram

a histogram containing the value counts accumulated since the last interval histogram was taken.

getIntervalHistogramback to summary
public synchronized Histogram getIntervalHistogram(Histogram histogramToRecycle, boolean enforeContainingInstance)

Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.

getIntervalHistogram(histogramToRecycle) accepts a previously returned interval histogram that can be recycled internally to avoid allocation and content copying operations, and is therefore significantly more efficient for repeated use than Recorder#getIntervalHistogram() and getIntervalHistogramInto(). The provided histogramToRecycle must be either be null or an interval histogram returned by a previous call to getIntervalHistogram(histogramToRecycle) or Recorder#getIntervalHistogram().

Note

The caller is responsible for not recycling the same returned interval histogram more than once. If the same interval histogram instance is recycled more than once, behavior is undefined.

Calling getIntervalHistogram(histogramToRecycle) will reset the value counts, and start accumulating value counts for the next interval

Parameters
histogramToRecycle:Histogram

a previously returned interval histogram that may be recycled to avoid allocation and copy operations.

enforeContainingInstance:boolean

if true, will only allow recycling of histograms previously returned from this instance of Recorder. If false, will allow recycling histograms previously returned by other instances of Recorder.

Returns:Histogram

a histogram containing the value counts accumulated since the last interval histogram was taken.

getIntervalHistogramIntoback to summary
public synchronized void getIntervalHistogramInto(Histogram targetHistogram)

Place a copy of the value counts accumulated since accumulated (since the last interval histogram was taken) into targetHistogram. Calling getIntervalHistogramInto(targetHistogram) will reset the value counts, and start accumulating value counts for the next interval.

Parameters
targetHistogram:Histogram

the histogram into which the interval histogram's data should be copied

performIntervalSampleback to summary
private void performIntervalSample()
recordValueback to summary
public void recordValue(final long value) throws ArrayIndexOutOfBoundsException

Implements org.HdrHistogram.ValueRecorder.recordValue.

Record a value

Parameters
value:long

the value to record

Annotations
@Override
Exceptions
ArrayIndexOutOfBoundsException:
(may throw) if value is exceeds highestTrackableValue
recordValueWithCountback to summary
public void recordValueWithCount(final long value, final long count) throws ArrayIndexOutOfBoundsException

Implements org.HdrHistogram.ValueRecorder.recordValueWithCount.

Record a value in the histogram (adding to the value's current count)

Parameters
value:long

The value to be recorded

count:long

The number of occurrences of this value to record

Annotations
@Override
Exceptions
ArrayIndexOutOfBoundsException:
(may throw) if value is exceeds highestTrackableValue
recordValueWithExpectedIntervalback to summary
public void recordValueWithExpectedInterval(final long value, final long expectedIntervalBetweenValueSamples) throws ArrayIndexOutOfBoundsException

Implements org.HdrHistogram.ValueRecorder.recordValueWithExpectedInterval.

Record a value

To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, Histogram will auto-generate an additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records.

See related notes AbstractHistogram#recordValueWithExpectedInterval(long, long) for more explanations about coordinated omission and expected interval correction. *

Parameters
value:long

The value to record

expectedIntervalBetweenValueSamples:long

If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples

Annotations
@Override
Exceptions
ArrayIndexOutOfBoundsException:
(may throw) if value is exceeds highestTrackableValue
resetback to summary
public synchronized void reset()

Implements org.HdrHistogram.ValueRecorder.reset.

Reset any value counts accumulated thus far.

Annotations
@Override
validateFitAsReplacementHistogramback to summary
private void validateFitAsReplacementHistogram(Histogram replacementHistogram, boolean enforeContainingInstance)
org.HdrHistogram back to summary

private Class Recorder.InternalAtomicHistogram

extends AtomicHistogram
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long
Inherited from org.HdrHistogram.AtomicHistogram:
countstotalCounttotalCountUpdater

Constructor Summary

AccessConstructor and Description
private
InternalAtomicHistogram(long id, long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits)

Method Summary

Inherited from org.HdrHistogram.AtomicHistogram:
_getEstimatedFootprintInBytesaddToCountAtIndexaddToTotalCountclearCountscopycopyCorrectedForCoordinatedOmissiondecodeFromByteBufferdecodeFromCompressedByteBufferfromStringgetCountAtIndexgetCountAtNormalizedIndexgetNormalizingIndexOffsetgetTotalCountincrementCountAtIndexincrementTotalCountresizesetAutoResizesetCountAtIndexsetCountAtNormalizedIndexsetNormalizingIndexOffsetsetTotalCountshiftNormalizingIndexByOffsetsupportsAutoResize

Field Detail

containingInstanceIdback to summary
private final long containingInstanceId

Constructor Detail

InternalAtomicHistogramback to summary
private InternalAtomicHistogram(long id, long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits)
org.HdrHistogram back to summary

private Class Recorder.InternalConcurrentHistogram

extends ConcurrentHistogram
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long
Inherited from org.HdrHistogram.ConcurrentHistogram:
activeCountsinactiveCountstotalCounttotalCountUpdaterwrp

Constructor Summary

AccessConstructor and Description
private
InternalConcurrentHistogram(long id, int numberOfSignificantValueDigits)

Method Summary

Inherited from org.HdrHistogram.ConcurrentHistogram:
_getEstimatedFootprintInBytesaddToCountAtIndexaddToTotalCountallocateArrayclearCountscopycopyCorrectedForCoordinatedOmissioncopyInactiveCountsContentsOnResizedecodeFromByteBufferdecodeFromCompressedByteBufferfillBufferFromCountsArrayfromStringgetCountAtIndexgetCountAtNormalizedIndexgetNormalizingIndexOffsetgetTotalCountincrementCountAtIndexincrementTotalCountrecordConvertedDoubleValuerecordConvertedDoubleValueWithCountresizesetAutoResizesetCountAtIndexsetCountAtNormalizedIndexsetIntegerToDoubleValueConversionRatiosetNormalizingIndexOffsetsetTotalCountshiftNormalizingIndexByOffset

Field Detail

containingInstanceIdback to summary
private final long containingInstanceId

Constructor Detail

InternalConcurrentHistogramback to summary
private InternalConcurrentHistogram(long id, int numberOfSignificantValueDigits)
org.HdrHistogram back to summary

private Class Recorder.InternalPackedConcurrentHistogram

extends PackedConcurrentHistogram
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long

Constructor Summary

AccessConstructor and Description
private
InternalPackedConcurrentHistogram(long id, int numberOfSignificantValueDigits)

Method Summary

Inherited from org.HdrHistogram.PackedConcurrentHistogram:
_getEstimatedFootprintInBytesaddToTotalCountallocateArrayclearCountscopycopyCorrectedForCoordinatedOmissiondecodeFromByteBufferdecodeFromCompressedByteBufferfillBufferFromCountsArrayfromStringgetTotalCountincrementTotalCountsetTotalCount

Field Detail

containingInstanceIdback to summary
private final long containingInstanceId

Constructor Detail

InternalPackedConcurrentHistogramback to summary
private InternalPackedConcurrentHistogram(long id, int numberOfSignificantValueDigits)