Package org.apache.accumulo.core.util
Class OpTimer
- java.lang.Object
-
- org.apache.accumulo.core.util.OpTimer
-
public class OpTimer extends Object
Provides a stop watch for timing a single type of event. This code is based on the org.apache.hadoop.util.StopWatch available in hadoop 2.7.0
-
-
Constructor Summary
Constructors Constructor Description OpTimer()
Create an OpTimer instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isRunning()
Returns timer running statelong
now()
Returns current timer elapsed time as nanoseconds.long
now(TimeUnit timeUnit)
Converts current timer value to specific unit.OpTimer
reset()
Stops timer instance and current elapsed time to 0.double
scale(TimeUnit timeUnit)
Returns the current elapsed time scaled to the provided time unit.OpTimer
start()
Start the timer instance.OpTimer
stop()
Stop the timer instance.String
toString()
Return the current elapsed time in nanoseconds as a string.
-
-
-
Method Detail
-
isRunning
public boolean isRunning()
Returns timer running state- Returns:
- true if timer is running
-
start
public OpTimer start() throws IllegalStateException
Start the timer instance.- Returns:
- this instance for fluent chaining.
- Throws:
IllegalStateException
- if start is called on running instance.
-
stop
public OpTimer stop() throws IllegalStateException
Stop the timer instance.- Returns:
- this instance for fluent chaining.
- Throws:
IllegalStateException
- if stop is called on instance that is not running.
-
reset
public OpTimer reset()
Stops timer instance and current elapsed time to 0.- Returns:
- this instance for fluent chaining
-
now
public long now(TimeUnit timeUnit)
Converts current timer value to specific unit. The conversion to courser granularities truncate with loss of precision.- Parameters:
timeUnit
- the time unit that will converted to.- Returns:
- truncated time in unit of specified time unit.
-
scale
public double scale(TimeUnit timeUnit)
Returns the current elapsed time scaled to the provided time unit. This method does not truncate likenow(TimeUnit)
but returns the value as a double.Note: this method is not included in the hadoop 2.7 org.apache.hadoop.util.StopWatch class. If that class is adopted, then provisions will be required to replace this method.
- Parameters:
timeUnit
- the time unit to scale the elapsed time to.- Returns:
- the elapsed time of this instance scaled to the provided time unit.
-
now
public long now()
Returns current timer elapsed time as nanoseconds.- Returns:
- elapsed time in nanoseconds.
-
-