|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.perf4j.StopWatch
org.perf4j.LoggingStopWatch
public class LoggingStopWatch
A LoggingStopWatch prevents the need to explicitly send the StopWatch string to a Logger when stopping. Instead, all of the stop() and lap() methods themselves are responsible for persisting the StopWatch:
LoggingStopWatch stopWatch = new LoggingStopWatch(); ...some code stopWatch.stop("codeBlock1"); //calling stop writes the StopWatch string to std err.This class just writes all StopWatch messages to the standard error stream, but subclasses will use Loggers from various logging frameworks to persist the StopWatch.
Field Summary |
---|
Fields inherited from class org.perf4j.StopWatch |
---|
DEFAULT_LOGGER_NAME |
Constructor Summary | |
---|---|
LoggingStopWatch()
Creates a LoggingStopWatch with a blank tag, no message and started at the instant of creation. |
|
LoggingStopWatch(long startTime,
long elapsedTime,
String tag,
String message)
Creates a LoggingStopWatch with a specified start and elapsed time, tag, and message. |
|
LoggingStopWatch(String tag)
Creates a LoggingStopWatch with the specified tag, no message and started at the instant of creation. |
|
LoggingStopWatch(String tag,
String message)
Creates a LoggingStopWatch with the specified tag and message, started an the instant of creation. |
Method Summary | |
---|---|
LoggingStopWatch |
clone()
|
boolean |
isLogging()
Determines whether or not logging is currently enabled for normal log messages for this StopWatch. |
String |
lap(String tag,
String message,
Throwable exception)
Identical to StopWatch.lap(String, String) , but also allows you to specify an exception to be logged. |
String |
lap(String tag,
Throwable exception)
Identical to StopWatch.lap(String) , but also allows you to specify an exception to be logged. |
protected void |
log(String stopWatchAsString,
Throwable exception)
This log method can be overridden by subclasses in order to persist the StopWatch, for example by using a log4j Logger. |
String |
stop()
This stop method is overridden to perform the logging itself instead of needing to make a separate call to persist the timing information. |
String |
stop(String tag,
String message,
Throwable exception)
Identical to StopWatch.stop(String, String) , but also allows you to specify an exception to be logged. |
String |
stop(String tag,
Throwable exception)
Identical to StopWatch.stop(String) , but also allows you to specify an exception to be logged. |
String |
stop(Throwable exception)
In cases where a code block terminated by throwing an exception, you may wish to have the exception logged in addition to the time it took to execute the block, in which case this method will write out the exception's stack trace in addition to the StopWatch timing method. |
Methods inherited from class org.perf4j.StopWatch |
---|
equals, getElapsedTime, getMessage, getStartTime, getTag, hashCode, lap, lap, setMessage, setTag, start, start, start, stop, stop, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LoggingStopWatch()
public LoggingStopWatch(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.public LoggingStopWatch(String tag, 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.message
- Additional text to be printed with the logging statement of this LoggingStopWatch.public LoggingStopWatch(long startTime, long elapsedTime, String tag, 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 String stop()
stop
in class StopWatch
public String stop(Throwable exception)
exception
- The exception that was thrown by the timed code block
public String stop(String tag, Throwable exception)
StopWatch.stop(String)
, but also allows you to specify an exception to be logged.
tag
- The grouping tag for this StopWatchexception
- The exception that was thrown by the timed code block
public String stop(String tag, String message, Throwable exception)
StopWatch.stop(String, String)
, but also allows you to specify an exception to be logged.
tag
- The grouping tag for this StopWatchmessage
- A descriptive message about the timed blockexception
- The exception that was thrown by the timed code block
public String lap(String tag, Throwable exception)
StopWatch.lap(String)
, but also allows you to specify an exception to be logged.
tag
- The grouping tag for the PREVIOUS code block that was timed.exception
- The exception that was thrown by the timed code block.
public String lap(String tag, String message, Throwable exception)
StopWatch.lap(String, String)
, but also allows you to specify an exception to be logged.
tag
- The grouping tag for the PREVIOUS code block that was timed.message
- A descriptive message about the timed blockexception
- The exception that was thrown by the timed code block
public boolean isLogging()
protected void log(String stopWatchAsString, Throwable exception)
stopWatchAsString
- The serialized StopWatch stringexception
- An exception, if any, that was also passed to the stop() or lap() methods - may be null.public LoggingStopWatch clone()
clone
in class StopWatch
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |