public abstract class AbstractHistogram extends AbstractHistogramBase implements ValueRecorder, java.io.Serializable
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.
Modifier and Type | Class and Description |
---|---|
class |
AbstractHistogram.AllValues
|
class |
AbstractHistogram.LinearBucketValues
|
class |
AbstractHistogram.LogarithmicBucketValues
|
class |
AbstractHistogram.Percentiles
|
class |
AbstractHistogram.RecordedValues
|
Modifier and Type | Field and Description |
---|---|
private static int |
compressedEncodingCookieBase |
private static java.lang.Class[] |
constructorArgsTypes |
private static int |
ENCODING_HEADER_SIZE |
private static int |
encodingCookieBase |
(package private) int |
leadingZeroCountBase
Number of leading zeros in the largest value that can fit in bucket 0.
|
(package private) long |
maxValue |
private static java.util.concurrent.atomic.AtomicLongFieldUpdater<AbstractHistogram> |
maxValueUpdater |
(package private) long |
minNonZeroValue |
private static java.util.concurrent.atomic.AtomicLongFieldUpdater<AbstractHistogram> |
minNonZeroValueUpdater |
private static long |
serialVersionUID |
(package private) int |
subBucketHalfCount |
(package private) int |
subBucketHalfCountMagnitude |
(package private) long |
subBucketMask
Biggest value that can fit in bucket 0
|
(package private) int |
unitMagnitude
Largest k such that 2^k <= lowestDiscernibleValue
|
(package private) long |
unitMagnitudeMask
Lowest unitMagnitude bits are set
|
private static int |
V0_ENCODING_HEADER_SIZE |
private static int |
V0CompressedEncodingCookieBase |
private static int |
V0EncodingCookieBase |
private static int |
V1CompressedEncodingCookieBase |
private static int |
V1EncodingCookieBase |
private static int |
V2CompressedEncodingCookieBase |
private static int |
V2EncodingCookieBase |
private static int |
V2maxWordSizeInBytes |
autoResize, bucketCount, constructionIdentityCount, countsArrayLength, doubleToIntegerValueConversionRatio, endTimeStampMsec, highestTrackableValue, identity, integerToDoubleValueConversionRatio, intermediateUncompressedByteArray, intermediateUncompressedByteBuffer, lowestDiscernibleValue, numberOfSignificantValueDigits, percentileIterator, recordedValuesIterator, startTimeStampMsec, subBucketCount, tag, wordSizeInBytes
Modifier | Constructor and Description |
---|---|
protected |
AbstractHistogram(AbstractHistogram source)
Construct a histogram with the same range settings as a given source histogram,
duplicating the source's start/end timestamps (but NOT it's contents)
|
protected |
AbstractHistogram(int numberOfSignificantValueDigits)
Construct an auto-resizing histogram with a lowest discernible value of 1 and an auto-adjusting
highestTrackableValue.
|
protected |
AbstractHistogram(long lowestDiscernibleValue,
long highestTrackableValue,
int numberOfSignificantValueDigits)
Construct a histogram given the Lowest and Highest values to be tracked and a number of significant
decimal digits.
|
Modifier and Type | Method and Description |
---|---|
(package private) abstract int |
_getEstimatedFootprintInBytes() |
void |
add(AbstractHistogram otherHistogram)
Add the contents of another histogram to this one.
|
(package private) abstract void |
addToCountAtIndex(int index,
long value) |
(package private) abstract void |
addToTotalCount(long value) |
void |
addWhileCorrectingForCoordinatedOmission(AbstractHistogram otherHistogram,
long expectedIntervalBetweenValueSamples)
Add the contents of another histogram to this one, while correcting the incoming data for coordinated omission.
|
AbstractHistogram.AllValues |
allValues()
Provide a means of iterating through all histogram values using the finest granularity steps supported by
the underlying representation.
|
(package private) abstract void |
clearCounts() |
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.
|
private int |
countsArrayIndex(int bucketIndex,
int subBucketIndex) |
(package private) int |
countsArrayIndex(long value) |
(package private) static <T extends AbstractHistogram> |
decodeFromByteBuffer(java.nio.ByteBuffer buffer,
java.lang.Class<T> histogramClass,
long minBarForHighestTrackableValue) |
private static <T extends AbstractHistogram> |
decodeFromByteBuffer(java.nio.ByteBuffer buffer,
java.lang.Class<T> histogramClass,
long minBarForHighestTrackableValue,
java.util.zip.Inflater decompressor) |
(package private) static <T extends AbstractHistogram> |
decodeFromCompressedByteBuffer(java.nio.ByteBuffer buffer,
java.lang.Class<T> histogramClass,
long minBarForHighestTrackableValue) |
(package private) int |
determineArrayLengthNeeded(long highestTrackableValue) |
int |
encodeIntoByteBuffer(java.nio.ByteBuffer buffer)
Encode this histogram into a ByteBuffer
|
int |
encodeIntoCompressedByteBuffer(java.nio.ByteBuffer targetBuffer)
Encode this histogram in compressed form into a byte array
|
int |
encodeIntoCompressedByteBuffer(java.nio.ByteBuffer targetBuffer,
int compressionLevel)
Encode this histogram in compressed form into a byte array
|
boolean |
equals(java.lang.Object other)
Determine if this histogram is equivalent to another.
|
(package private) void |
establishInternalTackingValues() |
(package private) void |
establishInternalTackingValues(int lengthToCover) |
(package private) void |
establishSize(long newHighestTrackableValue)
The buckets (each of which has subBucketCount sub-buckets, here assumed to be 2048 as an example) overlap:
|
(package private) void |
fillBufferFromCountsArray(java.nio.ByteBuffer buffer) |
(package private) abstract void |
fillCountsArrayFromBuffer(java.nio.ByteBuffer buffer,
int length) |
private int |
fillCountsArrayFromSourceBuffer(java.nio.ByteBuffer sourceBuffer,
int lengthInBytes,
int wordSizeInBytes) |
(package private) int |
getBucketIndex(long value) |
(package private) int |
getBucketsNeededToCoverValue(long value) |
private int |
getCompressedEncodingCookie() |
private static int |
getCookieBase(int cookie) |
(package private) abstract long |
getCountAtIndex(int index) |
(package private) abstract long |
getCountAtNormalizedIndex(int index) |
long |
getCountAtValue(long value)
Get the count of recorded values at a specific value (to within the histogram resolution at the value level).
|
long |
getCountBetweenValues(long lowValue,
long highValue)
Get the count of recorded values within a range of value levels (inclusive to within the histogram's resolution).
|
private int |
getEncodingCookie() |
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
|
(package private) int |
getLengthForNumberOfBuckets(int numberOfBuckets)
If we have N such that subBucketCount * 2^N > max value, we need storage for N+1 buckets, each with enough
slots to hold the top half of the subBucketCount (the lower half is covered by previous buckets), and the +1
being used for the lower half of the 0'th bucket.
|
long |
getLowestDiscernibleValue()
get the configured lowestDiscernibleValue
|
long |
getMaxValue()
Get the highest recorded value level in the histogram.
|
double |
getMaxValueAsDouble()
Get the highest recorded value level in the histogram as a double
|
double |
getMean()
Get the computed mean value of all recorded values in the histogram
|
long |
getMinNonZeroValue()
Get the lowest recorded non-zero value level in the histogram.
|
long |
getMinValue()
Get the lowest recorded value level in the histogram.
|
int |
getNeededByteBufferCapacity()
Get the capacity needed to encode this histogram into a ByteBuffer
|
(package private) int |
getNeededByteBufferCapacity(int relevantLength) |
(package private) int |
getNeededPayloadByteBufferCapacity(int relevantLength) |
(package private) int |
getNeededV0PayloadByteBufferCapacity(int relevantLength) |
(package private) abstract int |
getNormalizingIndexOffset() |
int |
getNumberOfSignificantValueDigits()
get the configured numberOfSignificantValueDigits
|
double |
getPercentileAtOrBelowValue(long value)
Get the percentile at a given value.
|
long |
getStartTimeStamp()
get the start time stamp [optionally] stored with this histogram
|
double |
getStdDeviation()
Get the computed standard deviation of all recorded values in the histogram
|
(package private) int |
getSubBucketIndex(long value,
int bucketIndex) |
java.lang.String |
getTag()
get the tag string [optionally] associated with this histogram
|
abstract long |
getTotalCount()
Get the total count of all recorded values in the histogram
|
long |
getValueAtPercentile(double percentile)
Get the value at a given percentile.
|
private static int |
getWordSizeInBytesFromCookie(int cookie) |
private void |
handleRecordException(long count,
long value,
java.lang.Exception ex) |
int |
hashCode() |
long |
highestEquivalentValue(long value)
Get the highest value that is equivalent to the given value within the histogram's resolution.
|
(package private) abstract void |
incrementCountAtIndex(int index) |
(package private) abstract void |
incrementTotalCount() |
private void |
init(long lowestDiscernibleValue,
long highestTrackableValue,
int numberOfSignificantValueDigits,
double integerToDoubleValueConversionRatio,
int normalizingIndexOffset) |
boolean |
isAutoResize()
Indicate whether or not the histogram is set to auto-resize and auto-adjust it's
highestTrackableValue
|
AbstractHistogram.LinearBucketValues |
linearBucketValues(long valueUnitsPerBucket)
Provide a means of iterating through histogram values using linear steps.
|
AbstractHistogram.LogarithmicBucketValues |
logarithmicBucketValues(long valueUnitsInFirstBucket,
double logBase)
Provide a means of iterating through histogram values at logarithmically increasing levels.
|
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.
|
(package private) void |
nonConcurrentNormalizingIndexShift(int shiftAmount,
boolean lowestHalfBucketPopulated) |
(package private) int |
normalizeIndex(int index,
int normalizingIndexOffset,
int arrayLength) |
(package private) static int |
numberOfSubbuckets(int numberOfSignificantValueDigits) |
private int |
oneAtATimeHashStep(int h,
int v) |
void |
outputPercentileDistribution(java.io.PrintStream printStream,
java.lang.Double outputValueUnitScalingRatio)
Produce textual representation of the value distribution of histogram data by percentile.
|
void |
outputPercentileDistribution(java.io.PrintStream printStream,
int percentileTicksPerHalfDistance,
java.lang.Double outputValueUnitScalingRatio)
Produce textual representation of the value distribution of histogram data by percentile.
|
void |
outputPercentileDistribution(java.io.PrintStream printStream,
int percentileTicksPerHalfDistance,
java.lang.Double outputValueUnitScalingRatio,
boolean useCsvFormat)
Produce textual representation of the value distribution of histogram data by percentile.
|
AbstractHistogram.Percentiles |
percentiles(int percentileTicksPerHalfDistance)
Provide a means of iterating through histogram values according to percentile levels.
|
private void |
readObject(java.io.ObjectInputStream o) |
(package private) void |
recordConvertedDoubleValue(double value) |
void |
recordConvertedDoubleValueWithCount(double value,
long count) |
private void |
recordCountAtValue(long count,
long value) |
AbstractHistogram.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(long value) |
private void |
recordSingleValueWithExpectedInterval(long value,
long expectedIntervalBetweenValueSamples) |
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)
|
private void |
recordValueWithCountAndExpectedInterval(long value,
long count,
long expectedIntervalBetweenValueSamples) |
void |
recordValueWithExpectedInterval(long value,
long expectedIntervalBetweenValueSamples)
Record a value in the histogram.
|
void |
reset()
Reset the contents and stats of this histogram
|
private void |
resetMaxValue(long maxValue) |
private void |
resetMinNonZeroValue(long minNonZeroValue) |
(package private) abstract void |
resize(long newHighestTrackableValue) |
void |
setAutoResize(boolean autoResize)
Control whether or not the histogram can auto-resize and auto-adjust it's
highestTrackableValue
|
(package private) abstract void |
setCountAtIndex(int index,
long value) |
(package private) abstract void |
setCountAtNormalizedIndex(int index,
long value) |
void |
setEndTimeStamp(long timeStampMsec)
Set the end time stamp value associated with this histogram to a given value.
|
(package private) abstract void |
setNormalizingIndexOffset(int normalizingIndexOffset) |
void |
setStartTimeStamp(long timeStampMsec)
Set the start time stamp value associated with this histogram to a given value.
|
void |
setTag(java.lang.String tag)
Set the tag string associated with this histogram
|
(package private) abstract void |
setTotalCount(long totalCount) |
private void |
shiftLowestHalfBucketContentsLeft(int shiftAmount,
int preShiftZeroIndex) |
(package private) abstract void |
shiftNormalizingIndexByOffset(int offsetToAdd,
boolean lowestHalfBucketPopulated,
double newIntegerToDoubleValueConversionRatio) |
void |
shiftValuesLeft(int numberOfBinaryOrdersOfMagnitude)
Shift recorded values to the left (the equivalent of a << shift operation on all recorded values).
|
(package private) void |
shiftValuesLeft(int numberOfBinaryOrdersOfMagnitude,
double newIntegerToDoubleValueConversionRatio) |
void |
shiftValuesRight(int numberOfBinaryOrdersOfMagnitude)
Shift recorded values to the right (the equivalent of a >> shift operation on all recorded values).
|
(package private) void |
shiftValuesRight(int numberOfBinaryOrdersOfMagnitude,
double newIntegerToDoubleValueConversionRatio) |
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.
|
void |
subtract(AbstractHistogram otherHistogram)
Subtract the contents of another histogram from this one.
|
boolean |
supportsAutoResize()
Indicate whether or not the histogram is capable of supporting auto-resize functionality.
|
private void |
updatedMaxValue(long value)
Set internally tracked maxValue to new value if new value is greater than current one.
|
(package private) void |
updateMinAndMax(long value) |
private void |
updateMinNonZeroValue(long value)
Set internally tracked minNonZeroValue to new value if new value is smaller than current one.
|
(package private) long |
valueFromIndex(int index) |
private long |
valueFromIndex(int bucketIndex,
int subBucketIndex) |
boolean |
valuesAreEquivalent(long value1,
long value2)
Determine if two values are equivalent with the histogram's resolution.
|
private void |
writeObject(java.io.ObjectOutputStream o) |
getDoubleToIntegerValueConversionRatio, getIntegerToDoubleValueConversionRatio, nonConcurrentSetIntegerToDoubleValueConversionRatio, setIntegerToDoubleValueConversionRatio
decodeFromCompressedByteBuffer
int leadingZeroCountBase
int subBucketHalfCountMagnitude
int unitMagnitude
int subBucketHalfCount
long subBucketMask
long unitMagnitudeMask
volatile long maxValue
volatile long minNonZeroValue
private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<AbstractHistogram> maxValueUpdater
private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<AbstractHistogram> minNonZeroValueUpdater
private static final long serialVersionUID
private static final int ENCODING_HEADER_SIZE
private static final int V0_ENCODING_HEADER_SIZE
private static final int V0EncodingCookieBase
private static final int V0CompressedEncodingCookieBase
private static final int V1EncodingCookieBase
private static final int V1CompressedEncodingCookieBase
private static final int V2EncodingCookieBase
private static final int V2CompressedEncodingCookieBase
private static final int V2maxWordSizeInBytes
private static final int encodingCookieBase
private static final int compressedEncodingCookieBase
private static final java.lang.Class[] constructorArgsTypes
protected AbstractHistogram(int numberOfSignificantValueDigits)
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.protected AbstractHistogram(long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits)
lowestDiscernibleValue
- The lowest value that can be discerned (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
- 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.protected AbstractHistogram(AbstractHistogram source)
source
- The source histogram to duplicateabstract long getCountAtIndex(int index)
abstract long getCountAtNormalizedIndex(int index)
abstract void incrementCountAtIndex(int index)
abstract void addToCountAtIndex(int index, long value)
abstract void setCountAtIndex(int index, long value)
abstract void setCountAtNormalizedIndex(int index, long value)
abstract int getNormalizingIndexOffset()
abstract void setNormalizingIndexOffset(int normalizingIndexOffset)
abstract void shiftNormalizingIndexByOffset(int offsetToAdd, boolean lowestHalfBucketPopulated, double newIntegerToDoubleValueConversionRatio)
abstract void setTotalCount(long totalCount)
abstract void incrementTotalCount()
abstract void addToTotalCount(long value)
abstract void clearCounts()
abstract int _getEstimatedFootprintInBytes()
abstract void resize(long newHighestTrackableValue)
public abstract long getTotalCount()
private void updatedMaxValue(long value)
value
- new maxValue to setprivate void resetMaxValue(long maxValue)
private void updateMinNonZeroValue(long value)
value
- new minNonZeroValue to setprivate void resetMinNonZeroValue(long minNonZeroValue)
private void init(long lowestDiscernibleValue, long highestTrackableValue, int numberOfSignificantValueDigits, double integerToDoubleValueConversionRatio, int normalizingIndexOffset)
final void establishSize(long newHighestTrackableValue)
The 0'th bucket covers from 0...2047 in multiples of 1, using all 2048 sub-buckets The 1'th bucket covers from 2048..4097 in multiples of 2, using only the top 1024 sub-buckets The 2'th bucket covers from 4096..8191 in multiple of 4, using only the top 1024 sub-buckets ...Bucket 0 is "special" here. It is the only one that has 2048 entries. All the rest have 1024 entries (because their bottom half overlaps with and is already covered by the all of the previous buckets put together). In other words, the k'th bucket could represent 0 * 2^k to 2048 * 2^k in 2048 buckets with 2^k precision, but the midpoint of 1024 * 2^k = 2048 * 2^(k-1) = the k-1'th bucket's end, so we would use the previous bucket for those lower values as it has better precision.
final int determineArrayLengthNeeded(long highestTrackableValue)
public boolean isAutoResize()
public boolean supportsAutoResize()
public void setAutoResize(boolean autoResize)
autoResize
- autoResize settingpublic void recordValue(long value) throws java.lang.ArrayIndexOutOfBoundsException
recordValue
in interface ValueRecorder
value
- The value to be recordedjava.lang.ArrayIndexOutOfBoundsException
- (may throw) if value is exceeds highestTrackableValuepublic void recordValueWithCount(long value, long count) throws java.lang.ArrayIndexOutOfBoundsException
recordValueWithCount
in interface ValueRecorder
value
- The value to be recordedcount
- The number of occurrences of this value to recordjava.lang.ArrayIndexOutOfBoundsException
- (may throw) if value is exceeds highestTrackableValuepublic void recordValueWithExpectedInterval(long value, long expectedIntervalBetweenValueSamples) throws java.lang.ArrayIndexOutOfBoundsException
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 copyCorrectedForCoordinatedOmission(long)
.
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.
recordValueWithExpectedInterval
in interface ValueRecorder
value
- The value to recordexpectedIntervalBetweenValueSamples
- If expectedIntervalBetweenValueSamples is larger than 0, add
auto-generated value records as appropriate if value is larger
than expectedIntervalBetweenValueSamplesjava.lang.ArrayIndexOutOfBoundsException
- (may throw) if value is exceeds highestTrackableValuevoid recordConvertedDoubleValue(double value)
public void recordConvertedDoubleValueWithCount(double value, long count) throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
public void recordValue(long value, long expectedIntervalBetweenValueSamples) throws java.lang.ArrayIndexOutOfBoundsException
recordValueWithExpectedInterval()
. It was renamed to avoid ambiguity.value
- The value to recordexpectedIntervalBetweenValueSamples
- If expectedIntervalBetweenValueSamples is larger than 0, add
auto-generated value records as appropriate if value is larger
than expectedIntervalBetweenValueSamplesjava.lang.ArrayIndexOutOfBoundsException
- (may throw) if value is exceeds highestTrackableValuevoid updateMinAndMax(long value)
private void recordCountAtValue(long count, long value) throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
private void recordSingleValue(long value) throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
private void handleRecordException(long count, long value, java.lang.Exception ex)
private void recordValueWithCountAndExpectedInterval(long value, long count, long expectedIntervalBetweenValueSamples) throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
private void recordSingleValueWithExpectedInterval(long value, long expectedIntervalBetweenValueSamples) throws java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
public void reset()
reset
in interface ValueRecorder
public abstract AbstractHistogram copy()
public abstract AbstractHistogram copyCorrectedForCoordinatedOmission(long expectedIntervalBetweenValueSamples)
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.
expectedIntervalBetweenValueSamples
- If expectedIntervalBetweenValueSamples is larger than 0, add
auto-generated value records as appropriate if value is larger
than expectedIntervalBetweenValueSamplespublic void copyInto(AbstractHistogram targetHistogram)
targetHistogram
- the histogram to copy intopublic void copyIntoCorrectedForCoordinatedOmission(AbstractHistogram targetHistogram, long expectedIntervalBetweenValueSamples)
copyCorrectedForCoordinatedOmission(long)
for more detailed explanation about how correction is applied)targetHistogram
- the histogram to copy intoexpectedIntervalBetweenValueSamples
- If expectedIntervalBetweenValueSamples is larger than 0, add
auto-generated value records as appropriate if value is larger
than expectedIntervalBetweenValueSamplespublic void add(AbstractHistogram otherHistogram) throws java.lang.ArrayIndexOutOfBoundsException
As part of adding the contents, the start/end timestamp range of this histogram will be extended to include the start/end timestamp range of the other histogram.
otherHistogram
- The other histogram.java.lang.ArrayIndexOutOfBoundsException
- (may throw) if values in fromHistogram's are
higher than highestTrackableValue.public void subtract(AbstractHistogram otherHistogram) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.IllegalArgumentException
The start/end timestamps of this histogram will remain unchanged.
otherHistogram
- The other histogram.java.lang.ArrayIndexOutOfBoundsException
- (may throw) if values in otherHistogram's are higher than highestTrackableValue.java.lang.IllegalArgumentException
public void addWhileCorrectingForCoordinatedOmission(AbstractHistogram otherHistogram, long expectedIntervalBetweenValueSamples)
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.
otherHistogram
- 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 expectedIntervalBetweenValueSamplesjava.lang.ArrayIndexOutOfBoundsException
- (may throw) if values exceed highestTrackableValuepublic void shiftValuesLeft(int numberOfBinaryOrdersOfMagnitude)
ArrayIndexOutOfBoundsException
will be thrown if any recorded values may be lost
as a result of the attempted operation, reflecting an "overflow" conditions. Expect such an overflow
exception if the operation would cause the current maxValue to be scaled to a value that is outside
of the covered value range.numberOfBinaryOrdersOfMagnitude
- The number of binary orders of magnitude to shift byvoid shiftValuesLeft(int numberOfBinaryOrdersOfMagnitude, double newIntegerToDoubleValueConversionRatio)
void nonConcurrentNormalizingIndexShift(int shiftAmount, boolean lowestHalfBucketPopulated)
private void shiftLowestHalfBucketContentsLeft(int shiftAmount, int preShiftZeroIndex)
public void shiftValuesRight(int numberOfBinaryOrdersOfMagnitude)
Shift right operations that do not underflow are reversible with a shift left operation with no loss of
information. An ArrayIndexOutOfBoundsException
reflecting an "underflow" conditions will be thrown
if any recorded values may lose representation accuracy as a result of the attempted shift operation.
For a shift of a single order of magnitude, expect such an underflow exception if any recorded non-zero values up to [numberOfSignificantValueDigits (rounded up to nearest power of 2) multiplied by (2 ^ numberOfBinaryOrdersOfMagnitude) currently exist in the histogram.
numberOfBinaryOrdersOfMagnitude
- The number of binary orders of magnitude to shift byvoid shiftValuesRight(int numberOfBinaryOrdersOfMagnitude, double newIntegerToDoubleValueConversionRatio)
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- the other histogram to compare topublic int hashCode()
hashCode
in class java.lang.Object
private int oneAtATimeHashStep(int h, int v)
public long getLowestDiscernibleValue()
public long getHighestTrackableValue()
public int getNumberOfSignificantValueDigits()
public long sizeOfEquivalentValueRange(long value)
value
- The given valuepublic long lowestEquivalentValue(long value)
value
- The given valuepublic long highestEquivalentValue(long value)
value
- The given valuepublic long medianEquivalentValue(long value)
value
- The given valuepublic long nextNonEquivalentValue(long value)
value
- The given valuepublic boolean valuesAreEquivalent(long value1, long value2)
value1
- first value to comparevalue2
- second value to comparepublic int getEstimatedFootprintInBytes()
public long getStartTimeStamp()
getStartTimeStamp
in class EncodableHistogram
public void setStartTimeStamp(long timeStampMsec)
setStartTimeStamp
in class EncodableHistogram
timeStampMsec
- the value to set the time stamp to, [by convention] in msec since the epoch.public long getEndTimeStamp()
getEndTimeStamp
in class EncodableHistogram
public void setEndTimeStamp(long timeStampMsec)
setEndTimeStamp
in class EncodableHistogram
timeStampMsec
- the value to set the time stamp to, [by convention] in msec since the epoch.public java.lang.String getTag()
getTag
in class EncodableHistogram
public void setTag(java.lang.String tag)
setTag
in class EncodableHistogram
tag
- the tag string to assciate with this histogrampublic long getMinValue()
public long getMaxValue()
public long getMinNonZeroValue()
public double getMaxValueAsDouble()
getMaxValueAsDouble
in class EncodableHistogram
public double getMean()
public double getStdDeviation()
public long getValueAtPercentile(double percentile)
Note that two values are "equivalent" in this statement if
valuesAreEquivalent(long, long)
would return true.
percentile
- The percentile for which to return the associated valuepublic double getPercentileAtOrBelowValue(long value)
Note that two values are "equivalent" in this statement if
valuesAreEquivalent(long, long)
would return true.
value
- The value for which to return the associated percentilepublic long getCountBetweenValues(long lowValue, long highValue) throws java.lang.ArrayIndexOutOfBoundsException
lowValue
- The lower value bound on the range for which
to provide the recorded count. Will be rounded down with
lowestEquivalentValue
.highValue
- The higher value bound on the range for which to provide the recorded count.
Will be rounded up with highestEquivalentValue
.java.lang.ArrayIndexOutOfBoundsException
public long getCountAtValue(long value) throws java.lang.ArrayIndexOutOfBoundsException
value
- The value for which to provide the recorded countjava.lang.ArrayIndexOutOfBoundsException
public AbstractHistogram.Percentiles percentiles(int percentileTicksPerHalfDistance)
percentileTicksPerHalfDistance
- The number of iteration steps per half-distance to 100%.Iterable
<HistogramIterationValue
>
through the histogram using a
PercentileIterator
public AbstractHistogram.LinearBucketValues linearBucketValues(long valueUnitsPerBucket)
valueUnitsPerBucket
- The size (in value units) of the linear buckets to useIterable
<HistogramIterationValue
>
through the histogram using a
LinearIterator
public AbstractHistogram.LogarithmicBucketValues logarithmicBucketValues(long valueUnitsInFirstBucket, double logBase)
valueUnitsInFirstBucket
- The size (in value units) of the first bucket in the iterationlogBase
- The multiplier by which bucket sizes will grow in each iteration stepIterable
<HistogramIterationValue
>
through the histogram using
a LogarithmicIterator
public AbstractHistogram.RecordedValues recordedValues()
Iterable
<HistogramIterationValue
>
through the histogram using
a RecordedValuesIterator
public AbstractHistogram.AllValues allValues()
Iterable
<HistogramIterationValue
>
through the histogram using
a AllValuesIterator
public void outputPercentileDistribution(java.io.PrintStream printStream, java.lang.Double outputValueUnitScalingRatio)
printStream
- Stream into which the distribution will be output
outputValueUnitScalingRatio
- The scaling factor by which to divide histogram recorded values units in
outputpublic void outputPercentileDistribution(java.io.PrintStream printStream, int percentileTicksPerHalfDistance, java.lang.Double outputValueUnitScalingRatio)
printStream
- Stream into which the distribution will be output
percentileTicksPerHalfDistance
- The number of reporting points per exponentially decreasing half-distance
outputValueUnitScalingRatio
- The scaling factor by which to divide histogram recorded values units in
outputpublic void outputPercentileDistribution(java.io.PrintStream printStream, int percentileTicksPerHalfDistance, java.lang.Double outputValueUnitScalingRatio, boolean useCsvFormat)
printStream
- Stream into which the distribution will be output
percentileTicksPerHalfDistance
- The number of reporting points per exponentially decreasing half-distance
outputValueUnitScalingRatio
- The scaling factor by which to divide histogram recorded values units in
outputuseCsvFormat
- Output in CSV format if true. Otherwise use plain text form.private void writeObject(java.io.ObjectOutputStream o) throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream o) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public int getNeededByteBufferCapacity()
getNeededByteBufferCapacity
in class EncodableHistogram
int getNeededByteBufferCapacity(int relevantLength)
int getNeededPayloadByteBufferCapacity(int relevantLength)
int getNeededV0PayloadByteBufferCapacity(int relevantLength)
abstract void fillCountsArrayFromBuffer(java.nio.ByteBuffer buffer, int length)
private int getEncodingCookie()
private int getCompressedEncodingCookie()
private static int getCookieBase(int cookie)
private static int getWordSizeInBytesFromCookie(int cookie)
public int encodeIntoByteBuffer(java.nio.ByteBuffer buffer)
buffer
- The buffer to encode intopublic int encodeIntoCompressedByteBuffer(java.nio.ByteBuffer targetBuffer, int compressionLevel)
encodeIntoCompressedByteBuffer
in class EncodableHistogram
targetBuffer
- The buffer to encode intocompressionLevel
- Compression level (for java.util.zip.Deflater).public int encodeIntoCompressedByteBuffer(java.nio.ByteBuffer targetBuffer)
targetBuffer
- The buffer to encode intostatic <T extends AbstractHistogram> T decodeFromByteBuffer(java.nio.ByteBuffer buffer, java.lang.Class<T> histogramClass, long minBarForHighestTrackableValue)
private static <T extends AbstractHistogram> T decodeFromByteBuffer(java.nio.ByteBuffer buffer, java.lang.Class<T> histogramClass, long minBarForHighestTrackableValue, java.util.zip.Inflater decompressor) throws java.util.zip.DataFormatException
java.util.zip.DataFormatException
private int fillCountsArrayFromSourceBuffer(java.nio.ByteBuffer sourceBuffer, int lengthInBytes, int wordSizeInBytes)
void fillBufferFromCountsArray(java.nio.ByteBuffer buffer)
static <T extends AbstractHistogram> T decodeFromCompressedByteBuffer(java.nio.ByteBuffer buffer, java.lang.Class<T> histogramClass, long minBarForHighestTrackableValue) throws java.util.zip.DataFormatException
java.util.zip.DataFormatException
void establishInternalTackingValues()
void establishInternalTackingValues(int lengthToCover)
int getBucketsNeededToCoverValue(long value)
int getLengthForNumberOfBuckets(int numberOfBuckets)
int countsArrayIndex(long value)
private int countsArrayIndex(int bucketIndex, int subBucketIndex)
int getBucketIndex(long value)
int getSubBucketIndex(long value, int bucketIndex)
int normalizeIndex(int index, int normalizingIndexOffset, int arrayLength)
private long valueFromIndex(int bucketIndex, int subBucketIndex)
final long valueFromIndex(int index)
static int numberOfSubbuckets(int numberOfSignificantValueDigits)