public class Timer extends Object
Modifier and Type | Field and Description |
---|---|
static int |
RECORD_ALL
Flag for indicating that all supported times should be taken.
|
static int |
RECORD_CPUTIME
Flag for indicating that CPU time should be taken.
|
static int |
RECORD_NONE
Flag for indicating that no times should be taken (just count runs).
|
static int |
RECORD_WALLTIME
Flag for indicating that wall clock time should be taken.
|
Constructor and Description |
---|
Timer(String name,
int todoFlags)
Constructor.
|
Timer(String name,
int todoFlags,
long threadId)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
long |
getAvgCpuTime()
Return the average CPU time across all measurements.
|
long |
getAvgWallTime()
Return the average wall clock time across all measurements.
|
String |
getName()
Get the string name of the timer.
|
static Timer |
getNamedTimer(String timerName)
Get a timer of the given string name that takes all possible times
(todos) for the current thread.
|
static Timer |
getNamedTimer(String timerName,
int todoFlags)
Get a timer of the given string name and todos for the current thread.
|
static Timer |
getNamedTimer(String timerName,
int todoFlags,
long threadId)
Get a timer of the given string name for the given thread.
|
static Timer |
getNamedTotalTimer(String timerName)
Collect the total times measured by all known named timers of the given
name.
|
long |
getThreadId()
Get the ID of the thread for which this timer was created.
|
long |
getTotalCpuTime()
Get the total recorded CPU time in nanoseconds.
|
long |
getTotalWallTime()
Get the total recorded wall clock time in nanoseconds.
|
int |
hashCode() |
boolean |
isRunning()
Return true if the timer is running.
|
void |
reset()
Stop the timer (if running) and reset all recorded values.
|
static void |
resetNamedTimer(String timerName)
Reset a timer of the given string name for all todos and the current
thread.
|
static void |
resetNamedTimer(String timerName,
int todoFlags)
Reset a timer of the given string name for the current thread.
|
static void |
resetNamedTimer(String timerName,
int todoFlags,
long threadId)
Reset a timer of the given string name for the given thread.
|
void |
start()
Start the timer.
|
static void |
startNamedTimer(String timerName)
Start a timer of the given string name for all todos and the current
thread.
|
static void |
startNamedTimer(String timerName,
int todoFlags)
Start a timer of the given string name for the current thread.
|
static void |
startNamedTimer(String timerName,
int todoFlags,
long threadId)
Start a timer of the given string name for the current thread.
|
long |
stop()
Stop the timer and record the times that have passed since its start.
|
static long |
stopNamedTimer(String timerName)
Stop a timer of the given string name for all todos and the current
thread.
|
static long |
stopNamedTimer(String timerName,
int todoFlags)
Stop a timer of the given string name for the current thread.
|
static long |
stopNamedTimer(String timerName,
int todoFlags,
long threadId)
Stop a timer of the given string name for the given thread.
|
String |
toString()
The implementation of toString() generates a summary of the times
recorded so far.
|
public static final int RECORD_NONE
public static final int RECORD_CPUTIME
public static final int RECORD_WALLTIME
public static final int RECORD_ALL
public Timer(String name, int todoFlags, long threadId)
name
- a string that identifies the timertodoFlags
- flags to define what the timer will measurethreadId
- the id of the thread for measuring CPU time or 0 if not
measuringpublic Timer(String name, int todoFlags)
Timer(String, int, long)
, but using the
current thread instead of a freely specified thread.name
- a string that identifies the timertodoFlags
- flags to define what the timer will measurepublic String getName()
public long getThreadId()
public boolean isRunning()
public long getTotalCpuTime()
public long getAvgCpuTime()
public long getTotalWallTime()
public long getAvgWallTime()
public void start()
public void reset()
public long stop()
getTotalCpuTime()
etc.
If CPU times are recorded, then the method returns the CPU time that has
passed since the timer was last started; otherwise -1 is returned.public String toString()
public static void startNamedTimer(String timerName)
timerName
- the name of the timerpublic static void startNamedTimer(String timerName, int todoFlags)
timerName
- the name of the timertodoFlags
- public static void startNamedTimer(String timerName, int todoFlags, long threadId)
timerName
- the name of the timertodoFlags
- threadId
- of the thread to track, or 0 if only system clock should be
trackedpublic static long stopNamedTimer(String timerName)
timerName
- the name of the timerpublic static long stopNamedTimer(String timerName, int todoFlags)
timerName
- the name of the timertodoFlags
- public static long stopNamedTimer(String timerName, int todoFlags, long threadId)
timerName
- the name of the timertodoFlags
- threadId
- of the thread to track, or 0 if only system clock should be
trackedpublic static void resetNamedTimer(String timerName)
timerName
- the name of the timerpublic static void resetNamedTimer(String timerName, int todoFlags)
timerName
- the name of the timertodoFlags
- public static void resetNamedTimer(String timerName, int todoFlags, long threadId)
timerName
- the name of the timertodoFlags
- threadId
- of the thread to track, or 0 if only system clock should be
trackedpublic static Timer getNamedTimer(String timerName)
timerName
- the name of the timerpublic static Timer getNamedTimer(String timerName, int todoFlags)
timerName
- the name of the timertodoFlags
- public static Timer getNamedTimer(String timerName, int todoFlags, long threadId)
timerName
- the name of the timertodoFlags
- threadId
- of the thread to track, or 0 if only system clock should be
trackedpublic static Timer getNamedTotalTimer(String timerName)
timerName
- Copyright © 2014–2024 Wikidata Toolkit Developers. Generated from source code published under the Apache License 2.0. For more information, see the Wikidata Toolkit homepage