public class StopWatch extends Statistic implements java.lang.Comparable<org.mitre.poorMan.javaTiming.HasName>
Timing.createStopWatch(String)
to create.count, enableMinMax, enableStdDev
Modifier and Type | Method and Description |
---|---|
void |
clearCumulative()
Resets cumulative time and count to zero.
|
void |
clearCumulative(boolean silently)
Resets cumulative time and count to zero.
|
int |
compareTo(org.mitre.poorMan.javaTiming.HasName ot) |
long |
elapsed() |
StopWatch |
enableMinMax()
Enable tracking of min and max.
|
StopWatch |
enableStartStopFromAnyThread()
By default a StopWatch can be concurrently accessed
from multiple threads and each start/stop is separately
tracked.
|
StopWatch |
enableStdDev()
Enable computation of standard deviation.
|
boolean |
equals(java.lang.Object o)
Equality is determined by a unique id which is
assigned upon instantiation.
|
java.lang.String |
getCompositeName() |
java.lang.String |
getLocationInCodeString()
The returned string reflects the java class, method, and line number
at which the StopWatch was created.
|
java.lang.String |
getName() |
long |
getStartTime()
This returns the time that was obtained from
System.nanoTime() when the StopWatch was started.
|
protected int |
getUniqueId() |
int |
hashCode() |
boolean |
isStarted()
This must be invoked in the same Thread that did the
start() OR enableStartStopFromAnyThread() must have been invoked. |
StopWatch |
setUnits(java.lang.String units,
double multiplier)
Specify the units and the multiplier to use.
|
StopWatch |
start()
Starts the nanosecond timer.
|
StopWatch |
startAtSameTimeAs(StopWatch otherStopWatch)
Set the start time of this StopWatch to be
the same as the start time of another.
|
void |
stop()
Stops the counter, advances the count by one, and adds to the accumulated time.
|
void |
stop(int countIncrement)
Stops the counter, adds to the accumulated time, and adds the specified
count increment (instead of 1) to the count.
|
boolean |
stopIfStarted()
Stops the counter if it has been started, advances the count by one, and adds to the accumulated time.
|
java.lang.String |
summarize() |
void |
summarize(java.util.Formatter formatter)
Builds a summary of the metric
|
void |
summarize(java.lang.StringBuilder sb)
Appends a summary line for the metric using the specified StringBuilder.
|
StopWatch |
summarizeAverageFirst()
Cause the output from summarize() to first show the average
then the cumulative.
|
StopWatch |
summarizeCumulativeFirst()
Cause the output from summarize() to first show the
cumulative, then the average.
|
StopWatch |
suppressIfCountIsZero()
This indicates that the StopWatch summary line
should not be output to the screen with
Timing.dumpTimings(java.lang.String) is called
if the getCount() value is zero. |
StopWatch |
suppressIfValueIsZero()
This indicates that the StopWatch summary line
should not be output to the screen with
Timing.dumpTimings(java.lang.String) is called
if the getCount() value is zero. |
void |
tallyAndContinue()
Stops the counter and restarts it in such
a way that no time is lost between stop and start.
|
java.lang.String |
toString() |
addCount, addDelta, addDelta, addDelta, addDelta, getAvg, getCoefOfVariation, getCount, getCumulative, getMax, getMin, getStdDev, reset
public final boolean isStarted()
start()
OR enableStartStopFromAnyThread()
must have been invoked.java.lang.IllegalStateException
- if the current calling thread is not the same as the thread that invoked start()
public final long getStartTime()
start()
OR enableStartStopFromAnyThread()
must have been invoked.java.lang.IllegalStateException
- if the current calling thread is not the same as the thread that invoked start()
public final StopWatch setUnits(java.lang.String units, double multiplier)
The default reporting units are milliseconds. The default reporting multiplier (nanosecond to millisecond conversion) is 0.000001.
public final StopWatch start()
start()
OR enableStartStopFromAnyThread()
must have been invoked.public final StopWatch startAtSameTimeAs(StopWatch otherStopWatch)
start()
OR enableStartStopFromAnyThread()
must have been invoked.java.lang.IllegalStateException
- if the current calling thread is not the same as the thread that invoked otherStopWatch.start()
public final boolean stopIfStarted()
start()
OR enableStartStopFromAnyThread()
must have been invoked.public final void stop()
start()
OR enableStartStopFromAnyThread()
must have been invoked.public final void stop(int countIncrement)
public final long elapsed()
java.lang.IllegalStateException
- if the current calling thread is not the same as the thread that invoked start()
public void summarize(java.util.Formatter formatter)
public final StopWatch suppressIfCountIsZero()
Timing.dumpTimings(java.lang.String)
is called
if the getCount()
value is zero.
Once this call is invoked its effect cannot be undone.public final StopWatch suppressIfValueIsZero()
Timing.dumpTimings(java.lang.String)
is called
if the getCount()
value is zero.
Once this call is invoked its effect cannot be undone.public final void tallyAndContinue()
stop()
followed by start()
there is a chance that the nanosecond timer will advance and
you will appear to have time unaccounted for.
This can be helpful in loops, for example, where you wish to measure each iteration of the loop and are carefully accounting for all elapsed time.
public StopWatch enableStdDev()
Statistic
enableStdDev
in class Statistic
public StopWatch enableMinMax()
Statistic
enableMinMax
in class Statistic
public StopWatch summarizeCumulativeFirst()
public StopWatch summarizeAverageFirst()
public StopWatch enableStartStopFromAnyThread()
public final void clearCumulative(boolean silently)
silently
- if false then a message is written to the log file indicating that the StopWatch was cleared.public final void clearCumulative()
clearCumulative(true)
public final int compareTo(org.mitre.poorMan.javaTiming.HasName ot)
compareTo
in interface java.lang.Comparable<org.mitre.poorMan.javaTiming.HasName>
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String getCompositeName()
public java.lang.String getLocationInCodeString()
public java.lang.String getName()
protected int getUniqueId()
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public void summarize(java.lang.StringBuilder sb)
public java.lang.String summarize()