Package io.micrometer.core.instrument
Interface LongTaskTimer
-
- All Superinterfaces:
Meter
- All Known Implementing Classes:
DefaultLongTaskTimer,NoopLongTaskTimer
public interface LongTaskTimer extends Meter
A long task timer is used to track the total duration of all in-flight long-running tasks and the number of such tasks.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classLongTaskTimer.BuilderFluent builder for long task timers.static classLongTaskTimer.Sample-
Nested classes/interfaces inherited from interface io.micrometer.core.instrument.Meter
Meter.Id, Meter.Type
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description intactiveTasks()static LongTaskTimer.Builderbuilder(Timed timed)Create a timer builder from aTimedannotation.static LongTaskTimer.Builderbuilder(java.lang.String name)doubleduration(long task, java.util.concurrent.TimeUnit unit)The current duration for an active task.doubleduration(java.util.concurrent.TimeUnit unit)default java.lang.Iterable<Measurement>measure()Get a set of measurements.default voidrecord(java.lang.Runnable f)Executes the runnablefand records the time taken.default voidrecord(java.util.function.Consumer<LongTaskTimer.Sample> f)Executes the runnablefand records the time taken.default <T> Trecord(java.util.function.Supplier<T> f)Executes the callablefand records the time taken.default <T> TrecordCallable(java.util.concurrent.Callable<T> f)Executes the callablefand records the time taken.LongTaskTimer.Samplestart()Start keeping time for a task.longstop(long task)Mark a given task as completed.
-
-
-
Method Detail
-
builder
static LongTaskTimer.Builder builder(java.lang.String name)
-
builder
static LongTaskTimer.Builder builder(Timed timed)
Create a timer builder from aTimedannotation.- Parameters:
timed- The annotation instance to base a new timer on.- Returns:
- This builder.
-
recordCallable
default <T> T recordCallable(java.util.concurrent.Callable<T> f) throws java.lang.ExceptionExecutes the callablefand records the time taken.- Type Parameters:
T- The return type of theCallable.- Parameters:
f- Function to execute and measure the execution time.- Returns:
- The return value of
f. - Throws:
java.lang.Exception- Any exception bubbling up from the callable.
-
record
default <T> T record(java.util.function.Supplier<T> f)
Executes the callablefand records the time taken.- Type Parameters:
T- The return type of theSupplier.- Parameters:
f- Function to execute and measure the execution time.- Returns:
- The return value of
f.
-
record
default void record(java.util.function.Consumer<LongTaskTimer.Sample> f)
Executes the runnablefand records the time taken.- Parameters:
f- Function to execute and measure the execution time with a reference to the timer id useful for looking up current duration.
-
record
default void record(java.lang.Runnable f)
Executes the runnablefand records the time taken.- Parameters:
f- Function to execute and measure the execution time.
-
start
LongTaskTimer.Sample start()
Start keeping time for a task.- Returns:
- A task id that can be used to look up how long the task has been running.
-
stop
long stop(long task)
Mark a given task as completed.- Parameters:
task- Id for the task to stop. This should be the value returned fromstart().- Returns:
- Duration for the task in nanoseconds. A -1 value will be returned for an unknown task.
-
duration
double duration(long task, java.util.concurrent.TimeUnit unit)The current duration for an active task.- Parameters:
task- Id for the task to stop. This should be the value returned fromstart().unit- The time unit to scale the duration to.- Returns:
- Duration for the task in nanoseconds. A -1 value will be returned for an unknown task.
-
duration
double duration(java.util.concurrent.TimeUnit unit)
- Parameters:
unit- The time unit to scale the duration to.- Returns:
- The cumulative duration of all current tasks in nanoseconds.
-
activeTasks
int activeTasks()
- Returns:
- The current number of tasks being executed.
-
measure
default java.lang.Iterable<Measurement> measure()
Description copied from interface:MeterGet a set of measurements. Should always return the same number of measurements and in the same order, regardless of the level of activity or the lack thereof.
-
-