@NotThreadSafe public class PerformanceLogger extends Object
This class is meant to be used like this:
//... PerformanceLogger plog = new PerformanceLogger(); doWork(); plog.logElapsedAndRestart(); doSomeMoreWork(); plog.logElapsed(); //...or
//...
PerformanceLogger.timedExec(() -> {
doSomeWork();
return doSomeMoreWork();
}
//...
For logging SLF4J with log level DEBUG is used; you can therefore disable
performance logging by simply setting the log level for this class accordingly.| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_PERFORMANCE_LOG_FORMATTER_KEY
The property key that specifies the default
PerformanceLogFormatter implementation to use. |
static String |
DEFAULT_SETTINGS_PATH
Path to an XML properties file that can be used to override the default settings of this class.
|
static String |
DEFAULT_THRESHOLD_KEY
The property key that specifies the default threshold to use.
|
| Constructor and Description |
|---|
PerformanceLogger()
Constructs a new
PerformanceLogger with default settings. |
PerformanceLogger(long threshold)
Constructs a new
PerformanceLogger a default PerformanceLogFormatter implementation. |
PerformanceLogger(long threshold,
PerformanceLogFormatter logFormatter)
Constructs a new
PerformanceLogger. |
PerformanceLogger(PerformanceLogFormatter logFormatter)
Constructs a new
PerformanceLogger with a default threshold. |
| Modifier and Type | Method and Description |
|---|---|
void |
logElapsed()
See
logElapsed(String). |
void |
logElapsed(String msg)
Logs the elapsed time if it is above the threshold.
|
void |
logElapsedAndRestart()
|
void |
logElapsedAndRestart(String msg)
Logs the elapsed time if it is above the threshold and restarts the internal timer.
|
void |
restart()
Restarts the internal timer.
|
static void |
timedExec(long threshold,
Runnable block)
|
static void |
timedExec(long threshold,
String msg,
Runnable block)
|
static <T> T |
timedExec(long threshold,
String msg,
java.util.function.Supplier<T> block)
Executes the given block and logs its execution time.
|
static <T> T |
timedExec(long threshold,
java.util.function.Supplier<T> block)
|
static void |
timedExec(Runnable block)
|
static void |
timedExec(String msg,
Runnable block)
|
static <T> T |
timedExec(String msg,
java.util.function.Supplier<T> block)
|
static <T> T |
timedExec(java.util.function.Supplier<T> block)
|
public static final String DEFAULT_SETTINGS_PATH
This file loaded using LocalResources. Consult the users manual for details.
public static final String DEFAULT_PERFORMANCE_LOG_FORMATTER_KEY
PerformanceLogFormatter implementation to use.DEFAULT_SETTINGS_PATH,
Constant Field Valuespublic static final String DEFAULT_THRESHOLD_KEY
DEFAULT_SETTINGS_PATH,
Constant Field Valuespublic PerformanceLogger()
PerformanceLogger with default settings.public PerformanceLogger(long threshold)
PerformanceLogger a default PerformanceLogFormatter implementation.threshold - the threshold in ms for which the logger should generate any output.public PerformanceLogger(PerformanceLogFormatter logFormatter)
PerformanceLogger with a default threshold.logFormatter - optional PerformanceLogFormatterpublic PerformanceLogger(long threshold,
PerformanceLogFormatter logFormatter)
PerformanceLogger.threshold - the threshold in ms for which the logger should generate any output.logFormatter - optional PerformanceLogFormatter.public void logElapsed()
logElapsed(String).public void logElapsedAndRestart()
public void logElapsed(String msg)
msg - an optional message.public void logElapsedAndRestart(String msg)
msg - an optional message.public void restart()
public static <T> T timedExec(long threshold,
String msg,
java.util.function.Supplier<T> block)
threshold - the threshold in ms for with the logger should generate any output.msg - an optional message.block - the block to execute.public static <T> T timedExec(String msg, java.util.function.Supplier<T> block)
public static <T> T timedExec(long threshold,
java.util.function.Supplier<T> block)
public static <T> T timedExec(java.util.function.Supplier<T> block)
public static void timedExec(long threshold,
Runnable block)
public static void timedExec(Runnable block)
Copyright © 2012-2017. All Rights Reserved.