de.is24.util.monitoring
Class PerfTimer
java.lang.Object
de.is24.util.monitoring.PerfTimer
- Direct Known Subclasses:
- PerfTimer.DefaultPerfTimer, PerfTimer.NoPerfTimer
public abstract class PerfTimer
- extends Object
Helper class to perform timer measurements. Once a timer it is created it measures the current system time.
Calling measure() will measure the time again, calculate the difference in milli seconds and return it.
Usage:
final PerfTimer actionTimer = PerfTimer.createDebugTimer(getClass());
doAction();
System.out.println("Executing action took " + actionTimer.measure() + " ms");
PerfTimer provides an InApplicationMonitor (createMonitor()) connection as well as debug-only measurement facilities.
- Author:
- Stefan Schubert, IT-E, IS24
|
Nested Class Summary |
private static class |
PerfTimer.DefaultPerfTimer
A timer implementing the default measurement behaviour based on system time. |
private static class |
PerfTimer.NoPerfTimer
A timer that always returns 0 on measurements for performance reasons (null object). |
static class |
PerfTimer.PerfMonitor
A timer providing an interface for submitting measurements to InApplicationMonitor. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PerfTimer
public PerfTimer()
createTimer
public static PerfTimer createTimer()
- Returns:
- a timer measuring at any time.
createMonitor
public static PerfTimer.PerfMonitor createMonitor()
- Returns:
- a
PerfTimer.PerfMonitor. Use PerfMonitor.monitor(String)
to perform a measurement and submit it to the InApplicationMonitor.
createDebugTimer
public static PerfTimer createDebugTimer(Class<?> type)
- Parameters:
type - the logger category used for debugging. A null argument performs equally to createTimer().
- Returns:
- a timer that only performs valid measurements on debug level and below.
createInfoTimer
public static PerfTimer createInfoTimer(Class<?> type)
- Parameters:
type - the logger category used for info-level debugging. A null argument performs equally to createTimer().
- Returns:
- a timer that only performs valid measurements on info level and below.
create
public static PerfTimer create(Class<?> type,
org.apache.log4j.Level level)
- Parameters:
type - the logger category used for custom level debugging. A null argument performs equally to createTimer().level - the level at which to log
- Returns:
- a timer that only performs valid measurements on the specified level and below.
isActive
private static boolean isActive(Class<?> type,
org.apache.log4j.Level level)
- Parameters:
type - the logger category used for custom level debugging. A null argument performs equally to createTimer().level - the level at which to log
- Returns:
- determines whether to measure or not to measure.
create
private static PerfTimer create(boolean active)
- Parameters:
active - determining whether to measure or not to measure.
- Returns:
- a timer that only performs valid measurements if the argument is true.
measure
public abstract long measure()
- Returns:
- the time in milli seconds from the creation of this timer until the call of this method.
Copyright © 2013 Immobilien Scout GmbH. All Rights Reserved.