Top Description Inners Fields Constructors Methods
org.HdrHistogram

public Class DoubleHistogram

extends EncodableHistogram
implements DoubleValueRecorder, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.HdrHistogram.DoubleValueRecorder
Known Direct Subclasses
org.HdrHistogram.PackedDoubleHistogram, org.HdrHistogram.SingleWriterDoubleRecorder.InternalDoubleHistogram, org.HdrHistogram.SynchronizedDoubleHistogram, org.HdrHistogram.ConcurrentDoubleHistogram
Imports
java.io.*, java.lang.reflect.Constructor, .InvocationTargetException, java.nio.ByteBuffer, java.util.Iterator, java.util.zip.DataFormatException, .Deflater

A floating point values High Dynamic Range (HDR) Histogram

It is important to note that DoubleHistogram is not thread-safe, and does not support safe concurrent recording by multiple threads. If concurrent operation is required, consider usings ConcurrentDoubleHistogram, SynchronizedDoubleHistogram, or (recommended) DoubleRecorder or SingleWriterDoubleRecorder which are intended for this purpose.

DoubleHistogram supports the recording and analyzing sampled data value counts across a configurable dynamic range of floating point (double) values, with configurable value precision within the range. Dynamic range is expressed as a ratio between the highest and lowest non-zero values trackable within the histogram at any given time. Value precision is expressed as the number of significant [decimal] 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.

Auto-ranging: Unlike integer value based histograms, the specific value range tracked by a DoubleHistogram is not specified upfront. Only the dynamic range of values that the histogram can cover is (optionally) specified. E.g. When a DoubleHistogram is created to track a dynamic range of 3600000000000 (enough to track values from a nanosecond to an hour), values could be recorded into into it in any consistent unit of time as long as the ratio between the highest and lowest non-zero values stays within the specified dynamic range, so recording in units of nanoseconds (1.0 thru 3600000000000.0), milliseconds (0.000001 thru 3600000.0) seconds (0.000000001 thru 3600.0), hours (1/3.6E12 thru 1.0) will all work just as well.

Auto-resizing: When constructed with no specified dynamic range (or when auto-resize is turned on with DoubleHistogram#setAutoResize) a DoubleHistogram will auto-resize its dynamic range to include recorded values as they are encountered. Note that recording calls that cause auto-resizing may take longer to execute, as resizing incurs allocation and copying of internal data structures.

Attempts to record non-zero values that range outside of the specified dynamic range (or exceed the limits of of dynamic range when auto-resizing) may results in ArrayIndexOutOfBoundsException exceptions, either due to overflow or underflow conditions. These exceptions will only be thrown if recording the value would have resulted in discarding or losing the required value precision of values already recorded in the histogram.

See package description for org.HdrHistogram for details.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
public class
public class
public class
public class

Field Summary

Modifier and TypeField and Description
private boolean
private long
private static final Class<T>[]
private volatile double
private volatile double
private static final int
private static final int
private static final double
pack-priv AbstractHistogram
private static final long

Constructor Summary

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

public
DoubleHistogram(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 Class<? extends AbstractHistogram>
The class to use for internal counts tracking
internalCountsHistogramClass
)

Construct a new auto-resizing DoubleHistogram using a precision stated as a number of significant decimal digits.

public
DoubleHistogram(final long
specifies the dynamic range to use
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 new DoubleHistogram with the specified dynamic range (provided in highestToLowestValueRatio) and using a precision stated as a number of significant decimal digits.

protected
DoubleHistogram(final long
specifies the dynamic range to use.
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
,
final Class<? extends AbstractHistogram>
The class to use for internal counts tracking
internalCountsHistogramClass
)

Construct a new DoubleHistogram with the specified dynamic range (provided in highestToLowestValueRatio) and using a precision stated as a number of significant decimal digits.

pack-priv
DoubleHistogram(final long highestToLowestValueRatio, final int numberOfSignificantValueDigits, final Class<? extends AbstractHistogram> internalCountsHistogramClass, AbstractHistogram internalCountsHistogram)

private
DoubleHistogram(final long highestToLowestValueRatio, final int numberOfSignificantValueDigits, final Class<? extends AbstractHistogram> internalCountsHistogramClass, AbstractHistogram internalCountsHistogram, boolean mimicInternalModel)

public
DoubleHistogram(final DoubleHistogram
The source histogram to duplicate
source
)

Construct a org.HdrHistogram.DoubleHistogram with the same range settings as a given source, duplicating the source's start/end timestamps (but NOT it's contents)

Method Summary

Modifier and TypeMethod and Description
public void
add(final DoubleHistogram
The other histogram.
fromHistogram
)

Add the contents of another histogram to this one.

public void
addWhileCorrectingForCoordinatedOmission(final DoubleHistogram
Other histogram. highestToLowestValueRatio and numberOfSignificantValueDigits must match.
fromHistogram
,
final double
If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples
expectedIntervalBetweenValueSamples
)

Add the contents of another histogram to this one, while correcting the incoming data for coordinated omission.

public DoubleHistogram.AllValues
allValues()

Provide a means of iterating through all histogram values using the finest granularity steps supported by the underlying representation.

private void
autoAdjustRangeForValue(final double value)

private synchronized void
autoAdjustRangeForValueSlowPath(final double value)

pack-priv static <T extends DoubleHistogram> T
constructHistogramFromBuffer(int cookie, final ByteBuffer buffer, final Class<T> doubleHistogramClass, final Class<? extends AbstractHistogram> histogramClass, final long minBarForHighestToLowestValueRatio)

public DoubleHistogram

Returns:

A distinct copy of this histogram.
copy
()

Create a copy of this histogram, complete with data and everything.

public DoubleHistogram

Returns:

a copy of this histogram, corrected for coordinated omission.
copyCorrectedForCoordinatedOmission
(final double
If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples
expectedIntervalBetweenValueSamples
)

Get a copy of this histogram, corrected for coordinated omission.

public void
copyInto(final DoubleHistogram
the histogram to copy into
targetHistogram
)

Copy this histogram into the target histogram, overwriting it's contents.

public void
copyIntoCorrectedForCoordinatedOmission(final DoubleHistogram
the histogram to copy into
targetHistogram
,
final double
If expectedIntervalBetweenValueSamples is larger than 0, add auto-generated value records as appropriate if value is larger than expectedIntervalBetweenValueSamples
expectedIntervalBetweenValueSamples
)

Copy this histogram, corrected for coordinated omission, into the target histogram, overwriting it's contents.

public static DoubleHistogram

Returns:

The newly constructed DoubleHistogram
decodeFromByteBuffer
(final ByteBuffer
The buffer to decode from
buffer
,
final long
Force highestTrackableValue to be set at least this high
minBarForHighestToLowestValueRatio
)

Construct a new DoubleHistogram by decoding it from a ByteBuffer.

public static DoubleHistogram

Returns:

The newly constructed DoubleHistogram
decodeFromByteBuffer
(final ByteBuffer
The buffer to decode from
buffer
,
final Class<? extends AbstractHistogram>
The class to use for internal counts tracking
internalCountsHistogramClass
,
long
Force highestTrackableValue to be set at least this high
minBarForHighestToLowestValueRatio
)

Construct a new DoubleHistogram by decoding it from a ByteBuffer, using a specified AbstractHistogram subclass for tracking internal counts (e.g. org.HdrHistogram.Histogram, org.HdrHistogram.ConcurrentHistogram, org.HdrHistogram.SynchronizedHistogram, org.HdrHistogram.IntCountsHistogram, org.HdrHistogram.ShortCountsHistogram).

public static DoubleHistogram

Returns:

The newly constructed DoubleHistogram
decodeFromCompressedByteBuffer
(final ByteBuffer
The buffer to decode from
buffer
,
final long
Force highestTrackableValue to be set at least this high
minBarForHighestToLowestValueRatio
)

Hides org.HdrHistogram.EncodableHistogram.decodeFromCompressedByteBuffer.

Construct a new DoubleHistogram by decoding it from a compressed form in a ByteBuffer.
public static DoubleHistogram

Returns:

The newly constructed DoubleHistogram
decodeFromCompressedByteBuffer
(final ByteBuffer
The buffer to decode from
buffer
,
Class<? extends AbstractHistogram>
The class to use for internal counts tracking
internalCountsHistogramClass
,
long
Force highestTrackableValue to be set at least this high
minBarForHighestToLowestValueRatio
)

Construct a new DoubleHistogram by decoding it from a compressed form in a ByteBuffer, using a specified AbstractHistogram subclass for tracking internal counts (e.g. org.HdrHistogram.Histogram, org.HdrHistogram.AtomicHistogram, org.HdrHistogram.SynchronizedHistogram, org.HdrHistogram.IntCountsHistogram, org.HdrHistogram.ShortCountsHistogram).

private long
deriveIntegerValueRange(final long externalHighestToLowestValueRatio, final int numberOfSignificantValueDigits)

private long
deriveInternalHighestToLowestValueRatio(final long externalHighestToLowestValueRatio)

public synchronized int

Returns:

The number of bytes written to the buffer
encodeIntoByteBuffer
(final ByteBuffer
The buffer to encode into
buffer
)

Encode this histogram into a ByteBuffer

public synchronized int

Returns:

The number of bytes written to the buffer
encodeIntoCompressedByteBuffer
(final ByteBuffer
The buffer to encode into
targetBuffer
,
final int
Compression level (for java.util.zip.Deflater).
compressionLevel
)

Implements abstract org.HdrHistogram.EncodableHistogram.encodeIntoCompressedByteBuffer.

Encode this histogram in compressed form into a byte array
public int

Returns:

The number of bytes written to the array
encodeIntoCompressedByteBuffer
(final ByteBuffer
The buffer to encode into
targetBuffer
)

Encode this histogram in compressed form into a byte array

public boolean

Returns:

True if this histogram are equivalent with the other.
equals
(final Object
the other histogram to compare to
other
)

Overrides java.lang.Object.equals.

Determine if this histogram is equivalent to another.
private int
findCappedContainingBinaryOrderOfMagnitude(final double doubleNumber)

private static int
findContainingBinaryOrderOfMagnitude(final long longNumber)

private static int
findContainingBinaryOrderOfMagnitude(final double doubleNumber)

public static DoubleHistogram

Returns:

A DoubleHistogram decoded from the string
fromString
(final String
A string containing a base64 encoding of a compressed histogram
base64CompressedHistogramString
)

Construct a new DoubleHistogram by decoding it from a String containing a base64 encoded compressed histogram representation.

public long

Returns:

The total count of values recorded in the histogram within the value range that is >= lowestEquivalentValue(value) and <= highestEquivalentValue(value)
getCountAtValue
(final double
The value for which to provide the recorded count
value
)

Get the count of recorded values at a specific value (to within the histogram resolution at the value level).

public double

Returns:

the total count of values recorded in the histogram within the value range that is >= lowestEquivalentValue(lowValue) and <= highestEquivalentValue(highValue)
getCountBetweenValues
(final double
The lower value bound on the range for which to provide the recorded count. Will be rounded down with lowestEquivalentValue.
lowValue
,
final double
The higher value bound on the range for which to provide the recorded count. Will be rounded up with highestEquivalentValue.
highValue
)

Get the count of recorded values within a range of value levels (inclusive to within the histogram's resolution).

pack-priv double

Returns:

current highest trackable value in the automatically determined range
getCurrentHighestTrackableValue
()

get the current highest trackable value in the automatically determined range (keep in mind that this can change because it is auto ranging)

pack-priv double

Returns:

current lowest trackable value the automatically determined range
getCurrentLowestTrackableNonZeroValue
()

get the current lowest (non zero) trackable value the automatically determined range (keep in mind that this can change because it is auto ranging)

pack-priv double
public long

Returns:

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

Implements abstract org.HdrHistogram.EncodableHistogram.getEndTimeStamp.

get the end time stamp [optionally] stored with this histogram
public int

Returns:

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

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

public long

Returns:

the dynamic range of the histogram, expressed as the ratio between the highest trackable value and the lowest trackable non zero value at any given time.
getHighestToLowestValueRatio
()

get the Dynamic range of the histogram: the configured ratio between the highest trackable value and the lowest trackable non zero value at any given time.

public double

Returns:

the current conversion ratio from interval integer value representation to double units.
getIntegerToDoubleValueConversionRatio
()

Get the current conversion ratio from interval integer value representation to double units.

private long
public double

Returns:

the Max value recorded in the histogram
getMaxValue
()

Get the highest recorded value level in the histogram

public double

Returns:

the highest recorded value level in the histogram as a double
getMaxValueAsDouble
()

Implements abstract org.HdrHistogram.EncodableHistogram.getMaxValueAsDouble.

Get the highest recorded value level in the histogram as a double
public double

Returns:

the mean value (in value units) of the histogram data
getMean
()

Get the computed mean value of all recorded values in the histogram

public double

Returns:

the lowest recorded non-zero value level in the histogram
getMinNonZeroValue
()

Get the lowest recorded non-zero value level in the histogram

public double

Returns:

the Min value recorded in the histogram
getMinValue
()

Get the lowest recorded value level in the histogram

public int

Returns:

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

Implements abstract org.HdrHistogram.EncodableHistogram.getNeededByteBufferCapacity.

Get the capacity needed to encode this histogram into a ByteBuffer
private int
getNeededByteBufferCapacity(final int relevantLength)

public int

Returns:

numberOfSignificantValueDigits
getNumberOfSignificantValueDigits
()

get the configured numberOfSignificantValueDigits

public double

Returns:

The percentile of values recorded in the histogram that are smaller than or equivalent to the given value.
getPercentileAtOrBelowValue
(final double
The value for which to return the associated percentile
value
)

Get the percentile at a given value.

public long

Returns:

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

Implements abstract org.HdrHistogram.EncodableHistogram.getStartTimeStamp.

get the start time stamp [optionally] stored with this histogram
public double

Returns:

the standard deviation (in value units) of the histogram data
getStdDeviation
()

Get the computed standard deviation of all recorded values in the histogram

public String

Returns:

tag string [optionally] associated with this histogram
getTag
()

Implements abstract org.HdrHistogram.EncodableHistogram.getTag.

get the tag string [optionally] associated with this histogram
public long

Returns:

the total count of all recorded values in the histogram
getTotalCount
()

Get the total count of all recorded values in the histogram

public double

Returns:

The value that the given percentage of the overall recorded value entries in the histogram are either smaller than or equivalent to. When the percentile is 0.0, returns the value that all value entries in the histogram are either larger than or equivalent to.
getValueAtPercentile
(final double
The percentile for which to return the associated value
percentile
)

Get the value at a given percentile.

private void
handleShiftValuesException(final int numberOfBinaryOrdersOfMagnitude, Exception ex)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public double

Returns:

The highest value that is equivalent to the given value within the histogram's resolution.
highestEquivalentValue
(final double
The given value
value
)

Get the highest value that is equivalent to the given value within the histogram's resolution.

private void
init(final long configuredHighestToLowestValueRatio, final double lowestTrackableUnitValue, final AbstractHistogram integerValuesHistogram)

public boolean
pack-priv static boolean
pack-priv static boolean
pack-priv static boolean
public DoubleHistogram.LinearBucketValues

Returns:

An java.lang.Iterable<DoubleHistogramIterationValue> through the histogram using a DoubleLinearIterator
linearBucketValues
(final double
The size (in value units) of the linear buckets to use
valueUnitsPerBucket
)

Provide a means of iterating through histogram values using linear steps.

public DoubleHistogram.LogarithmicBucketValues
logarithmicBucketValues(final double
The size (in value units) of the first bucket in the iteration
valueUnitsInFirstBucket
,
final double
The multiplier by which bucket sizes will grow in each iteration step
logBase
)

Provide a means of iterating through histogram values at logarithmically increasing levels.

public double

Returns:

The lowest value that is equivalent to the given value within the histogram's resolution.
lowestEquivalentValue
(final double
The given value
value
)

Get the lowest value that is equivalent to the given value within the histogram's resolution.

public double

Returns:

The value lies in the middle (rounded up) of the range of values equivalent the given value.
medianEquivalentValue
(final double
The given value
value
)

Get a value that lies in the middle (rounded up) of the range of values equivalent the given value.

public double

Returns:

The next value that is not equivalent to the given value within the histogram's resolution.
nextNonEquivalentValue
(final double
The given value
value
)

Get the next value that is not equivalent to the given value within the histogram's resolution.

public void
outputPercentileDistribution(final PrintStream
Stream into which the distribution will be output

printStream
,
final Double
The scaling factor by which to divide histogram recorded values units in output
outputValueUnitScalingRatio
)

Produce textual representation of the value distribution of histogram data by percentile.

public void
outputPercentileDistribution(final PrintStream
Stream into which the distribution will be output

printStream
,
final int
The number of reporting points per exponentially decreasing half-distance

percentileTicksPerHalfDistance
,
final Double
The scaling factor by which to divide histogram recorded values units in output
outputValueUnitScalingRatio
)

Produce textual representation of the value distribution of histogram data by percentile.

public void
outputPercentileDistribution(final PrintStream
Stream into which the distribution will be output

printStream
,
final int
The number of reporting points per exponentially decreasing half-distance

percentileTicksPerHalfDistance
,
final Double
The scaling factor by which to divide histogram recorded values units in output
outputValueUnitScalingRatio
,
final boolean
Output in CSV format if true. Otherwise use plain text form.
useCsvFormat
)

Produce textual representation of the value distribution of histogram data by percentile.

public DoubleHistogram.Percentiles
percentiles(final int
The number of iteration steps per half-distance to 100%.
percentileTicksPerHalfDistance
)

Provide a means of iterating through histogram values according to percentile levels.

private void
private void
recordCountAtValue(final long count, final double value)

public DoubleHistogram.RecordedValues
recordedValues()

Provide a means of iterating through all recorded histogram values using the finest granularity steps supported by the underlying representation.

private void
recordSingleValue(final double value)

public void
recordValue(final double
The value to be recorded
value
)

Implements org.HdrHistogram.DoubleValueRecorder.recordValue.

Record a value in the histogram
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)
private void
recordValueWithCountAndExpectedInterval(final double value, final long count, final double expectedIntervalBetweenValueSamples)

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 in the histogram.
public void
reset()

Implements org.HdrHistogram.DoubleValueRecorder.reset.

Reset the contents and stats of this histogram
public void
setAutoResize(boolean autoResize)

public void
setEndTimeStamp(final long
the value to set the time stamp to, [by convention] in msec since the epoch.
timeStampMsec
)

Implements abstract org.HdrHistogram.EncodableHistogram.setEndTimeStamp.

Set the end time stamp value associated with this histogram to a given value.
public void
setStartTimeStamp(final long
the value to set the time stamp to, [by convention] in msec since the epoch.
timeStampMsec
)

Implements abstract org.HdrHistogram.EncodableHistogram.setStartTimeStamp.

Set the start time stamp value associated with this histogram to a given value.
public void
setTag(String
the tag string to assciate with this histogram
tag
)

Implements abstract org.HdrHistogram.EncodableHistogram.setTag.

Set the tag string associated with this histogram
private void
setTrackableValueRange(final double lowestValueInAutoRange, final double highestValueInAutoRange)

private void
shiftCoveredRangeToTheLeft(final int numberOfBinaryOrdersOfMagnitude)

private void
shiftCoveredRangeToTheRight(final int numberOfBinaryOrdersOfMagnitude)

public double

Returns:

The lowest value that is equivalent to the given value within the histogram's resolution.
sizeOfEquivalentValueRange
(final double
The given value
value
)

Get the size (in value units) of the range of values that are equivalent to the given value within the histogram's resolution.

public void
subtract(final DoubleHistogram
The other histogram.
otherHistogram
)

Subtract the contents of another histogram from this one.

public boolean

Returns:

True if values are equivalent to within the histogram's resolution.
valuesAreEquivalent
(final double
first value to compare
value1
,
final double
second value to compare
value2
)

Determine if two values are equivalent with the histogram's resolution.

private void