org.activemath.webapp.util
Class StopWatch

java.lang.Object
  extended by org.activemath.webapp.util.StopWatch

public class StopWatch
extends Object

Simple stop watch, allowing for timing of a number of tasks, exposing total running time and running time for each named task.
Note that this object is not designed to be threadsafe, and does not use synchronization or threading. Therefore it is safe to invoke it from EJBs.
This class is normally used to verify performance during proof-of-concepts and in development, rather than as part of production applications. Usage: StopWatch sw = new StopWatch("Transformer"); sw.start("Building JDOM document"); ... sw.stop(); sw.start("Loading stylesheet"); ... sw.stop(); System.out.println(sw.prettyPrint());

Since:
May 2, 2001

Nested Class Summary
 class StopWatch.TaskInfo
          Inner class to hold data about one task
 
Constructor Summary
StopWatch()
          Construct a new stop watch.
StopWatch(String id)
          Construct a new stop watch with the given id Does not start any task.
 
Method Summary
 long getLastInterval()
          Return the time taken by the last operation
 int getTaskCount()
          Return the number of tasks timed
 StopWatch.TaskInfo[] getTaskInfo()
          Return an array of the data for tasks performed
 long getTotalTime()
          Return the total time in milliseconds for all tasks
 double getTotalTimeSecs()
          Return the total time in seconds for all tasks
 String prettyPrint()
          Return an informative string describing all tasks performed
 void start(String task)
          Start a named task.
 void stop()
          Stop the current task.
 String toString()
          Return an informative string describing all tasks performed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StopWatch

public StopWatch()
Construct a new stop watch. Does not start any task.


StopWatch

public StopWatch(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(String task)
Start a named task. The results are undefined if stop() or timing methods are called without invoking this method.

Parameters:
task - name of the task to start

stop

public void stop()
Stop the current task. The results are undefined if timing methods are called without invoking at least one pair start()/stop() methods.


getTotalTime

public long getTotalTime()
Return the total time in milliseconds for all tasks

Returns:
the total time in milliseconds for all tasks

getLastInterval

public long getLastInterval()
Return the time taken by the last operation

Returns:
the time taken by the last operation

getTotalTimeSecs

public double getTotalTimeSecs()
Return the total time in seconds for all tasks

Returns:
the total time in seconds for all tasks

getTaskCount

public int getTaskCount()
Return the number of tasks timed

Returns:
the number of tasks timed

getTaskInfo

public StopWatch.TaskInfo[] getTaskInfo()
Return an array of the data for tasks performed

Returns:
an array of the data for tasks performed

toString

public String toString()
Return an informative string describing all tasks performed

Overrides:
toString in class Object
Returns:
an informative string describing all tasks performed. For custom reporting, call getTaskInfo() and use the task info directly

prettyPrint

public String prettyPrint()
Return an informative string describing all tasks performed

Returns:
an informative string describing all tasks performed. For custom reporting, call getTaskInfo() and use the task info directly