Top Description Inners Fields Constructors Methods
org.HdrHistogram

public Class SingleWriterDoubleRecorder

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

Records floating point values, and provides stable interval DoubleHistogram 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.

SingleWriterDoubleRecorder expects only a single thread (the "single writer") to call SingleWriterDoubleRecorder#recordValue or SingleWriterDoubleRecorder#recordValueWithExpectedInterval at any point in time. It DOES NOT support concurrent recording 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 SingleWriterDoubleRecorder looks like this:


SingleWriterDoubleRecorder recorder = new SingleWriterDoubleRecorder(2); // Two decimal point accuracy
DoubleHistogram 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 class
private class

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
SingleWriterDoubleRecorder(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 SingleWriterDoubleRecorder using a precision stated as a number of significant decimal digits.

public
SingleWriterDoubleRecorder(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 SingleWriterDoubleRecorder using a precision stated as a number of significant decimal digits.

public
SingleWriterDoubleRecorder(final long
specifies the dynamic range to use (as a ratio)
highestToLowestValueRatio
,
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 SingleWriterDoubleRecorder dynamic range of values to cover and a number of significant decimal digits.

Method Summary

Modifier and TypeMethod and Description
public synchronized DoubleHistogram

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 DoubleHistogram

Returns:

a histogram containing the value counts accumulated since the last interval histogram was taken.
getIntervalHistogram
(DoubleHistogram
a previously returned interval histogram (from this instance of SingleWriterDoubleRecorder) 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 DoubleHistogram

Returns:

a histogram containing the value counts accumulated since the last interval histogram was taken.
getIntervalHistogram
(DoubleHistogram
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 SingleWriterDoubleRecorder. If false, will allow recycling histograms previously returned by other instances of SingleWriterDoubleRecorder.
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(DoubleHistogram
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 double
the value to record
value
)

Implements org.HdrHistogram.DoubleValueRecorder.recordValue.

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

Implements org.HdrHistogram.DoubleValueRecorder.recordValueWithCount.

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

Implements org.HdrHistogram.DoubleValueRecorder.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.DoubleValueRecorder.reset.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

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

Constructor Detail

SingleWriterDoubleRecorderback to summary
public SingleWriterDoubleRecorder(final int numberOfSignificantValueDigits, final boolean packed)

Construct an auto-resizing SingleWriterDoubleRecorder using a precision stated as a number of significant decimal digits.

Depending on the valuer of the packed parameter SingleWriterDoubleRecorder 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.

SingleWriterDoubleRecorderback to summary
public SingleWriterDoubleRecorder(final int numberOfSignificantValueDigits)

Construct an auto-resizing SingleWriterDoubleRecorder using a precision stated as a number of significant decimal digits.

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.

SingleWriterDoubleRecorderback to summary
public SingleWriterDoubleRecorder(final long highestToLowestValueRatio, final int numberOfSignificantValueDigits)

Construct a SingleWriterDoubleRecorder dynamic range of values to cover and a number of significant decimal digits.

Parameters
highestToLowestValueRatio:long

specifies the dynamic range to use (as a ratio)

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 DoubleHistogram 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:DoubleHistogram

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

getIntervalHistogramback to summary
public synchronized DoubleHistogram getIntervalHistogram(DoubleHistogram 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 SingleWriterDoubleRecorder#getIntervalHistogram() and getIntervalHistogramInto(). The provided histogramToRecycle must be either be null or an interval histogram returned by a previous call to getIntervalHistogram(histogramToRecycle) or SingleWriterDoubleRecorder#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:DoubleHistogram

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

Returns:DoubleHistogram

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

getIntervalHistogramback to summary
public synchronized DoubleHistogram getIntervalHistogram(DoubleHistogram 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 SingleWriterDoubleRecorder#getIntervalHistogram() and getIntervalHistogramInto(). The provided histogramToRecycle must be either be null or an interval histogram returned by a previous call to getIntervalHistogram(histogramToRecycle) or SingleWriterDoubleRecorder#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:DoubleHistogram

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

Returns:DoubleHistogram

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

getIntervalHistogramIntoback to summary
public synchronized void getIntervalHistogramInto(DoubleHistogram 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:DoubleHistogram

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 double value)

Implements org.HdrHistogram.DoubleValueRecorder.recordValue.

Record a value

Parameters
value:double

the value to record

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

Implements org.HdrHistogram.DoubleValueRecorder.recordValueWithCount.

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

Parameters
value:double

The value to be recorded

count:long

The number of occurrences of this value to record

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

Implements org.HdrHistogram.DoubleValueRecorder.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 org.HdrHistogram.DoubleHistogram#recordValueWithExpectedInterval(double, double) for more explanations about coordinated omission and expected interval correction. *

Parameters
value:double

The value to record

expectedIntervalBetweenValueSamples:double

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

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

Implements org.HdrHistogram.DoubleValueRecorder.reset.

Reset any value counts accumulated thus far.

validateFitAsReplacementHistogramback to summary
private void validateFitAsReplacementHistogram(DoubleHistogram replacementHistogram, boolean enforeContainingInstance)
org.HdrHistogram back to summary

private Class SingleWriterDoubleRecorder.InternalDoubleHistogram

extends DoubleHistogram
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long
Inherited from org.HdrHistogram.DoubleHistogram:
integerValuesHistogram

Constructor Summary

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

private
InternalDoubleHistogram(long id, long highestToLowestValueRatio, int numberOfSignificantValueDigits)

private

Method Summary

Inherited from org.HdrHistogram.DoubleHistogram:
addaddWhileCorrectingForCoordinatedOmissionallValuesconstructHistogramFromBuffercopycopyCorrectedForCoordinatedOmissioncopyIntocopyIntoCorrectedForCoordinatedOmissiondecodeFromByteBufferdecodeFromByteBufferdecodeFromCompressedByteBufferdecodeFromCompressedByteBufferencodeIntoByteBufferencodeIntoCompressedByteBufferencodeIntoCompressedByteBufferequalsfromStringgetCountAtValuegetCountBetweenValuesgetCurrentHighestTrackableValuegetCurrentLowestTrackableNonZeroValuegetDoubleToIntegerValueConversionRatiogetEndTimeStampgetEstimatedFootprintInBytesgetHighestToLowestValueRatiogetIntegerToDoubleValueConversionRatiogetMaxValuegetMaxValueAsDoublegetMeangetMinNonZeroValuegetMinValuegetNeededByteBufferCapacitygetNumberOfSignificantValueDigitsgetPercentileAtOrBelowValuegetStartTimeStampgetStdDeviationgetTaggetTotalCountgetValueAtPercentilehashCodehighestEquivalentValueisAutoResizeisCompressedDoubleHistogramCookieisDoubleHistogramCookieisNonCompressedDoubleHistogramCookielinearBucketValueslogarithmicBucketValueslowestEquivalentValuemedianEquivalentValuenextNonEquivalentValueoutputPercentileDistributionoutputPercentileDistributionoutputPercentileDistributionpercentilesrecordedValuesrecordValuerecordValueWithCountrecordValueWithExpectedIntervalresetsetAutoResizesetEndTimeStampsetStartTimeStampsetTagsizeOfEquivalentValueRangesubtractvaluesAreEquivalent

Field Detail

containingInstanceIdback to summary
private final long containingInstanceId

Constructor Detail

InternalDoubleHistogramback to summary
private InternalDoubleHistogram(long id, int numberOfSignificantValueDigits)
InternalDoubleHistogramback to summary
private InternalDoubleHistogram(long id, long highestToLowestValueRatio, int numberOfSignificantValueDigits)
InternalDoubleHistogramback to summary
private InternalDoubleHistogram(SingleWriterDoubleRecorder.InternalDoubleHistogram source)
org.HdrHistogram back to summary

private Class SingleWriterDoubleRecorder.PackedInternalDoubleHistogram

extends PackedDoubleHistogram
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final long

Constructor Summary

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

Method Summary

Inherited from org.HdrHistogram.PackedDoubleHistogram:
decodeFromByteBufferdecodeFromCompressedByteBuffer

Field Detail

containingInstanceIdback to summary
private final long containingInstanceId

Constructor Detail

PackedInternalDoubleHistogramback to summary
private PackedInternalDoubleHistogram(long id, int numberOfSignificantValueDigits)