Class Recorder
- All Implemented Interfaces:
IntervalHistogramProvider<Histogram>,ValueRecorder
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
recordValue(long) or
recordValueWithExpectedInterval(long, long) 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]
-
Constructor Summary
ConstructorsConstructorDescriptionRecorder(int numberOfSignificantValueDigits) Construct an auto-resizingRecorderwith a lowest discernible value of 1 and an auto-adjusting highestTrackableValue.Recorder(int numberOfSignificantValueDigits, boolean packed) Construct an auto-resizingRecorderwith a lowest discernible value of 1 and an auto-adjusting highestTrackableValue.Recorder(long highestTrackableValue, int numberOfSignificantValueDigits) Construct aRecordergiven the highest value to be tracked and a number of significant decimal digits.Recorder(long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits) Construct aRecordergiven the Lowest and highest values to be tracked and a number of significant decimal digits. -
Method Summary
Modifier and TypeMethodDescriptionGet 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.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(Histogram histogramToRecycle, boolean enforceContainingInstance) Get an interval histogram, which will include a stable, consistent view of all value counts accumulated since the last interval histogram was taken.voidgetIntervalHistogramInto(Histogram targetHistogram) Place a copy of the value counts accumulated since accumulated (since the last interval histogram was taken) intotargetHistogram.voidrecordValue(long value) Record a valuevoidrecordValueWithCount(long value, long count) Record a value in the histogram (adding to the value's current count)voidrecordValueWithExpectedInterval(long value, long expectedIntervalBetweenValueSamples) Record a valuevoidreset()Reset any value counts accumulated thus far.
-
Constructor Details
-
Recorder
public Recorder(int numberOfSignificantValueDigits, boolean packed) Construct an auto-resizingRecorderwith 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
packedparameterRecordercan be configured 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 storage 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.
-
Recorder
public Recorder(int numberOfSignificantValueDigits) Construct an auto-resizingRecorderwith 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- 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.
-
Recorder
public Recorder(long highestTrackableValue, int numberOfSignificantValueDigits) Construct aRecordergiven 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- The highest value to be tracked by the histogram. Must be a positive integer that is >= 2.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.
-
Recorder
public Recorder(long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits) Construct aRecordergiven 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- 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- The highest value to be tracked by the histogram. Must be a positive integer that is >= (2 * lowestDiscernibleValue).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 Details
-
recordValue
Record a value- Specified by:
recordValuein interfaceValueRecorder- Parameters:
value- the value to record- Throws:
ArrayIndexOutOfBoundsException- (may throw) if value is exceeds highestTrackableValue
-
recordValueWithCount
Record a value in the histogram (adding to the value's current count)- Specified by:
recordValueWithCountin interfaceValueRecorder- Parameters:
value- The value to be recordedcount- The number of occurrences of this value to record- Throws:
ArrayIndexOutOfBoundsException- (may throw) if value is exceeds highestTrackableValue
-
recordValueWithExpectedInterval
public void recordValueWithExpectedInterval(long value, long expectedIntervalBetweenValueSamples) throws 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
AbstractHistogram.recordValueWithExpectedInterval(long, long)for more explanations about coordinated omission and expected interval correction. *- Specified by:
recordValueWithExpectedIntervalin interfaceValueRecorder- 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:
ArrayIndexOutOfBoundsException- (may throw) if value is exceeds highestTrackableValue
-
getIntervalHistogram
Description copied from interface:IntervalHistogramProviderGet 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 this will reset the value counts, and start accumulating value counts for the next interval.
- Specified by:
getIntervalHistogramin interfaceIntervalHistogramProvider<Histogram>- Returns:
- a histogram containing the value counts accumulated since the last interval histogram was taken.
-
getIntervalHistogram
Description copied from interface:IntervalHistogramProviderGet 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 thanIntervalHistogramProvider.getIntervalHistogram()andgetIntervalHistogramInto(). The providedhistogramToRecyclemust be either be null or an interval histogram returned by a previous call togetIntervalHistogram(histogramToRecycle)orIntervalHistogramProvider.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- Specified by:
getIntervalHistogramin interfaceIntervalHistogramProvider<Histogram>- Parameters:
histogramToRecycle- a previously returned interval histogram 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 Histogram getIntervalHistogram(Histogram histogramToRecycle, boolean enforceContainingInstance) Description copied from interface:IntervalHistogramProviderGet 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 thanIntervalHistogramProvider.getIntervalHistogram()andgetIntervalHistogramInto(). The providedhistogramToRecyclemust be either be null or an interval histogram returned by a previous call togetIntervalHistogram(histogramToRecycle)orIntervalHistogramProvider.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- Specified by:
getIntervalHistogramin interfaceIntervalHistogramProvider<Histogram>- Parameters:
histogramToRecycle- a previously returned interval histogram that may be recycled to avoid allocation and copy operations.enforceContainingInstance- if true, will only allow recycling of histograms previously returned from this instance ofIntervalHistogramProvider. If false, will allow recycling histograms previously returned by other instances ofIntervalHistogramProvider.- Returns:
- a histogram containing the value counts accumulated since the last interval histogram was taken.
-
getIntervalHistogramInto
Description copied from interface:IntervalHistogramProviderPlace a copy of the value counts accumulated since accumulated (since the last interval histogram was taken) intotargetHistogram.Calling
getIntervalHistogramInto()will reset the value counts, and start accumulating value counts for the next interval.- Specified by:
getIntervalHistogramIntoin interfaceIntervalHistogramProvider<Histogram>- 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:
resetin interfaceValueRecorder
-