public class Histogram extends Object implements NanoSampler
Histogram class represents a histogram of samples. The histogram is defined by a set of buckets,
each of which counts the number of samples that fall into its range of values. The range of values for each
bucket is determined by a combination of the number of powers of 2 and the number of fraction bits.
Note that this class is marked as SingleThreaded, which means it is not safe for use by multiple threads
simultaneously.
This class implements the NanoSampler interface, which provides a method for sampling values in nanoseconds.
| Constructor and Description |
|---|
Histogram()
Creates a new Histogram with default parameters.
|
Histogram(int powersOf2,
int fractionBits)
Creates a new Histogram with the specified number of powers of 2 and fraction bits.
|
Histogram(int powersOf2,
int fractionBits,
double minValue)
Creates a new Histogram with the specified number of powers of 2, fraction bits, and minimum value.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(@NotNull Histogram h)
Adds the contents of another histogram to this one.
|
boolean |
equals(Object obj) |
long |
floor() |
int |
fractionBits()
Gets the number of fraction bits used by the histogram.
|
double[] |
getPercentiles()
Calculates an array of percentiles based on the total count.
|
double[] |
getPercentiles(double[] percentileFor)
Calculates an array of percentiles for the given set of values.
|
int |
hashCode() |
void |
init(int powersOf2,
int fractionBits,
long overRange,
long totalCount,
long floor)
Re initialise this histogram from deserialized data
|
double |
max()
Gets the maximum value in the histogram.
|
double |
min()
Gets the minimum value in the histogram.
|
long |
overRange()
Gets the number of values that are over the range of the histogram's buckets.
|
double |
percentageLessThan(double time)
Calculates the percentage of values that are less than the given time.
|
double |
percentile(double fraction) |
static double[] |
percentilesFor(long count)
Calculates the percentiles for a given count.
|
int |
powersOf2()
Gets the number of powers of 2 used by the histogram.
|
void |
reset() |
int |
sample(double time)
Samples a value and updates the histogram accordingly.
|
int[] |
sampleCount()
Gets the array of sample counts per bucket.
|
void |
sampleNanos(long durationNs)
Records a sample with the provided duration in nanoseconds.
|
static @NotNull Histogram |
timeMicros() |
@NotNull String |
toLongMicrosFormat()
Returns a string representation of the histogram in a long format suitable for display in microseconds.
|
@NotNull String |
toLongMicrosFormat(@NotNull DoubleFunction<Double> toMicros)
Returns a string representation of the histogram in a long format suitable for display in microseconds.
|
@NotNull String |
toMicrosFormat()
Returns a string representation of the histogram in a format suitable for display in microseconds.
|
@NotNull String |
toMicrosFormat(@NotNull DoubleFunction<Double> toMicros)
Returns a string representation of the histogram in a format suitable for display in microseconds.
|
@NotNull String |
toString() |
long |
totalCount() |
double |
typical()
Gets the median value in the histogram.
|
protected String |
was() |
public Histogram()
public Histogram(int powersOf2,
int fractionBits)
powersOf2 - the number of powers of 2 to use in the histogramfractionBits - the number of fraction bits to use in the histogrampublic Histogram(int powersOf2,
int fractionBits,
double minValue)
powersOf2 - the number of powers of 2 to use in the histogramfractionBits - the number of fraction bits to use in the histogramminValue - the minimum value for the histogram@NotNull public static @NotNull Histogram timeMicros()
public static double[] percentilesFor(long count)
count - the count of valuespublic void init(int powersOf2,
int fractionBits,
long overRange,
long totalCount,
long floor)
public int fractionBits()
public int powersOf2()
public long overRange()
public int[] sampleCount()
public void add(@NotNull
@NotNull Histogram h)
h - the other histogramAssertionError - if the other histogram does not have the same number of powers of 2 and fraction bitspublic int sample(double time)
time - the value to samplepublic double min()
public double typical()
public double max()
public double percentile(double fraction)
public double percentageLessThan(double time)
time - the time to compare the values againstpublic double[] getPercentiles()
public double[] getPercentiles(double[] percentileFor)
percentileFor - an array of values for which to calculate percentiles@NotNull public @NotNull String toMicrosFormat()
@NotNull public @NotNull String toMicrosFormat(@NotNull @NotNull DoubleFunction<Double> toMicros)
toMicros - a function that converts a value to microseconds@NotNull public @NotNull String toLongMicrosFormat()
@NotNull public @NotNull String toLongMicrosFormat(@NotNull @NotNull DoubleFunction<Double> toMicros)
toMicros - a function that converts a value to microsecondsprotected String was()
public long totalCount()
public long floor()
public void reset()
public void sampleNanos(long durationNs)
NanoSamplerThis method must be called from a single thread only. If called from multiple threads or if provided with a negative duration, the result is unspecified and no errors or exceptions should be thrown.
sampleNanos in interface NanoSamplerdurationNs - The duration of the sample in nanoseconds. Must be non-negative.Copyright © 2024. All rights reserved.