|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mindswap.pellet.utils.Timer
public class Timer
Class used to keep track how much time is spent for a specific operation. Timers are primarily used to display info about performance. A timer is started at the beginning of a function and is stopped at the end of that function (special care needed when there are multiple return commands in a function because the status of unstopped timers is undefined). A timer also stores how many times the timer has been started so average time spent in a function can be computed.
When a timer is used in a recursive function it will typically be started multiple times. Timer class will only measure the time spent in the first call. This is done by counting how many times a timer is started and time spent is computed only when the number of stop() calls evens out the start() calls. It is the programmer's responsibility to make sure each start() is stopped by a stop() call.
Each timer may be associated with a timeout limit. This means that time spent between start() and stop() calls should be less than the timeout specified. Timeouts will only be checked when check() function is called. If check() function is not called setting timeouts has no effect. It is up to the programmer to decide when and how many times a timer will be checked.
There may be a dependancy between timers. For example, classification, realization and entailment operations all use consistency checks. If something goes wrong inside a consistency check and that operation does not finish in a reasonable time, the timeout on the dependant timer may expire. To handle such cases, a timer may be asscoaited with a dependant timer so every time a timer is checked for a timeout, its dependant timer will also be checked. Normally, we would like to associate many dependants with a timer but for efficency reasons (looping over an array each time is expensive) each timer is allowed to have only one dependant.
Timers
class stores a set of timers and provides functions to start, stop and
check timers.
Timers
Field Summary | |
---|---|
static long |
NO_TIMEOUT
|
static long |
NOT_STARTED
|
Constructor Summary | |
---|---|
Timer(java.lang.String name)
Create a timer with no dependant. |
|
Timer(java.lang.String name,
Timer dependant)
Create a timer that has the specified dependant timer. |
Method Summary | |
---|---|
void |
add(Timer timer)
Update the total time elapsed and number of counts by by adding the values from another timer. |
void |
check()
Check if the elapsed time is greater than the timeout limit and throw a TimeoutException if that is the case. |
double |
getAverage()
Retutn the total time spent (in milliseconds) divided by the number of times this timer has been ran. |
long |
getCount()
Return the total number of times this timer has been started and stopped. |
long |
getElapsed()
Return the time elapsed (in miliseconds) since the last time this timer was started. |
long |
getLast()
Return the total time spent between last start()-stop() period. |
java.lang.String |
getName()
Return the name of this timer. |
long |
getTimeout()
Return the timeout associated with this timer. |
long |
getTotal()
Return the total time (in miliseconds) spent while this timer was running. |
boolean |
isStarted()
Return true if timer has been started with a start() call but not has been
stopped with a stop() call. |
void |
reset()
Reset all the counters associated with this timer. |
void |
setTimeout(long timeout)
Set a timeout limit for this timer. |
void |
start()
Start time timer by recording the time this function is called. |
void |
stop()
Stop the timer, increment the count and update the total time spent. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final long NOT_STARTED
public static final long NO_TIMEOUT
Constructor Detail |
---|
public Timer(java.lang.String name)
name
- public Timer(java.lang.String name, Timer dependant)
name
- dependant
- Method Detail |
---|
public void add(Timer timer)
timer
- public void start()
public void stop()
public void reset()
public void check() throws TimeoutException
TimeoutException
public boolean isStarted()
start()
call but not has been
stopped with a stop()
call.
public java.lang.String getName()
public long getElapsed()
public long getTotal()
public long getCount()
start()
function is called may be greater than this amount.
public long getTimeout()
public double getAverage()
public long getLast()
public void setTimeout(long timeout)
timeout
- public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |