Class FastTimer
java.lang.Object
com.codahale.metrics.Timer
org.apache.bookkeeper.stats.codahale.FastTimer
- All Implemented Interfaces:
com.codahale.metrics.Counting,com.codahale.metrics.Metered,com.codahale.metrics.Metric,com.codahale.metrics.Sampling
public class FastTimer
extends com.codahale.metrics.Timer
A fast and (nearly) garbage-free Rate and Response Times Timer.
FastTimer uses circular arrays which are allocated upfront.
Timer updates or queries never allocate new objects and thus never
create garbage.
A small number of new objects are allocated for snapshots when
calling getSnapshot().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines the response time buckets to use.Nested classes/interfaces inherited from class com.codahale.metrics.Timer
com.codahale.metrics.Timer.Context -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new timer with default time window (60 seconds) and default time buckets (fine).FastTimer(int timeWindowSeconds, FastTimer.Buckets buckets) Constructs a new timer. -
Method Summary
Modifier and TypeMethodDescriptionintgetBucket(long duration) Figure out which percentile bucket an event of a given duration belongs into.longgetBucketBound(int b) Returns the upper bucket bound (inclusive) of a given bucket.longgetBucketValue(int b) Returns the average value of a given bucket (the mean between its lower and upper bound).longgetCount()Returns the all-time count of events this timer has seen.doubledoubledoubleintReturns the number of response time buckets used by this timer.doubledoublegetRate(int seconds) Returns the average per-second rate of events this timer has seen.com.codahale.metrics.SnapshotReturns a snapshot of this timer.protected intgetTime()Returns the current absolute time (in seconds).voidAdd an event to this timer.Methods inherited from class com.codahale.metrics.Timer
time, time, time, timeSupplier, update
-
Constructor Details
-
FastTimer
public FastTimer()Constructs a new timer with default time window (60 seconds) and default time buckets (fine). -
FastTimer
Constructs a new timer.- Parameters:
timeWindowSeconds- the time window (in seconds) for this timerbuckets- the type of buckets to use for response times
-
-
Method Details
-
getNumberOfBuckets
public int getNumberOfBuckets()Returns the number of response time buckets used by this timer.- Returns:
- the number of response time buckets
-
getBucket
public int getBucket(long duration) Figure out which percentile bucket an event of a given duration belongs into.- Parameters:
duration- the duration (in nanoseconds)- Returns:
- the bucket
-
getBucketBound
public long getBucketBound(int b) Returns the upper bucket bound (inclusive) of a given bucket.- Parameters:
b- the bucket- Returns:
- the bound (in nanoseconds)
-
getBucketValue
public long getBucketValue(int b) Returns the average value of a given bucket (the mean between its lower and upper bound).- Parameters:
b- the bucket- Returns:
- the average value (in nanoseconds)
-
getTime
protected int getTime()Returns the current absolute time (in seconds).- Returns:
- the current absolute time (in seconds)
-
getRate
public double getRate(int seconds) Returns the average per-second rate of events this timer has seen. The computed rate is calculated for past seconds (not including the current second, which is still being updated). If the specified time exceeds the time window of this timer, the only rate of the configured time window is reported.- Parameters:
seconds- the number of seconds over which to calculate the average rate- Returns:
- the average rate (per second).
-
getCount
public long getCount()Returns the all-time count of events this timer has seen.- Specified by:
getCountin interfacecom.codahale.metrics.Counting- Specified by:
getCountin interfacecom.codahale.metrics.Metered- Overrides:
getCountin classcom.codahale.metrics.Timer- Returns:
- the all-time count of events
-
getFifteenMinuteRate
public double getFifteenMinuteRate()- Specified by:
getFifteenMinuteRatein interfacecom.codahale.metrics.Metered- Overrides:
getFifteenMinuteRatein classcom.codahale.metrics.Timer
-
getFiveMinuteRate
public double getFiveMinuteRate()- Specified by:
getFiveMinuteRatein interfacecom.codahale.metrics.Metered- Overrides:
getFiveMinuteRatein classcom.codahale.metrics.Timer
-
getMeanRate
public double getMeanRate()- Specified by:
getMeanRatein interfacecom.codahale.metrics.Metered- Overrides:
getMeanRatein classcom.codahale.metrics.Timer
-
getOneMinuteRate
public double getOneMinuteRate()- Specified by:
getOneMinuteRatein interfacecom.codahale.metrics.Metered- Overrides:
getOneMinuteRatein classcom.codahale.metrics.Timer
-
getSnapshot
public com.codahale.metrics.Snapshot getSnapshot()Returns a snapshot of this timer. The computed snapshot is calculated over the complete time interval supported by this timer.- Specified by:
getSnapshotin interfacecom.codahale.metrics.Sampling- Overrides:
getSnapshotin classcom.codahale.metrics.Timer- Returns:
- a snapshot of this timer
-
update
Add an event to this timer.- Overrides:
updatein classcom.codahale.metrics.Timer- Parameters:
duration- the time duration of the eventunit- the unit of time duration
-