com.iplanet.jato.util
Class ProfileTimer

java.lang.Object
  |
  +--com.iplanet.jato.util.ProfileTimer

public class ProfileTimer
extends java.lang.Object

Provides an easy-to-use and accurate timing mechanism for a variety of profiling uses. The timer can time individual events, or accumulate several discreet timing intervals and then provide a total or average.

The instance implmentation of this class is synchronized, allowing mutiple threads to share a timer. This behavior is useful for profiling code running in a shared server environment. The static implementation of this class is geared toward use on a single thread, and thus avoids synchronization since the thread's timer instance will not be shared.

Version:
JATO/1.2.2 $Id: ProfileTimer.java,v 1.8 2002/03/16 03:26:38 todd Exp $

Constructor Summary
ProfileTimer()
          Default constructor
 
Method Summary
 double getAverageTime(boolean reset)
          Returns the total time recorded by this timer between starts and stops averaged over the number of starts and stops since the last reset
 long getLastTime()
          Returns the time interval recorded by the timer when it was last stopped, restarted, or updated
static double getThreadAverageTime(boolean reset)
          Gets the average time recorded by the current thread timer
static long getThreadLastTime()
          Gets the last time recorded by the current thread timer
static ProfileTimer getThreadTimer()
          Returns a timer instance that is shared across the current thread
static long getThreadTotalTime()
          Gets the total time recorded by the current thread timer
 long getTotalTime()
          Returns the total time recorded by this timer since the last reset
 void reset()
          Resets all recorded time, intervals, and number of stops and starts
 long restart()
          Stops the timer, recording the elapsed time, and then starts it again, all in one (threadsafe) operation
static void setThreadTimer(ProfileTimer timer)
          Sets a timer instance to be shared across the current thread
 void start()
          Starts the timer
 long stop()
          Stops the timer and adds the elapsed time to the total time recorded since this timer was reset.
static void threadReset()
          Resets the current thread timer
static long threadRestart()
          Restarts the current thread timer
static void threadStart()
          Starts the current thread timer
static long threadStop()
          Stops the current thread timer
static void threadUpdate(long interval)
          Updates the current thread timer
 void update(long interval)
          Updates the total timer time with the specified interval, and increments the recorded number of times the timer has been started and stopped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProfileTimer

public ProfileTimer()
Default constructor
Method Detail

start

public void start()
Starts the timer

stop

public long stop()
Stops the timer and adds the elapsed time to the total time recorded since this timer was reset. This method also increments the recorded number of times the timer has been stopped and started, which allows the timer to later provide a time average.
Returns:
The elapsed time in milliseconds since the timer was last started

restart

public long restart()
Stops the timer, recording the elapsed time, and then starts it again, all in one (threadsafe) operation
Returns:
The elapsed time in milliseconds since the timer was last started

update

public void update(long interval)
Updates the total timer time with the specified interval, and increments the recorded number of times the timer has been started and stopped. This method may be called many times, each time adding the specified interval to the total recorded time.
Parameters:
interval - The time interval to be added to the total time recorded by the timer

getLastTime

public long getLastTime()
Returns the time interval recorded by the timer when it was last stopped, restarted, or updated
Returns:
Last recorded time in milliseconds

getTotalTime

public long getTotalTime()
Returns the total time recorded by this timer since the last reset
Returns:
Total recorded time in milliseconds

getAverageTime

public double getAverageTime(boolean reset)
Returns the total time recorded by this timer between starts and stops averaged over the number of starts and stops since the last reset
Parameters:
reset - If true, resets the timer after calculating the average
Returns:
Average time in milliseconds

reset

public void reset()
Resets all recorded time, intervals, and number of stops and starts

getThreadTimer

public static ProfileTimer getThreadTimer()
Returns a timer instance that is shared across the current thread

setThreadTimer

public static void setThreadTimer(ProfileTimer timer)
Sets a timer instance to be shared across the current thread

threadStart

public static void threadStart()
Starts the current thread timer
See Also:
start()

threadStop

public static long threadStop()
Stops the current thread timer
See Also:
stop()

threadRestart

public static long threadRestart()
Restarts the current thread timer
See Also:
restart()

threadUpdate

public static void threadUpdate(long interval)
Updates the current thread timer
See Also:
#update()

getThreadLastTime

public static long getThreadLastTime()
Gets the last time recorded by the current thread timer
See Also:
getLastTime()

getThreadTotalTime

public static long getThreadTotalTime()
Gets the total time recorded by the current thread timer
See Also:
getTotalTime()

getThreadAverageTime

public static double getThreadAverageTime(boolean reset)
Gets the average time recorded by the current thread timer
See Also:
getAverageTime(boolean)

threadReset

public static void threadReset()
Resets the current thread timer
See Also:
reset()