|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.opentsdb.stats.Histogram
public final class Histogram
A histogram to keep track of the approximation of a distribution of values.
This is not a general purpose implementation of histogram. It's specifically designed for "small" values (close to 0) as the primary use case is latency histograms.
All values must be positive (>= 0
).
The histogram is linear (fixed size buckets) up to a given cutoff point. Beyond that point, the histogram becomes exponential (each bucket is twice as large as the previous one). This gives good granularity for lower values while still allowing a rough classification for the "long tail" of larger values.
Note that this implementation doesn't allow you to directly control the number of buckets in the histogram. The number will depend on the arguments given to the constructor.
This class is not synchronized.
Constructor Summary | |
---|---|
Histogram(int max,
short interval,
int cutoff)
Constructor. |
Method Summary | |
---|---|
void |
add(int value)
Adds a value to the histogram. |
int |
buckets()
Returns the number of buckets in this histogram. |
int |
percentile(int p)
Returns the value of the pth percentile in this histogram. |
void |
printAscii(StringBuilder out)
Prints this histogram in a human readable ASCII format. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Histogram(int max, short interval, int cutoff)
max
- The maximum value of the histogram. Any value greater
than this will be considered to be "infinity".interval
- The interval (size) of each linear bucket.cutoff
- The value beyond which to switch to exponential
buckets. The histogram may actually use this value or a value up
to interval
greater.
IllegalArgumentException
- if any of following conditions are
not met:
0 < interval <= max 0 <= cutoff <= max
Method Detail |
---|
public int buckets()
public void add(int value)
This method works in O(1)
.
value
- The value to add.
IllegalArgumentException
- if the value given is negative.public int percentile(int p)
This method works in O(N)
where N
is the number of
buckets
.
p
- A strictly positive integer in the range [1; 100]
IllegalArgumentException
- if p
is not valid.public void printAscii(StringBuilder out)
This is equivalent to calling printAsciiBucket(java.lang.StringBuilder, int)
on every
bucket.
out
- The buffer to which to write the output.public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |