Class DoubleRecorder
- java.lang.Object
-
- org.HdrHistogram.DoubleRecorder
-
- All Implemented Interfaces:
DoubleValueRecorder
public class DoubleRecorder extends java.lang.Object implements DoubleValueRecorder
Records floating point (double) values, and provides stable intervalDoubleHistogram
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.
DoubleRecorder
supports concurrentrecordValue(double)
orrecordValueWithExpectedInterval(double, double)
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
DoubleRecorder
looks like this:DoubleRecorder recorder = new DoubleRecorder(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 Class Summary
Nested Classes Modifier and Type Class Description private static class
DoubleRecorder.InternalConcurrentDoubleHistogram
private static class
DoubleRecorder.PackedInternalConcurrentDoubleHistogram
-
Field Summary
Fields Modifier and Type Field Description private ConcurrentDoubleHistogram
activeHistogram
private ConcurrentDoubleHistogram
inactiveHistogram
private long
instanceId
private static java.util.concurrent.atomic.AtomicLong
instanceIdSequencer
private WriterReaderPhaser
recordingPhaser
-
Constructor Summary
Constructors Constructor Description DoubleRecorder(int numberOfSignificantValueDigits)
Construct an auto-resizingDoubleRecorder
using a precision stated as a number of significant decimal digits.DoubleRecorder(int numberOfSignificantValueDigits, boolean packed)
Construct an auto-resizingDoubleRecorder
using a precision stated as a number of significant decimal digits.DoubleRecorder(long highestToLowestValueRatio, int numberOfSignificantValueDigits)
Construct aDoubleRecorder
dynamic range of values to cover and a number of significant decimal digits.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.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.void
getIntervalHistogramInto(DoubleHistogram targetHistogram)
Place a copy of the value counts accumulated since accumulated (since the last interval histogram was taken) intotargetHistogram
.private void
performIntervalSample()
void
recordValue(double value)
Record a valuevoid
recordValueWithCount(double value, long count)
Record a value in the histogram (adding to the value's current count)void
recordValueWithExpectedInterval(double value, double expectedIntervalBetweenValueSamples)
Record a valuevoid
reset()
Reset any value counts accumulated thus far.private void
validateFitAsReplacementHistogram(DoubleHistogram replacementHistogram, boolean enforeContainingInstance)
-
-
-
Field Detail
-
instanceIdSequencer
private static java.util.concurrent.atomic.AtomicLong instanceIdSequencer
-
instanceId
private final long instanceId
-
recordingPhaser
private final WriterReaderPhaser recordingPhaser
-
activeHistogram
private volatile ConcurrentDoubleHistogram activeHistogram
-
inactiveHistogram
private ConcurrentDoubleHistogram inactiveHistogram
-
-
Constructor Detail
-
DoubleRecorder
public DoubleRecorder(int numberOfSignificantValueDigits, boolean packed)
Construct an auto-resizingDoubleRecorder
using a precision stated as a number of significant decimal digits.Depending on the valuer of the
packed
parameterDoubleRecorder
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
- 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
- Specifies whether the recorder will uses a packed internal representation or not.
-
DoubleRecorder
public DoubleRecorder(int numberOfSignificantValueDigits)
Construct an auto-resizingDoubleRecorder
using a precision stated as a number of significant decimal digits.- Parameters:
numberOfSignificantValueDigits
- 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.
-
DoubleRecorder
public DoubleRecorder(long highestToLowestValueRatio, int numberOfSignificantValueDigits)
Construct aDoubleRecorder
dynamic range of values to cover and a number of significant decimal digits.- Parameters:
highestToLowestValueRatio
- specifies the dynamic range to use (as a ratio)numberOfSignificantValueDigits
- 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
-
recordValue
public void recordValue(double value)
Record a value- Specified by:
recordValue
in interfaceDoubleValueRecorder
- Parameters:
value
- the value to record- Throws:
java.lang.ArrayIndexOutOfBoundsException
- (may throw) if value is exceeds highestTrackableValue
-
recordValueWithCount
public void recordValueWithCount(double value, long count) throws java.lang.ArrayIndexOutOfBoundsException
Record a value in the histogram (adding to the value's current count)- Specified by:
recordValueWithCount
in interfaceDoubleValueRecorder
- Parameters:
value
- The value to be recordedcount
- The number of occurrences of this value to record- Throws:
java.lang.ArrayIndexOutOfBoundsException
- (may throw) if value is exceeds highestTrackableValue
-
recordValueWithExpectedInterval
public void recordValueWithExpectedInterval(double value, double expectedIntervalBetweenValueSamples) throws java.lang.ArrayIndexOutOfBoundsException
Record a valueTo 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
DoubleHistogram.recordValueWithExpectedInterval(double, double)
for more explanations about coordinated omission and expected interval correction. *- Specified by:
recordValueWithExpectedInterval
in interfaceDoubleValueRecorder
- Parameters:
value
- The value to recordexpectedIntervalBetweenValueSamples
- If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples- Throws:
java.lang.ArrayIndexOutOfBoundsException
- (may throw) if value is exceeds highestTrackableValue
-
getIntervalHistogram
public 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:
- a histogram containing the value counts accumulated since the last interval histogram was taken.
-
getIntervalHistogram
public 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 thangetIntervalHistogram()
andgetIntervalHistogramInto()
. The providedhistogramToRecycle
must be either be null or an interval histogram returned by a previous call togetIntervalHistogram(histogramToRecycle)
orgetIntervalHistogram()
.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
- a previously returned interval histogram (from this instance ofDoubleRecorder
) that may be recycled to avoid allocation and copy operations.- Returns:
- a histogram containing the value counts accumulated since the last interval histogram was taken.
-
getIntervalHistogram
public 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 thangetIntervalHistogram()
andgetIntervalHistogramInto()
. The providedhistogramToRecycle
must be either be null or an interval histogram returned by a previous call togetIntervalHistogram(histogramToRecycle)
orgetIntervalHistogram()
.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
- a previously returned interval histogram that may be recycled to avoid allocation and copy operations.enforeContainingInstance
- if true, will only allow recycling of histograms previously returned from this instance ofDoubleRecorder
. If false, will allow recycling histograms previously returned by other instances ofDoubleRecorder
.- Returns:
- a histogram containing the value counts accumulated since the last interval histogram was taken.
-
getIntervalHistogramInto
public void getIntervalHistogramInto(DoubleHistogram targetHistogram)
Place a copy of the value counts accumulated since accumulated (since the last interval histogram was taken) intotargetHistogram
. CallinggetIntervalHistogramInto(targetHistogram)
will reset the value counts, and start accumulating value counts for the next interval.- Parameters:
targetHistogram
- the histogram into which the interval histogram's data should be copied
-
reset
public void reset()
Reset any value counts accumulated thus far.- Specified by:
reset
in interfaceDoubleValueRecorder
-
performIntervalSample
private void performIntervalSample()
-
validateFitAsReplacementHistogram
private void validateFitAsReplacementHistogram(DoubleHistogram replacementHistogram, boolean enforeContainingInstance)
-
-