Package com.codahale.metrics
Class Timer
- java.lang.Object
-
- com.codahale.metrics.Timer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Timer.Context
A timing context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getCount()
Returns the number of events which have been marked.double
getFifteenMinuteRate()
Returns the fifteen-minute moving average rate at which events have occurred since the meter was created.double
getFiveMinuteRate()
Returns the five-minute moving average rate at which events have occurred since the meter was created.double
getMeanRate()
Returns the mean rate at which events have occurred since the meter was created.double
getOneMinuteRate()
Returns the one-minute moving average rate at which events have occurred since the meter was created.Snapshot
getSnapshot()
Returns a snapshot of the values.Timer.Context
time()
Returns a newTimer.Context
.void
time(Runnable event)
Times and records the duration of event.<T> T
time(Callable<T> event)
Times and records the duration of event.<T> T
timeSupplier(Supplier<T> event)
Times and records the duration of event.void
update(long duration, TimeUnit unit)
Adds a recorded duration.void
update(Duration duration)
Adds a recorded duration.
-
-
-
Method Detail
-
update
public void update(long duration, TimeUnit unit)
Adds a recorded duration.- Parameters:
duration
- the length of the durationunit
- the scale unit ofduration
-
update
public void update(Duration duration)
Adds a recorded duration.- Parameters:
duration
- theDuration
to add to the timer. Negative or zero value are ignored.
-
time
public <T> T time(Callable<T> event) throws Exception
Times and records the duration of event.- Type Parameters:
T
- the type of the value returned byevent
- Parameters:
event
- aCallable
whoseCallable.call()
method implements a process whose duration should be timed- Returns:
- the value returned by
event
- Throws:
Exception
- ifevent
throws anException
-
timeSupplier
public <T> T timeSupplier(Supplier<T> event)
Times and records the duration of event. Should not throw exceptions, for that use thetime(Callable)
method.- Type Parameters:
T
- the type of the value returned byevent
- Parameters:
event
- aSupplier
whoseSupplier.get()
method implements a process whose duration should be timed- Returns:
- the value returned by
event
-
time
public void time(Runnable event)
Times and records the duration of event.- Parameters:
event
- aRunnable
whoseRunnable.run()
method implements a process whose duration should be timed
-
time
public Timer.Context time()
Returns a newTimer.Context
.- Returns:
- a new
Timer.Context
- See Also:
Timer.Context
-
getCount
public long getCount()
Description copied from interface:Metered
Returns the number of events which have been marked.
-
getFifteenMinuteRate
public double getFifteenMinuteRate()
Description copied from interface:Metered
Returns the fifteen-minute moving average rate at which events have occurred since the meter was created.- Specified by:
getFifteenMinuteRate
in interfaceMetered
- Returns:
- the fifteen-minute moving average rate at which events have occurred since the meter was created
-
getFiveMinuteRate
public double getFiveMinuteRate()
Description copied from interface:Metered
Returns the five-minute moving average rate at which events have occurred since the meter was created.- Specified by:
getFiveMinuteRate
in interfaceMetered
- Returns:
- the five-minute moving average rate at which events have occurred since the meter was created
-
getMeanRate
public double getMeanRate()
Description copied from interface:Metered
Returns the mean rate at which events have occurred since the meter was created.- Specified by:
getMeanRate
in interfaceMetered
- Returns:
- the mean rate at which events have occurred since the meter was created
-
getOneMinuteRate
public double getOneMinuteRate()
Description copied from interface:Metered
Returns the one-minute moving average rate at which events have occurred since the meter was created.- Specified by:
getOneMinuteRate
in interfaceMetered
- Returns:
- the one-minute moving average rate at which events have occurred since the meter was created
-
getSnapshot
public Snapshot getSnapshot()
Description copied from interface:Sampling
Returns a snapshot of the values.- Specified by:
getSnapshot
in interfaceSampling
- Returns:
- a snapshot of the values
-
-