|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.commsen.stopwatch.Stopwatch
public class Stopwatch
Stopwatch allows you to measure performance of any given piece of code. It's basic usage is as
follows:
since version 0.4 there is also
.....
long swId = Stopwatch.start("group", "label");
// some code to be measured
Stopwatch.stop(swId);
...
Meter
object
To skip already started mensuration (for example if an Exception is thrown) something similar to
following code may be used:
.....
Meter meter = Stopwatch.startMeter("group", "label");
// some code to be measured
meter.stop();
...
or alternatively (since version 0.4) use
.....
long swId = Stopwatch.start("group", "label");
try {
// some code to be measured
} catch (Exception) {
Stopwatch.skip(swId);
} finally {
Stopwatch.stop(swId);
}
...
Meter
object
.....
Meter meter = Stopwatch.startMeter("group", "label");
try {
// some code to be measured
} catch (Exception) {
meter.cancel();
} finally {
meter.stop();
}
...
By default Stopwatch is not active! It means all calls to start(String, String)
,
skip(long)
and stop(long)
methods are simply ignored. To activate Stopwatch do
one of the following:
-Dcom.commsen.stopwatch.activeOnStart=true
JVM parameteractiveOnStart=true
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_ENGINE
|
static java.lang.String |
DEFAULT_ENGINE_PROPERTIES
|
static int |
DEFAULT_MODE
|
static java.lang.String |
DEFAULT_STORAGE
|
static java.lang.String |
DEFAULT_STORAGE_PROPERTIES
|
static java.lang.String |
PROPERTY_ACTIVE
|
static java.lang.String |
PROPERTY_DEBUG
|
static java.lang.String |
PROPERTY_ENGINE
|
static java.lang.String |
PROPERTY_ENGINE_PROPERTIES
|
static java.lang.String |
PROPERTY_JMX_MANAGED
|
static java.lang.String |
PROPERTY_MBEAN_SERVER_NAME
|
static java.lang.String |
PROPERTY_MODE
|
static java.lang.String |
PROPERTY_STORAGE
|
static java.lang.String |
PROPERTY_STORAGE_PROPERTIES
|
static java.lang.String |
SYSTEM_PROPERTIES_PREFIX
|
Constructor Summary | |
---|---|
Stopwatch()
|
Method Summary | |
---|---|
static Report[] |
getAllByGroupReports()
|
static Report[] |
getAllByGroupReports(ReportComparator comparator)
|
static Report[] |
getAllByLabelReports()
|
static Report[] |
getAllByLabelReports(ReportComparator comparator)
|
static Report[] |
getAllReports()
Generates an array of reports which contains exactly 1 element for each combination of group and label If there is no enough data to produce reports, this method returns null |
static Report[] |
getAllReports(ReportComparator comparator)
Generates an array of reports which contains exactly 1 element for each combination of group and label If there is no enough data to produce reports, this method returns null |
static java.lang.String |
getEngineClass()
|
static long[] |
getGroupLoad(java.lang.String group,
int periodField,
int numberOfPeriods)
Returns information of how many instances of any measured code in group group
ware running for the last numberOfPeriods periods. |
static Report[] |
getGroupReports(java.lang.String group)
Generates an array of reports which contains exactly 1 element for each group If there is no enough data to produce the report, this method returns null |
static Report[] |
getGroupReports(java.lang.String group,
ReportComparator comparator)
Generates an array of reports which contains exactly 1 element for each group If there is no enough data to produce the report, this method returns null |
static long[] |
getLabelLoad(java.lang.String label,
int periodField,
int numberOfPeriods)
Returns information of how many instances of any measured code labeled label
ware running for the last numberOfPeriods periods. |
static Report[] |
getLabelReports(java.lang.String label)
Generates an array of reports which contains exactly 1 element for each label If there is no enough data to produce the report, this method returns null |
static Report[] |
getLabelReports(java.lang.String label,
ReportComparator comparator)
Generates an array of reports which contains exactly 1 element for each label If there is no enough data to produce the report, this method returns null |
static long[] |
getLoad(int periodField,
int numberOfPeriods)
Returns information of how many instances of any measured code ware running for the last numberOfPeriods periods. |
static long[] |
getLoad(java.lang.String group,
java.lang.String label,
int periodField,
int numberOfPeriods)
Returns information of how many instances of any measured code in group group
labeled label ware running for the last numberOfPeriods
periods. |
static java.lang.String |
getPersistenceMode()
|
static java.lang.String |
getProperty(java.lang.String key,
java.lang.String defaultValue)
Tries to get the value of property key |
static Report |
getSingleReport(java.lang.String group,
java.lang.String label)
Generates a single report for provided group and label If there is no enough data to produce the report, this method returns null |
static java.lang.String |
getStorageClass()
|
static boolean |
isActive()
Called to check if Stopwatch is active. |
static boolean |
isDebugEnabled()
Called to check if Stopwatch should produce debug information. |
static boolean |
isInitialised()
|
static void |
reset()
|
static void |
setActive(boolean active)
This method changes stopwatch's status Should be used to activate/deactivate Stopwatch at runtime. |
static void |
setDebugEnabled(boolean debugEnabled)
Used to disable/enable Stopwatch's debug information. |
static void |
skip(long id)
Skip measurement identified by id . |
static long |
start(java.lang.String group,
java.lang.String label)
Starts new measurement. |
static Meter |
startMeter(java.lang.String group,
java.lang.String label)
Starts new measurement and provides a Meter which can be later on stopped (Meter.stop() )
or canceled (Meter.cancel() ). |
static void |
stop(long id)
Stop measurement identified by id . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String SYSTEM_PROPERTIES_PREFIX
public static final java.lang.String PROPERTY_ACTIVE
public static final java.lang.String PROPERTY_DEBUG
public static final java.lang.String PROPERTY_ENGINE
public static final java.lang.String PROPERTY_ENGINE_PROPERTIES
public static final java.lang.String PROPERTY_STORAGE
public static final java.lang.String PROPERTY_STORAGE_PROPERTIES
public static final java.lang.String PROPERTY_MODE
public static final java.lang.String PROPERTY_JMX_MANAGED
public static final java.lang.String PROPERTY_MBEAN_SERVER_NAME
public static final java.lang.String DEFAULT_ENGINE
public static final java.lang.String DEFAULT_ENGINE_PROPERTIES
public static final java.lang.String DEFAULT_STORAGE
public static final java.lang.String DEFAULT_STORAGE_PROPERTIES
public static final int DEFAULT_MODE
Constructor Detail |
---|
public Stopwatch()
Method Detail |
---|
public static long start(java.lang.String group, java.lang.String label)
group
- the name of the group this measurement should be placed inlabel
- how this measurement should be labeled
public static Meter startMeter(java.lang.String group, java.lang.String label)
Meter
which can be later on stopped (Meter.stop()
)
or canceled (Meter.cancel()
).
group
- the name of the group this measurement should be placed inlabel
- how this measurement should be labeled
Meter
which can be later on stopped (Meter.stop()
) or canceled (Meter.cancel()
)public static void stop(long id)
id
. This method will do nothing if Stopwatch
is not active or measurement has been skipped already.
id
- which measurement to stoppublic static void skip(long id)
id
. Method should be called if for some reason
current measurement should be skipped. Default stopwatch engine will delete any information
related to this id
but other engines may behave differently (for example to
provide a "skipped measurements" report).
This method will do nothing if Stopwatch is not active or measurement has been stopped
already.
id
- which measurement to stoppublic static Report[] getAllReports()
null
null
.public static Report[] getAllReports(ReportComparator comparator)
null
null
.public static Report[] getAllByGroupReports()
public static Report[] getAllByGroupReports(ReportComparator comparator)
public static Report[] getAllByLabelReports()
public static Report[] getAllByLabelReports(ReportComparator comparator)
public static Report[] getGroupReports(java.lang.String group)
null
group
- the group for which report should be generated
null
.public static Report[] getGroupReports(java.lang.String group, ReportComparator comparator)
null
group
- the group for which report should be generated
null
.public static Report[] getLabelReports(java.lang.String label)
null
label
- the label for which report should be generated
null
.public static Report[] getLabelReports(java.lang.String label, ReportComparator comparator)
null
label
- the label for which report should be generated
null
.public static Report getSingleReport(java.lang.String group, java.lang.String label)
null
group
- the group for which report should be generatedlabel
- the label for which report should be generated
null
.public static long[] getLoad(int periodField, int numberOfPeriods)
numberOfPeriods
periods. Period length is defined by periodField
which can be one of Calendar.FIELD_NAME
For example to see how many peaces of measured code were running per minute for the last 30 minutes, one could use:
long[] load = Stopwatch.getLoad(Calendar.MINUTE
, 30);
In this case load[0]
will contain the number of code instances running 30
minutes ago and load[29]
number of code instances running in the last minute.
periodField
- can be one of Calendar.FIELD_NAME
numberOfPeriods
- number of periods
numberOfPeriods
where every element represents the
load for given pariod.public static long[] getGroupLoad(java.lang.String group, int periodField, int numberOfPeriods)
group
ware running for the last numberOfPeriods
periods. Period length is defined by
periodField
which can be one of Calendar.FIELD_NAME
For example to see how many peaces of measured code in group g1
were running
per day for the last 10 days, one could use:
long[] load = Stopwatch.getLoad(Calendar.DAY_OF_MONTH
, 10);
In this case load[0]
will contain the number of code instances running 10 days
ago and load[9]
number of code instances running today.
group
- the group for which report should be generatedperiodField
- can be one of Calendar.FIELD_NAME
numberOfPeriods
- number of periods
numberOfPeriods
where every element represents the
load for given period.public static long[] getLabelLoad(java.lang.String label, int periodField, int numberOfPeriods)
label
ware running for the last numberOfPeriods
periods. Period length is defined by
periodField
which can be one of Calendar.FIELD_NAME
For example to see how many peaces of measured code labeled l1
were running
per second for the last 15 seconds, one could use:
long[] load = Stopwatch.getLoad(Calendar.SECOND
, 15);
In this case load[0]
will contain the number of code instances running 15
seconds ago and load[14]
number of code instances running in the last second.
label
- the label for which report should be generatedperiodField
- can be one of Calendar.FIELD_NAME
numberOfPeriods
- number of periods
numberOfPeriods
where every element represents the
load for given period.public static long[] getLoad(java.lang.String group, java.lang.String label, int periodField, int numberOfPeriods)
group
labeled label
ware running for the last numberOfPeriods
periods. Period length is defined by periodField
which can be one of
Calendar.FIELD_NAME
For example to see how many peaces of measured code in group g1
labeled
l1
were running per second for the last 3 weeks, one could use:
long[] load = Stopwatch.getLoad(Calendar.WEEK_OF_YEAR
, 3);
In this case load[0]
will contain the number of code instances running 3 weeks
ago and load[2]
number of code instances running in the last week.
group
- the group for which report should be generatedlabel
- the label for which report should be generatedperiodField
- can be one of Calendar.FIELD_NAME
numberOfPeriods
- number of periods
numberOfPeriods
where every element represents the
load for given period.public static void reset()
public static boolean isActive()
false
all
calls to start(String, String)
and stop(long)
are ignored.
public static void setActive(boolean active)
active
- the Stopwatch's status.public static boolean isDebugEnabled()
true
or false
setDebugEnabled(boolean)
public static void setDebugEnabled(boolean debugEnabled)
debugEnabled
- should debug information be generatedpublic static java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
key
- defaultValue
-
defaultValue
if property not
found.public static java.lang.String getEngineClass()
public static java.lang.String getStorageClass()
public static java.lang.String getPersistenceMode()
public static boolean isInitialised()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |