Top Description Inners Fields Constructors Methods
org.HdrHistogram

public Class SingleWriterRecorder

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.

SingleWriterRecorder expects only a single thread (the "single writer") to call SingleWriterRecorder#recordValue or SingleWriterRecorder#recordValueWithExpectedInterval at any point in time. It DOES NOT safely support concurrent recording calls. Recording calls are wait-free on architectures that support atomic increment operations, and re lock-free on architectures that do not. *

A common pattern for using a SingleWriterRecorder looks like this:


SingleWriterRecorder recorder = new SingleWriterRecorder(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

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
SingleWriterRecorder(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
,
final boolean
Specifies whether the recorder will uses a packed internal representation or not.
packed
)

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

public
SingleWriterRecorder(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 SingleWriterRecorder with a lowest discernible value of 1 and an auto-adjusting highestTrackableValue.

public
SingleWriterRecorder(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 SingleWriterRecorder given the highest value to be tracked and a number of significant decimal digits.

public
SingleWriterRecorder(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 SingleWriterRecorder 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 SingleWriterRecorder) 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 SingleWriterRecorder. If false, will allow recycling histograms previously returned by other instances of SingleWriterRecorder.
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

SingleWriterRecorderback to summary
public SingleWriterRecorder(final int numberOfSignificantValueDigits, final boolean packed)

Construct an auto-resizing SingleWriterRecorder 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 SingleWriterRecorder 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.

SingleWriterRecorderback to summary
public SingleWriterRecorder(final int numberOfSignificantValueDigits)

Construct an auto-resizing SingleWriterRecorder 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.

SingleWriterRecorderback to summary
public SingleWriterRecorder(final long highestTrackableValue, final int numberOfSignificantValueDigits)

Construct a SingleWriterRecorder 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.

SingleWriterRecorderback to summary
public SingleWriterRecorder(final long lowestDiscernibleValue, final long highestTrackableValue, final int numberOfSignificantValueDigits)

Construct a SingleWriterRecorder 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 SingleWriterRecorder#getIntervalHistogram() and getIntervalHistogramInto(). The provided histogramToRecycle must be either be null or an interval histogram returned by a previous call to getIntervalHistogram(histogramToRecycle) or SingleWriterRecorder#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 SingleWriterRecorder) 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 SingleWriterRecorder#getIntervalHistogram() and getIntervalHistogramInto(). The provided histogramToRecycle must be either be null or an interval histogram returned by a previous call to getIntervalHistogram(histogramToRecycle) or SingleWriterRecorder#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 SingleWriterRecorder. If false, will allow recycling histograms previously returned by other instances of SingleWriterRecorder.

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)

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 SingleWriterRecorder.InternalHistogram

extends Histogram
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long
Inherited from org.HdrHistogram.Histogram:
countsnormalizingIndexOffsettotalCount

Constructor Summary

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

private
InternalHistogram(long id, long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits)

private

Method Summary

Inherited from org.HdrHistogram.Histogram:
_getEstimatedFootprintInBytesaddToCountAtIndexaddToTotalCountclearCountscopycopyCorrectedForCoordinatedOmissiondecodeFromByteBufferdecodeFromCompressedByteBufferfromStringgetCountAtIndexgetCountAtNormalizedIndexgetNormalizingIndexOffsetgetTotalCountincrementCountAtIndexincrementTotalCountresizesetCountAtIndexsetCountAtNormalizedIndexsetIntegerToDoubleValueConversionRatiosetNormalizingIndexOffsetsetTotalCountshiftNormalizingIndexByOffset

Field Detail

containingInstanceIdback to summary
private final long containingInstanceId

Constructor Detail

InternalHistogramback to summary
private InternalHistogram(long id, int numberOfSignificantValueDigits)
InternalHistogramback to summary
private InternalHistogram(long id, long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits)
InternalHistogramback to summary
private InternalHistogram(SingleWriterRecorder.InternalHistogram source)
org.HdrHistogram back to summary

private Class SingleWriterRecorder.PackedInternalHistogram

extends PackedHistogram
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long

Constructor Summary

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

Method Summary

Inherited from org.HdrHistogram.PackedHistogram:
_getEstimatedFootprintInBytesaddToCountAtIndexclearCountscopycopyCorrectedForCoordinatedOmissiondecodeFromByteBufferdecodeFromCompressedByteBuffergetCountAtIndexgetCountAtNormalizedIndexincrementCountAtIndexresizesetCountAtIndexsetCountAtNormalizedIndex

Field Detail

containingInstanceIdback to summary
private final long containingInstanceId

Constructor Detail

PackedInternalHistogramback to summary
private PackedInternalHistogram(long id, int numberOfSignificantValueDigits)