public interface Stopwatch extends Simon
start()
creates new Split
object.
On this object you can call Split.stop()
- this demarcates measured interval.
Alternatively method addSplit(Split)
can be used to add split to the stopwatch (Split.create(long)
can be used to create finished Split for any nanos value). Both ways effectively
updates usage times, increase usage counter by one and updates total time of the stopwatch.
Split object enables multiple time-splits to be measured in parallel.
Example:
Split split = SimonManager.getStopwatch("com.my.stopwatch").start(); //... here goes the measured code split.stop(); System.out.println("Result: " + split.getStopwatch()); // print will be probably somewhere elseThis can be used for simple micro-benchmarking, critical section monitoring, in web filter to measure request times, etc.
SimonManager
should always be used to get the stopwatch before using it,
because otherwise the code will not reflect enable/disable of the whole API.Modifier and Type | Method and Description |
---|---|
Stopwatch |
addSplit(Split split)
Adds
Split to the stopwatch which is useful for aggregation of splits created for other stopwatch. |
long |
getActive()
Returns current number of measured splits (concurrently running).
|
long |
getCounter()
Returns usage count of the stopwatch.
|
long |
getLast()
Returns value of the last added split - whether it was added directly or with stop method.
|
long |
getMax()
Returns maximal time split value in nanoseconds.
|
long |
getMaxActive()
Returns peek value of active concurrent splits.
|
long |
getMaxActiveTimestamp()
Returns ms timestamp when the last peek of the active split count occurred.
|
long |
getMaxTimestamp()
Returns ms timestamp when the max value was measured.
|
double |
getMean()
Returns mean value (average) of all measured values.
|
long |
getMin()
Returns minimal time split value in nanoseconds.
|
long |
getMinTimestamp()
Returns ms timestamp when the min value was measured.
|
double |
getStandardDeviation()
Returns unbiased estimate of standard deviation.
|
long |
getTotal()
Returns total sum of all split times in nanoseconds.
|
double |
getVariance()
Returns unbiased estimate of the population variance.
|
double |
getVarianceN()
Returns variance value of all measured values (entire population).
|
StopwatchSample |
sample()
Samples Simon values and returns them in a Java Bean derived from Sample interface.
|
StopwatchSample |
sampleIncrement(Object key)
Samples increment in Simon values since the previous call of this method with the
same key.
|
StopwatchSample |
sampleIncrementNoReset(Object key)
Samples current value of incremental Simon.
|
Split |
start()
Starts the new split for this stopwatch.
|
getChildren, getFirstUsage, getLastUsage, getManager, getName, getNote, getParent, getState, isEnabled, setNote, setState, stopIncrementalSampling
getAttribute, getAttribute, getAttributeNames, getCopyAsSortedMap, removeAttribute, setAttribute
Split start()
Split
object is collected, no leak occurs. However, active count is increased
and without stopping the split active count stays increased which may render that
information useless.Split.stop()
Stopwatch addSplit(Split split)
Split
to the stopwatch which is useful for aggregation of splits created for other stopwatch.
Split object should be stopped. Main difference is the callback method called as
Callback.onStopwatchAdd(Stopwatch, Split, StopwatchSample)
provides split object to the callback.
Usage examples:
Split split = Split.start(); // no stopwatch needed ... someStopwatch.addSplit(split.stop()); // you may omit stop(), if you does not use the split after this point
split
- split object (should be stopped)long getTotal()
long getLast()
long getCounter()
addTime
and
stop
- that means that it's updated every time the next time split is added.long getMax()
long getMin()
long getMaxTimestamp()
long getMinTimestamp()
long getActive()
long getMaxActive()
long getMaxActiveTimestamp()
double getMean()
getCounter()
is 0 it should return Double.NaN
, but for practical reasons returns 0.double getStandardDeviation()
getCounter()
is 0 returns Double.NaN
.
http://en.wikipedia.org/wiki/Unbiased_estimation_of_standard_deviationdouble getVariance()
getCounter()
is 0 returns Double.NaN
.
http://en.wikipedia.org/wiki/Variance#Population_variance_and_sample_variancedouble getVarianceN()
getCounter()
is 0 returns Double.NaN
.
http://en.wikipedia.org/wiki/Variance#Population_variance_and_sample_varianceStopwatchSample sample()
Simon
StopwatchSample sampleIncrement(Object key)
Simon
Simon.sample()
. Any subsequent calls with the key
provide increments.
Clients can use any sampling key (any Object) which enables safe access to their own increments.
Using String does not guarantee this as any client can potentially guess the key. This
may or may not be an issue.sampleIncrement
in interface Simon
key
- sampling key used to access incremental sampleSample
with value incrementsStopwatchSample sampleIncrementNoReset(Object key)
Simon
Simon.sampleIncrement(Object)
but
does not reset the incremental Simon. This method does not start incremental sampling
and keeps returning values from Simon.sample()
for any key that was not used with
Simon.sampleIncrement(Object)
before.sampleIncrementNoReset
in interface Simon
key
- sampling key used to access incremental sampleSample
with value incrementsSimon.sampleIncrement(Object)
Copyright © 2019. All rights reserved.