|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.javasimon.Split
public final class Split
Represents single time split - one Stopwatch measurement. Object is obtained by Stopwatch.start()
and the measurement is ended using stop() method on this object. Split will return 0 as the result
if the related Stopwatch was disabled when the Split was obtained. The Split can be stopped in any other thread.
Split measures real time (based on System.nanoTime()), it does not measure CPU time. Split can be garbage collected
and no resource leak occurs if it is not stopped, however Stopwatch's active counter (Stopwatch.getActive())
will be stay incremented.
isRunning()) if it is disabled. Enabled split is running until it is stopped.
Stopped split (not running) will never again be running. Split never changes enabled flag after creation.
Stopwatch| Field Summary | |
|---|---|
static String |
ATTR_EFFECTIVE_STOPWATCH
Attribute name under which effectively used stopwatch is stored if the split was stopped with stop(String). |
private AttributesSupport |
attributesSupport
|
static Split |
DISABLED
Disabled split (implies not running) for cases where monitoring is disabled and null value is not an option. |
private boolean |
enabled
|
private boolean |
running
|
private long |
start
|
private Stopwatch |
stopwatch
|
private long |
total
|
| Constructor Summary | |
|---|---|
private |
Split(boolean enabled)
|
(package private) |
Split(Stopwatch stopwatch)
Creates a new Split for a disabled Stopwatch - called internally only. |
(package private) |
Split(Stopwatch stopwatch,
long start)
Creates a new Split for an enabled Stopwatch with a specific timestamp in nanoseconds - called internally only. |
| Method Summary | ||
|---|---|---|
Object |
getAttribute(String name)
Returns the value of the named attribute as an Object, or null if no attribute of
the given name exists. |
|
|
getAttribute(String name,
Class<T> clazz)
Returns the value of the named attribute typed to the specified class, or null if no attribute of
the given name exists. |
|
Iterator<String> |
getAttributeNames()
Returns an Iterator containing the names of the attributes available to this Split. |
|
Map<String,Object> |
getCopyAsSortedMap()
Returns copy of attributes as a sorted map, this can be used further for operations like toString. |
|
long |
getStart()
Returns start nano timer value - can be converted to ms timestamp using SimonUtils.millisForNano(long). |
|
Stopwatch |
getStopwatch()
Returns the stopwatch that this split is running for. |
|
boolean |
isEnabled()
Returns true if this split was created from enabled Simon or via start(). |
|
boolean |
isRunning()
Returns true if this split is still running ( stop() has not been called yet). |
|
String |
presentRunningFor()
Returns printable form of how long this split was running for. |
|
void |
removeAttribute(String name)
Removes an attribute from this Split. |
|
long |
runningFor()
Returns the current running nano-time from the start to the method call or the total split time if the Split has been stopped already. |
|
void |
setAttribute(String name,
Object value)
Stores an attribute in this Split. |
|
static Split |
start()
Creates a new Split for direct use without Stopwatch ("anonymous split"). |
|
Split |
stop()
Stops the split, updates the stopwatch and returns this. |
|
Split |
stop(String subSimon)
Stops the split, updates the sub-stopwatch specified by parameter and returns this. |
|
String |
toString()
Returns information about this Split, if it's running, name of the related Stopwatch and split's time. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Split DISABLED
null value is not an option.
public static final String ATTR_EFFECTIVE_STOPWATCH
stop(String).
private volatile Stopwatch stopwatch
private final boolean enabled
private volatile boolean running
private volatile long start
private volatile long total
private AttributesSupport attributesSupport
| Constructor Detail |
|---|
private Split(boolean enabled)
Split(Stopwatch stopwatch,
long start)
stopwatch - owning Stopwatch (enabled)start - start timestamp in nanosecondsSplit(Stopwatch stopwatch)
stopwatch - owning Stopwatch (disabled)| Method Detail |
|---|
public static Split start()
Stopwatch ("anonymous split"). Stop will not update any Stopwatch,
value can be added to any chosen Stopwatch using Stopwatch.addSplit(Split) - even in conjunction with
stop() like this:
Split split = Split.start();
...
SimonManager.getStopwatch("codeBlock2.success").addTime(split.stop());
If the split is not needed afterwards calling stop() is not necessary:
Split split = Split.start();
...
SimonManager.getStopwatch("codeBlock2.success").addTime(split);
public Stopwatch getStopwatch()
null for anonymous splits (directly created).
nullpublic Split stop()
runningFor() for the same resultpublic Split stop(String subSimon)
stop() (or this stop with null argument)
results in Callback.onStopwatchStop(Split, StopwatchSample) callback method being invoked,
if sub-simon is affected then Callback.onStopwatchAdd(Stopwatch, Split, StopwatchSample)
is called instead.
If the split was obtained from disabled Stopwatch, this method does not update sub-simon even if it is enabled, because
split itself is disabled as well. If split is enabled, but sub-simon is disabled, the latter is not updated.
subSimon - name of the sub-stopwatch (hierarchy delimiter is added automatically) - if null
it behaves exactly like stop()
public long runningFor()
public String presentRunningFor()
public boolean isEnabled()
start().
public boolean isRunning()
stop() has not been called yet).
Returns false for disabled Split.
public long getStart()
SimonUtils.millisForNano(long).
Returns 0 if the split is not enabled (started for disabled Stopwatch).
public void setAttribute(String name,
Object value)
setAttribute in interface HasAttributesname - a String specifying the name of the attributevalue - the Object to be storedpublic Object getAttribute(String name)
null if no attribute of
the given name exists.
getAttribute in interface HasAttributesname - a String specifying the name of the attribute
null if the attribute does not exist
public <T> T getAttribute(String name,
Class<T> clazz)
null if no attribute of
the given name exists.
getAttribute in interface HasAttributesname - a String specifying the name of the attribute
null if the attribute does not existpublic void removeAttribute(String name)
removeAttribute in interface HasAttributesname - a String specifying the name of the attribute to removepublic Iterator<String> getAttributeNames()
getAttributeNames in interface HasAttributespublic Map<String,Object> getCopyAsSortedMap()
toString.
getCopyAsSortedMap in interface HasAttributespublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||