Package edu.wpi.grip.core.metrics
Class Timer
- java.lang.Object
-
- edu.wpi.grip.core.metrics.Timer
-
public class Timer extends java.lang.ObjectTimer for code that gets run.Sample usage:
Timer myTimer = ... myTimer.time(this::doSomething);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTimer.Factory
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetElapsedTime()voidreset()Resets this timer.voidstarted()Starts the timer.voidstop()Stops the timer.voidtime(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 aTimerEventcontaining 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()
-
-