|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.perf4j.StopWatch
public class StopWatch
The StopWatch class is the main object that is used to log timing statements in perf4j. The general usage pattern is to create a StopWatch before a section of code that is to be timed and then stop it before it is passed to a logging method:
StopWatch stopWatch = new StopWatch(); try { ...code being timed... log.info(stopWatch.stop("methodBeingTimed.success")); } catch (Exception e) { log.error(stopWatch.stop("methodBeingTimed.fail"), e); }Note that a StopWatch is reusable. That is, you can call start() and stop() in succession and the getElapsedTime() method will refer to the time since the most recent start() call.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_LOGGER_NAME
|
Constructor Summary | |
---|---|
StopWatch()
Creates a StopWatch with a blank tag, no message and started at the instant of creation. |
|
StopWatch(long startTime,
long elapsedTime,
java.lang.String tag,
java.lang.String message)
Creates a StopWatch with a specified start and elapsed time, tag, and message. |
|
StopWatch(java.lang.String tag)
Creates a StopWatch with the specified tag, no message and started at the instant of creation. |
|
StopWatch(java.lang.String tag,
java.lang.String message)
Creates a StopWatch with the specified tag and message, started an the instant of creation. |
Method Summary | |
---|---|
StopWatch |
clone()
|
boolean |
equals(java.lang.Object o)
|
long |
getElapsedTime()
Gets the time in milliseconds between when this StopWatch was last started and stopped. |
java.lang.String |
getMessage()
Gets any additional message that was set on this StopWatch instance. |
long |
getStartTime()
Gets the time when this instance was created, or when one of the start() messages was last called. |
java.lang.String |
getTag()
Gets the tag used to group this StopWatch instance with other instances used to time the same code block. |
int |
hashCode()
|
void |
setMessage(java.lang.String message)
Sends a message on this StopWatch instance to be printed when this instance is logged. |
void |
setTag(java.lang.String tag)
Sets the grouping tag for this StopWatch instance. |
void |
start()
Starts this StopWatch, which sets its startTime property to the current time and resets the elapsedTime property. |
void |
start(java.lang.String tag)
Starts this StopWatch and sets its tag to the specified value. |
void |
start(java.lang.String tag,
java.lang.String message)
Starts this StopWatch and sets its tag and message to the specified values. |
java.lang.String |
stop()
Stops this StopWatch, which "freezes" its elapsed time. |
java.lang.String |
stop(java.lang.String tag)
Stops this StopWatch and sets its grouping tag. |
java.lang.String |
stop(java.lang.String tag,
java.lang.String message)
Stops this StopWatch and sets its grouping tag and message. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_LOGGER_NAME
Constructor Detail |
---|
public StopWatch()
public StopWatch(java.lang.String tag)
tag
- The tag name for this timing call. Tags are used to group timing logs, thus each block of code being
timed should have a unique tag. Note that tags can take a hierarchical format using dot notation -
See the GroupedTimingStatistics.setCreateRollupStatistics(boolean)
method for
more information.public StopWatch(java.lang.String tag, java.lang.String message)
tag
- The tag name for this timing call. Tags are used to group timing logs, thus each block of code
being timed should have a unique tag. Note that tags can take a hierarchical format using dot
notation - See the GroupedTimingStatistics.setCreateRollupStatistics(boolean)
method for more information.message
- Additional text to be printed with the logging statement of this StopWatch.public StopWatch(long startTime, long elapsedTime, java.lang.String tag, java.lang.String message)
startTime
- The start time in millisecondselapsedTime
- The elapsed time in millisecondstag
- The tag used to group timing logs of the same code blockmessage
- Additional message textMethod Detail |
---|
public long getStartTime()
public long getElapsedTime()
public java.lang.String getTag()
public void setTag(java.lang.String tag)
tag
- The grouping tag.public java.lang.String getMessage()
public void setMessage(java.lang.String message)
message
- The message associated with this StopWatch, which may be null.public void start()
public void start(java.lang.String tag)
tag
- The grouping tag for this StopWatchpublic void start(java.lang.String tag, java.lang.String message)
tag
- The grouping tag for this StopWatchmessage
- A descriptive message about the code being timed, may be nullpublic java.lang.String stop()
public java.lang.String stop(java.lang.String tag)
tag
- The grouping tag for this StopWatch
public java.lang.String stop(java.lang.String tag, java.lang.String message)
tag
- The grouping tag for this StopWatchmessage
- A descriptive message about the code being timed, may be null
public java.lang.String toString()
toString
in class java.lang.Object
public StopWatch clone()
clone
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |