Package edu.wpi.grip.core.metrics
Class Timer
- java.lang.Object
-
- edu.wpi.grip.core.metrics.Timer
-
public class Timer extends java.lang.Object
Timer for code that gets run.Sample usage:
Timer myTimer = ... myTimer.time(this::doSomething);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Timer.Factory
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getElapsedTime()
void
reset()
Resets this timer.void
started()
Starts the timer.void
stop()
Stops the timer.void
time(java.lang.Runnable target)
Times the given runnable target.
-
-
-
Method Detail
-
started
public void started()
Starts the timer. Callstop()
to stop timing.- Throws:
java.lang.IllegalStateException
- if this a call to this method is preceded by another call tostarted()
-
stop
public void stop()
Stops the timer. This will post aTimerEvent
containing the elapsed time and analysis to the event bus.- Throws:
java.lang.IllegalStateException
- if this a call to this method is not preceded by a call tostarted()
.
-
reset
public void reset()
Resets this timer.
-
time
public void time(java.lang.Runnable target)
Times the given runnable target. This is safe, even if the target throws an exception.Sample usage:
Timer myTimer = ... myTimer.time(this::doSomething);
- Parameters:
target
- the code to time- Throws:
java.lang.IllegalStateException
- if this timer is already timing something
-
getElapsedTime
public long getElapsedTime()
-
-