com.twitter.common.stats
Class Percentile<T extends Number & Comparable<T>>

java.lang.Object
  extended by com.twitter.common.stats.Percentile<T>

public class Percentile<T extends Number & Comparable<T>>
extends Object

A stats tracker to export percentiles of inputs based on a sampling rate. A percentile tracker will randomly sample recorded events with the given sampling rate, and will automatically register variables to track the percentiles requested. Percentiles are calculated based on the K most recent sampling windows, where each sampling window has the recorded events for a sampling period.


Constructor Summary
Percentile(String name, float samplePercent, double... percentiles)
          Creates a new percentile tracker.
Percentile(String name, int numSampleWindows, Sampler sampler, double... percentiles)
          Creates a new percentile tracker.
Percentile(String name, Sampler sampler, double... percentiles)
          Creates a new percentile tracker.
 
Method Summary
 Map<Double,? extends Stat> getPercentiles()
          Get the variables associated with this percentile tracker.
 void record(T value)
          Records an event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Percentile

public Percentile(String name,
                  float samplePercent,
                  double... percentiles)
Creates a new percentile tracker.

Parameters:
name - The name of the value whose percentile is being tracked.
samplePercent - The percent of events to sample [0, 100].
percentiles - The percentiles to track.

Percentile

public Percentile(String name,
                  Sampler sampler,
                  double... percentiles)
Creates a new percentile tracker.

Parameters:
name - The name of the value whose percentile is being tracked.
sampler - The sampler to use for selecting recorded events.
percentiles - The percentiles to track.

Percentile

public Percentile(String name,
                  int numSampleWindows,
                  @Nullable
                  Sampler sampler,
                  double... percentiles)
Creates a new percentile tracker. A percentile tracker will randomly sample recorded events with the given sampling rate, and will automatically register variables to track the percentiles requested. When allowFlushAfterSample is set to true, once the last percentile is sampled, all recorded values are flushed in preparation for the next window; otherwise, the percentile is calculated using the moving window of the most recent values.

Parameters:
name - The name of the value whose percentile is being tracked.
numSampleWindows - How many sampling windows are used for calculation.
sampler - The sampler to use for selecting recorded events. You may set sampler to null to sample all input.
percentiles - The percentiles to track.
Method Detail

getPercentiles

public Map<Double,? extends Stat> getPercentiles()
Get the variables associated with this percentile tracker.

Returns:
A map from tracked percentile to the Stat corresponding to it

record

public void record(T value)
Records an event.

Parameters:
value - The value to record if it is randomly selected based on the sampling rate.