Package org.elasticsearch.common
Class StopWatch
java.lang.Object
org.elasticsearch.common.StopWatch
Simple stop watch, allowing for timing of a number of tasks,
exposing total running time and running time for each named task.
Conceals use of System.nanoTime()
, improving the
readability of application code and reducing the likelihood of calculation errors.
Note that this object is not designed to be thread-safe and does not use synchronization.
This class is normally used to verify performance during proof-of-concepts and in development, rather than as part of production applications.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Inner class to hold data about one task executed within the stop watch. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Return whether the stop watch is currently running.Return the time taken by the last task.Return a string with a table describing all tasks performed.Return a short description of the total running time.start()
Start an unnamed task.Start a named task.stop()
Stop the current task.taskInfo()
Return an array of the data for tasks performed.toString()
Return an informative string describing all tasks performed For custom reporting, callgetTaskInfo()
and use the task info directly.Return the total time for all tasks.
-
Constructor Details
-
StopWatch
public StopWatch()Construct a new stop watch. Does not start any task. -
StopWatch
Construct a new stop watch with the given id. Does not start any task.- Parameters:
id
- identifier for this stop watch. Handy when we have output from multiple stop watches and need to distinguish between them.
-
-
Method Details
-
start
Start an unnamed task. The results are undefined ifstop()
or timing methods are called without invoking this method.- Throws:
IllegalStateException
- See Also:
-
start
Start a named task. The results are undefined ifstop()
or timing methods are called without invoking this method.- Parameters:
taskName
- the name of the task to start- Throws:
IllegalStateException
- See Also:
-
stop
Stop the current task. The results are undefined if timing methods are called without invoking at least one pairstart()
/#stop()
methods.- Throws:
IllegalStateException
- See Also:
-
timing
-
isRunning
public boolean isRunning()Return whether the stop watch is currently running. -
lastTaskTime
Return the time taken by the last task.- Throws:
IllegalStateException
-
totalTime
Return the total time for all tasks. -
taskInfo
Return an array of the data for tasks performed. -
shortSummary
Return a short description of the total running time. -
prettyPrint
Return a string with a table describing all tasks performed. For custom reporting, call getTaskInfo() and use the task info directly. -
toString
Return an informative string describing all tasks performed For custom reporting, callgetTaskInfo()
and use the task info directly.
-