org.HdrHistogram
Class AbstractHistogram

java.lang.Object
  extended by org.HdrHistogram.AbstractHistogram
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AtomicHistogram, Histogram, IntHistogram, ShortHistogram, SynchronizedHistogram

public abstract class AbstractHistogram
extends Object
implements Serializable

A High Dynamic Range (HDR) Histogram

AbstractHistogram supports the recording and analyzing sampled data value counts across a configurable integer value range with configurable value precision within the range. Value precision is expressed as the number of significant digits in the value recording, and provides control over value quantization behavior across the value range and the subsequent value resolution at any given level.

For example, a Histogram could be configured to track the counts of observed integer values between 0 and 3,600,000,000 while maintaining a value precision of 3 significant digits across that range. Value quantization within the range will thus be no larger than 1/1,000th (or 0.1%) of any value. This example Histogram could be used to track and analyze the counts of observed response times ranging between 1 microsecond and 1 hour in magnitude, while maintaining a value resolution of 1 microsecond up to 1 millisecond, a resolution of 1 millisecond (or better) up to one second, and a resolution of 1 second (or better) up to 1,000 seconds. At it's maximum tracked value (1 hour), it would still maintain a resolution of 3.6 seconds (or better).

See package description for org.HdrHistogram for details.

See Also:
Serialized Form

Constructor Summary
AbstractHistogram(long lowestTrackableValue, long highestTrackableValue, int numberOfSignificantValueDigits)
          Construct a Histogram given the Lowest and Highest values to be tracked and a number of significant decimal digits.
 
Method Summary
 void add(AbstractHistogram fromHistogram)
          Add the contents of another histogram to this one.
 void addWhileCorrectingForCoordinatedOmission(AbstractHistogram fromHistogram, long expectedIntervalBetweenValueSamples)
          Add the contents of another histogram to this one, while correcting the incoming data for coordinated omission.
abstract  AbstractHistogram copy()
          Create a copy of this histogram, complete with data and everything.
abstract  AbstractHistogram copyCorrectedForCoordinatedOmission(long expectedIntervalBetweenValueSamples)
          Get a copy of this histogram, corrected for coordinated omission.
 void copyInto(AbstractHistogram targetHistogram)
          Copy this histogram into the target histogram, overwriting it's contents.
 void copyIntoCorrectedForCoordinatedOmission(AbstractHistogram targetHistogram, long expectedIntervalBetweenValueSamples)
          Copy this histogram, corrected for coordinated omission, into the target histogram, overwriting it's contents.
 int encodeIntoByteBuffer(ByteBuffer buffer)
          Encode this histogram into a ByteBuffer
 int encodeIntoCompressedByteBuffer(ByteBuffer targetBuffer)
          Encode this histogram in compressed form into a byte array
 int encodeIntoCompressedByteBuffer(ByteBuffer targetBuffer, int compressionLevel)
          Encode this histogram in compressed form into a byte array
 boolean equals(Object other)
          Determine if this histogram is equivalent to another.
 long getEndTimeStamp()
          get the end time stamp [optionally] stored with this histogram
 int getEstimatedFootprintInBytes()
          Provide a (conservatively high) estimate of the Histogram's total footprint in bytes
 long getHighestTrackableValue()
          get the configured highestTrackableValue
 HistogramData getHistogramData()
          Provide access to the histogram's data set.
 long getLowestTrackableValue()
          get the configured lowestTrackableValue
 int getNeededByteBufferCapacity()
          Get the capacity needed to encode this histogram into a ByteBuffer
 int getNumberOfSignificantValueDigits()
          get the configured numberOfSignificantValueDigits
 long getStartTimeStamp()
          get the start time stamp [optionally] stored with this histogram
 boolean hasOverflowed()
          Determine if this histogram had any of it's value counts overflow.
 long highestEquivalentValue(long value)
          Get the highest value that is equivalent to the given value within the histogram's resolution.
 long lowestEquivalentValue(long value)
          Get the lowest value that is equivalent to the given value within the histogram's resolution.
 long medianEquivalentValue(long value)
          Get a value that lies in the middle (rounded up) of the range of values equivalent the given value.
 long nextNonEquivalentValue(long value)
          Get the next value that is not equivalent to the given value within the histogram's resolution.
 void recordValue(long value)
          Record a value in the histogram
 void recordValue(long value, long expectedIntervalBetweenValueSamples)
          Deprecated. Record a value in the histogram. This deprecated method has identical behavior to recordValueWithExpectedInterval(). It was renamed to avoid ambiguity.
 void recordValueWithCount(long value, long count)
          Record a value in the histogram (adding to the value's current count)
 void recordValueWithExpectedInterval(long value, long expectedIntervalBetweenValueSamples)
          Record a value in the histogram.
 void reestablishTotalCount()
          Reestablish the internal notion of totalCount by recalculating it from recorded values.
 void reset()
          Reset the contents and stats of this histogram
 void setEndTimeStamp(long timeStampMsec)
          Set the end time stamp value associated with this histogram to a given value.
 void setStartTimeStamp(long timeStampMsec)
          Set the start time stamp value associated with this histogram to a given value.
 long sizeOfEquivalentValueRange(long value)
          Get the size (in value units) of the range of values that are equivalent to the given value within the histogram's resolution.
 boolean valuesAreEquivalent(long value1, long value2)
          Determine if two values are equivalent with the histogram's resolution.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHistogram

public AbstractHistogram(long lowestTrackableValue,
                         long highestTrackableValue,
                         int numberOfSignificantValueDigits)
Construct a Histogram given the Lowest and Highest values to be tracked and a number of significant decimal digits. Providing a lowestTrackableValue 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 lowestTrackableValue would be 1000.

Parameters:
lowestTrackableValue - 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 * lowestTrackableValue).
numberOfSignificantValueDigits - 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

copy

public abstract AbstractHistogram copy()
Create a copy of this histogram, complete with data and everything.

Returns:
A distinct copy of this histogram.

copyCorrectedForCoordinatedOmission

public abstract AbstractHistogram copyCorrectedForCoordinatedOmission(long expectedIntervalBetweenValueSamples)
Get a copy of this histogram, corrected for coordinated omission.

To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, the new histogram will include an auto-generated additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records for each count found in the current histogram that is larger than the expectedIntervalBetweenValueSamples. Note: This is a post-correction method, as opposed to the at-recording correction method provided by recordValueWithExpectedInterval. The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue. by

See notes in the description of the Histogram calls for an illustration of why this corrective behavior is important.

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

getEstimatedFootprintInBytes

public int getEstimatedFootprintInBytes()
Provide a (conservatively high) estimate of the Histogram's total footprint in bytes

Returns:
a (conservatively high) estimate of the Histogram's total footprint in bytes

copyInto

public void copyInto(AbstractHistogram targetHistogram)
Copy this histogram into the target histogram, overwriting it's contents.

Parameters:
targetHistogram -

copyIntoCorrectedForCoordinatedOmission

public void copyIntoCorrectedForCoordinatedOmission(AbstractHistogram targetHistogram,
                                                    long expectedIntervalBetweenValueSamples)
Copy this histogram, corrected for coordinated omission, into the target histogram, overwriting it's contents. (see copyCorrectedForCoordinatedOmission(long) for more detailed explanation about how correction is applied)

Parameters:
targetHistogram -
expectedIntervalBetweenValueSamples -

getLowestTrackableValue

public long getLowestTrackableValue()
get the configured lowestTrackableValue

Returns:
lowestTrackableValue

getHighestTrackableValue

public long getHighestTrackableValue()
get the configured highestTrackableValue

Returns:
highestTrackableValue

getNumberOfSignificantValueDigits

public int getNumberOfSignificantValueDigits()
get the configured numberOfSignificantValueDigits

Returns:
numberOfSignificantValueDigits

getStartTimeStamp

public long getStartTimeStamp()
get the start time stamp [optionally] stored with this histogram

Returns:
the start time stamp [optionally] stored with this histogram

setStartTimeStamp

public void setStartTimeStamp(long timeStampMsec)
Set the start time stamp value associated with this histogram to a given value.

Parameters:
timeStampMsec - the value to set the time stamp to, [by convention] in msec since the epoch.

getEndTimeStamp

public long getEndTimeStamp()
get the end time stamp [optionally] stored with this histogram

Returns:
the end time stamp [optionally] stored with this histogram

setEndTimeStamp

public void setEndTimeStamp(long timeStampMsec)
Set the end time stamp value associated with this histogram to a given value.

Parameters:
timeStampMsec - the value to set the time stamp to, [by convention] in msec since the epoch.

recordValueWithExpectedInterval

public void recordValueWithExpectedInterval(long value,
                                            long expectedIntervalBetweenValueSamples)
                                     throws ArrayIndexOutOfBoundsException
Record a value in the histogram.

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.

Note: This is a at-recording correction method, as opposed to the post-recording correction method provided by getHistogramCorrectedForCoordinatedOmission. The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue.

See notes in the description of the Histogram calls for an illustration of why this corrective behavior is important.

Parameters:
value - The value to record
expectedIntervalBetweenValueSamples - If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples
Throws:
ArrayIndexOutOfBoundsException

recordValue

public void recordValue(long value,
                        long expectedIntervalBetweenValueSamples)
                 throws ArrayIndexOutOfBoundsException
Deprecated. Record a value in the histogram. This deprecated method has identical behavior to recordValueWithExpectedInterval(). It was renamed to avoid ambiguity.

Parameters:
value - The value to record
expectedIntervalBetweenValueSamples - If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples
Throws:
ArrayIndexOutOfBoundsException

recordValueWithCount

public void recordValueWithCount(long value,
                                 long count)
                          throws ArrayIndexOutOfBoundsException
Record a value in the histogram (adding to the value's current count)

Parameters:
value - The value to be recorded
count - The number of occurrences of this value to record
Throws:
ArrayIndexOutOfBoundsException

recordValue

public void recordValue(long value)
                 throws ArrayIndexOutOfBoundsException
Record a value in the histogram

Parameters:
value - The value to be recorded
Throws:
ArrayIndexOutOfBoundsException

reset

public void reset()
Reset the contents and stats of this histogram


add

public void add(AbstractHistogram fromHistogram)
         throws ArrayIndexOutOfBoundsException
Add the contents of another histogram to this one.

Parameters:
fromHistogram - The other histogram.
Throws:
ArrayIndexOutOfBoundsException - if fromHistogram's highestTrackableValue is larger than this one's.

addWhileCorrectingForCoordinatedOmission

public void addWhileCorrectingForCoordinatedOmission(AbstractHistogram fromHistogram,
                                                     long expectedIntervalBetweenValueSamples)
Add the contents of another histogram to this one, while correcting the incoming data for coordinated omission.

To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, the values added will include an auto-generated additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records for each count found in the current histogram that is larger than the expectedIntervalBetweenValueSamples. Note: This is a post-recording correction method, as opposed to the at-recording correction method provided by recordValueWithExpectedInterval. The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue. by

See notes in the description of the Histogram calls for an illustration of why this corrective behavior is important.

Parameters:
fromHistogram - The other histogram. highestTrackableValue and largestValueWithSingleUnitResolution must match.
expectedIntervalBetweenValueSamples - If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples
Throws:
ArrayIndexOutOfBoundsException

hasOverflowed

public boolean hasOverflowed()
Determine if this histogram had any of it's value counts overflow. Since counts are kept in fixed integer form with potentially limited range (e.g. int and short), a specific value range count could potentially overflow, leading to an inaccurate and misleading histogram representation. This method accurately determines whether or not an overflow condition has happened in an IntHistogram or ShortHistogram.

Returns:
True if this histogram has had a count value overflow.

reestablishTotalCount

public void reestablishTotalCount()
Reestablish the internal notion of totalCount by recalculating it from recorded values. Implementations of AbstractHistogram may maintain a separately tracked notion of totalCount, which is useful for concurrent modification tracking, overflow detection, and speed of execution in iteration. This separately tracked totalCount can get into a state that is inconsistent with the currently recorded value counts under various concurrent modification and overflow conditions. Applying this method will override internal indications of potential overflows and concurrent modification, and will reestablish a self-consistent representation of the histogram data based purely on the current internal representation of recorded counts.

In cases of concurrent modifications such as during copying, or due to racy multi-threaded updates on non-atomic or non-synchronized variants, which can result in potential loss of counts and an inconsistent (indicating potential overflow) internal state, calling this method on a histogram will reestablish a consistent internal state based on the potentially lossy counts representations.

Note that this method is not synchronized against concurrent modification in any way, and will only reliably reestablish consistent internal state when no concurrent modification of the histogram is performed while it executes.

Note that in the cases of actual overflow conditions (which can result in negative counts) this self consistent view may be very wrong, and not just slightly lossy.


equals

public boolean equals(Object other)
Determine if this histogram is equivalent to another.

Overrides:
equals in class Object
Parameters:
other - the other histogram to compare to
Returns:
True if this histogram are equivalent with the other.

getHistogramData

public HistogramData getHistogramData()
Provide access to the histogram's data set.

Returns:
a HistogramData that can be used to query stats and iterate through the default (corrected) data set.

sizeOfEquivalentValueRange

public long sizeOfEquivalentValueRange(long value)
Get the size (in value units) of the range of values that are equivalent to the given value within the histogram's resolution. Where "equivalent" means that value samples recorded for any two equivalent values are counted in a common total count.

Parameters:
value - The given value
Returns:
The lowest value that is equivalent to the given value within the histogram's resolution.

lowestEquivalentValue

public long lowestEquivalentValue(long value)
Get the lowest value that is equivalent to the given value within the histogram's resolution. Where "equivalent" means that value samples recorded for any two equivalent values are counted in a common total count.

Parameters:
value - The given value
Returns:
The lowest value that is equivalent to the given value within the histogram's resolution.

highestEquivalentValue

public long highestEquivalentValue(long value)
Get the highest value that is equivalent to the given value within the histogram's resolution. Where "equivalent" means that value samples recorded for any two equivalent values are counted in a common total count.

Parameters:
value - The given value
Returns:
The highest value that is equivalent to the given value within the histogram's resolution.

medianEquivalentValue

public long medianEquivalentValue(long value)
Get a value that lies in the middle (rounded up) of the range of values equivalent the given value. Where "equivalent" means that value samples recorded for any two equivalent values are counted in a common total count.

Parameters:
value - The given value
Returns:
The value lies in the middle (rounded up) of the range of values equivalent the given value.

nextNonEquivalentValue

public long nextNonEquivalentValue(long value)
Get the next value that is not equivalent to the given value within the histogram's resolution. Where "equivalent" means that value samples recorded for any two equivalent values are counted in a common total count.

Parameters:
value - The given value
Returns:
The next value that is not equivalent to the given value within the histogram's resolution.

valuesAreEquivalent

public boolean valuesAreEquivalent(long value1,
                                   long value2)
Determine if two values are equivalent with the histogram's resolution. Where "equivalent" means that value samples recorded for any two equivalent values are counted in a common total count.

Parameters:
value1 - first value to compare
value2 - second value to compare
Returns:
True if values are equivalent with the histogram's resolution.

getNeededByteBufferCapacity

public int getNeededByteBufferCapacity()
Get the capacity needed to encode this histogram into a ByteBuffer

Returns:
the capacity needed to encode this histogram into a ByteBuffer

encodeIntoByteBuffer

public int encodeIntoByteBuffer(ByteBuffer buffer)
Encode this histogram into a ByteBuffer

Parameters:
buffer - The buffer to encode into
Returns:
The number of bytes written to the buffer

encodeIntoCompressedByteBuffer

public int encodeIntoCompressedByteBuffer(ByteBuffer targetBuffer,
                                          int compressionLevel)
Encode this histogram in compressed form into a byte array

Parameters:
targetBuffer - The buffer to encode into
compressionLevel - Compression level (for java.util.zip.Deflater).
Returns:
The number of bytes written to the buffer

encodeIntoCompressedByteBuffer

public int encodeIntoCompressedByteBuffer(ByteBuffer targetBuffer)
Encode this histogram in compressed form into a byte array

Parameters:
targetBuffer - The buffer to encode into
Returns:
The number of bytes written to the array


Copyright © 2014. All rights reserved.