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.Modifier and Type | Field and Description |
---|---|
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 |
Modifier | Constructor and Description |
---|---|
protected |
AtkTimer() |
Modifier and Type | Method and Description |
---|---|
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. |
protected java.util.Map threadMap
protected java.util.Map methodMap
protected static AtkTimer self
protected int maxMethodName
protected java.lang.String skip
protected boolean timer
public static AtkTimer getInstance()
getInstance
Gives you the AtkTimer instancepublic 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());t
- The Thread
running the calling method.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.t
- The Thread
running the calling method.java.lang.IllegalStateException
- if the popped method name is not
that of the caller.public static java.lang.String padding(int length)
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.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.String
value