fr.esrf.tangoatk.util
Class AtkTimer

java.lang.Object
  extended by fr.esrf.tangoatk.util.AtkTimer

public class AtkTimer
extends java.lang.Object

AtkTimer is a singleton class which takes care of timing methods. The two main entry points are startTimer(java.lang.Thread) endTimer(java.lang.Thread). The results are printed when printResults() is called.


Field Summary
protected  int maxMethodName
           
protected  java.util.Map methodMap
           
protected static AtkTimer self
           
protected  java.lang.String skip
           
protected  java.util.Map threadMap
           
protected  boolean timer
           
 
Constructor Summary
protected AtkTimer()
           
 
Method Summary
 void endTimer(java.lang.Thread t)
          endTimer ends the timer for the caller of this method.
protected  java.lang.String getCaller()
          getCaller Figures out the calling method.
static AtkTimer getInstance()
          getInstance Gives you the AtkTimer instance
static java.lang.String padding(int length)
           
 void printResults()
          printResults prints the results of the timing.
 void startTimer(java.lang.Thread t)
          startTimer starts the timer for the caller of this method You can time the same method in different treads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadMap

protected java.util.Map threadMap

methodMap

protected java.util.Map methodMap

self

protected static AtkTimer self

maxMethodName

protected int maxMethodName

skip

protected java.lang.String skip

timer

protected boolean timer
Constructor Detail

AtkTimer

protected AtkTimer()
Method Detail

getInstance

public static AtkTimer getInstance()
getInstance Gives you the AtkTimer instance


startTimer

public void startTimer(java.lang.Thread t)
startTimer starts the timer for the caller of this method You can time the same method in different treads. The timers are stored on a stack, so it is able to time recursions correctly. Normally startTimer is called like this AtkTimer.getInstance().startTimer(Thread.currentThread());

Parameters:
t - The Thread running the calling method.

endTimer

public void endTimer(java.lang.Thread t)
endTimer ends the timer for the caller of this method. It pops the current method of its stack, calculates the difference between the methods starttime and the current time, and adds this time to a list containing the other times for this method.

Parameters:
t - The Thread running the calling method.
Throws:
java.lang.IllegalStateException - if the popped method name is not that of the caller.

padding

public static java.lang.String padding(int length)

printResults

public void printResults()
printResults prints the results of the timing. Gives you Average, min, and max time as well as number of calls recorded for each method.


getCaller

protected java.lang.String getCaller()
getCaller Figures out the calling method. It does this by creating a new Throwable to get a hold of a stack trace and treats this in its own way to get a hold of the calling methods name.

Returns:
a String value