public class StatsTimer extends StatsMonitor implements Timer
Timer
that provides statistics.
The statistics are collected periodically and are published according to the configuration
specified by the user using a StatsConfig
object. Please
make sure that the sampleSize corresponds to roughly the number of samples expected in
a reporting interval. While the statistics collected are accurate for this machine they will not
be correct if they are aggregated across groups of machines.
If that is an expected use-case a better
approach is to use buckets that correspond to different times.
For example you might have a counter
that tracks how many calls took < 20ms, one for [ 20ms, 500ms ], and one for > 500ms.
This bucketing approach can be easily aggregated.
See BucketTimer
count, defaultExecutor, totalMeasurement
config
Constructor and Description |
---|
StatsTimer(MonitorConfig baseConfig,
StatsConfig statsConfig)
Creates a new instance of the timer with a unit of milliseconds, using the default executor.
|
StatsTimer(MonitorConfig baseConfig,
StatsConfig statsConfig,
java.util.concurrent.TimeUnit unit)
Creates a new instance of the timer with a given unit, using the default executor.
|
StatsTimer(MonitorConfig config,
StatsConfig statsConfig,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.ScheduledExecutorService executor)
Creates a new instance of the timer with a unit of milliseconds,
using the
ScheduledExecutorService provided by
the user. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
long |
getCount()
Get the number of times this timer has been updated.
|
java.util.concurrent.TimeUnit |
getTimeUnit()
The time unit reported by this timer.
|
long |
getTotalTime()
Get the total time recorded for this timer.
|
int |
hashCode() |
void |
record(long duration,
java.util.concurrent.TimeUnit timeUnit)
Record a new value that was collected with the given TimeUnit.
|
Stopwatch |
start()
Returns a stopwatch that has been started and will automatically
record its result to this timer when stopped.
|
java.lang.String |
toString() |
getCount, getMonitors, getTotalMeasurement, getValue, getValue, handleException, record, startComputingStats
getConfig
public StatsTimer(MonitorConfig baseConfig, StatsConfig statsConfig)
public StatsTimer(MonitorConfig baseConfig, StatsConfig statsConfig, java.util.concurrent.TimeUnit unit)
public StatsTimer(MonitorConfig config, StatsConfig statsConfig, java.util.concurrent.TimeUnit unit, java.util.concurrent.ScheduledExecutorService executor)
ScheduledExecutorService
provided by
the user.public Stopwatch start()
public java.util.concurrent.TimeUnit getTimeUnit()
getTimeUnit
in interface Timer
public void record(long duration, java.util.concurrent.TimeUnit timeUnit)
public java.lang.String toString()
toString
in class StatsMonitor
public boolean equals(java.lang.Object obj)
equals
in class StatsMonitor
public int hashCode()
hashCode
in class StatsMonitor
public long getCount()
public long getTotalTime()