Package org.grails.core.util
Class StopWatch
- java.lang.Object
-
- org.grails.core.util.StopWatch
-
public class StopWatch extends java.lang.ObjectBased on the Spring StopWatch class, but supporting nested tasks- Since:
- May 2, 2001
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStopWatch.TaskInfoInner class to hold data about one task executed within the stop watch.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcomplete()StopWatch.TaskInfogetLastTaskInfo()Return the last task as a TaskInfo object.java.lang.StringgetLastTaskName()Return the name of the last task.longgetLastTaskTimeMillis()Return the time taken by the last task.intgetTaskCount()Return the number of tasks timed.StopWatch.TaskInfo[]getTaskInfo()Return an array of the data for tasks performed.longgetTotalTimeMillis()Return the total time in milliseconds for all tasks.doublegetTotalTimeSeconds()Return the total time in seconds for all tasks.booleanisRunning()Return whether the stop watch is currently running.java.lang.StringprettyPrint()Return a string with a table describing all tasks performed.java.lang.StringshortSummary()Return a short description of the total running time.voidstart()Start an unnamed task.voidstart(java.lang.String taskName)Start a named task.voidstop()Stop the current task.java.lang.StringtoString()Return an informative string describing all tasks performed For custom reporting, callgetTaskInfo()and use the task info directly.
-
-
-
Constructor Detail
-
StopWatch
public StopWatch()
Construct a new stop watch. Does not start any task.
-
StopWatch
public StopWatch(java.lang.String id)
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 Detail
-
start
public void start() throws java.lang.IllegalStateExceptionStart an unnamed task. The results are undefined ifstop()or timing methods are called without invoking this method.- Throws:
java.lang.IllegalStateException- See Also:
stop()
-
start
public void start(java.lang.String taskName) throws java.lang.IllegalStateExceptionStart 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:
java.lang.IllegalStateException- See Also:
stop()
-
stop
public void stop() throws java.lang.IllegalStateExceptionStop the current task. The results are undefined if timing methods are called without invoking at least one pairstart()/stop()methods.- Throws:
java.lang.IllegalStateException- See Also:
start()
-
complete
public void complete()
-
isRunning
public boolean isRunning()
Return whether the stop watch is currently running.
-
getLastTaskTimeMillis
public long getLastTaskTimeMillis() throws java.lang.IllegalStateExceptionReturn the time taken by the last task.- Throws:
java.lang.IllegalStateException
-
getLastTaskName
public java.lang.String getLastTaskName() throws java.lang.IllegalStateExceptionReturn the name of the last task.- Throws:
java.lang.IllegalStateException
-
getLastTaskInfo
public StopWatch.TaskInfo getLastTaskInfo() throws java.lang.IllegalStateException
Return the last task as a TaskInfo object.- Throws:
java.lang.IllegalStateException
-
getTotalTimeMillis
public long getTotalTimeMillis()
Return the total time in milliseconds for all tasks.
-
getTotalTimeSeconds
public double getTotalTimeSeconds()
Return the total time in seconds for all tasks.
-
getTaskCount
public int getTaskCount()
Return the number of tasks timed.
-
getTaskInfo
public StopWatch.TaskInfo[] getTaskInfo()
Return an array of the data for tasks performed.
-
shortSummary
public java.lang.String shortSummary()
Return a short description of the total running time.
-
prettyPrint
public java.lang.String prettyPrint()
Return a string with a table describing all tasks performed. For custom reporting, call getTaskInfo() and use the task info directly.
-
toString
public java.lang.String toString()
Return an informative string describing all tasks performed For custom reporting, callgetTaskInfo()and use the task info directly.- Overrides:
toStringin classjava.lang.Object
-
-