Package weka.core
Class Debug.Clock
- java.lang.Object
-
- weka.core.Debug.Clock
-
- All Implemented Interfaces:
java.io.Serializable,RevisionHandler
- Enclosing class:
- Debug
public static class Debug.Clock extends java.lang.Object implements java.io.Serializable, RevisionHandler
A little helper class for clocking and outputting times. It measures the CPU time if possible, otherwise it's just based on the system time. In case one just wants to measure time (e.g., database queries don't take up much CPU time, but still might take a long time to finish), then one can disable the use of CPU time as well.- Version:
- $Revision: 7519 $
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
ThreadMXBean.isThreadCpuTimeEnabled(), Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intFORMAT_HHMMSSthe output format in hours:minutes:seconds, with fraction of msecsstatic intFORMAT_MILLISECONDSthe output format in milli-secondsstatic intFORMAT_SECONDSthe output format in seconds, with fraction of msecsintm_OutputFormatthe format of the outputstatic Tag[]TAGS_FORMATthe output formats
-
Constructor Summary
Constructors Constructor Description Clock()automatically starts the clock with FORMAT_SECONDS format and CPU time if availableClock(boolean start)starts the clock depending onstartimmediately with the FORMAT_SECONDS output format and CPU time if availableClock(boolean start, int format)starts the clock depending onstartimmediately, using CPU time if availableClock(int format)automatically starts the clock with the given output format and CPU time if available
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetOutputFormat()returns the output formatjava.lang.StringgetRevision()Returns the revision string.longgetStart()returns the start timelonggetStop()returns the stop time or, if still running, the current timebooleangetUseCpuTime()returns whether the use of CPU is time is enabled/disabled (regardless whether the system supports it or not)booleanisCpuTime()whether the measurement is based on the msecs returned from the System class or on the more accurate CPU time.booleanisRunning()whether the time is still being clockedvoidsetOutputFormat(int value)sets the format of the outputvoidsetUseCpuTime(boolean value)enables/disables the use of CPU time (if measurement of CPU time is available).voidstart()saves the current system time (or CPU time) in msec as start timevoidstop()saves the current system (or CPU time) in msec as stop timejava.lang.StringtoString()returns the elapsed time, getStop() - getStart(), as string
-
-
-
Field Detail
-
FORMAT_MILLISECONDS
public static final int FORMAT_MILLISECONDS
the output format in milli-seconds- See Also:
- Constant Field Values
-
FORMAT_SECONDS
public static final int FORMAT_SECONDS
the output format in seconds, with fraction of msecs- See Also:
- Constant Field Values
-
FORMAT_HHMMSS
public static final int FORMAT_HHMMSS
the output format in hours:minutes:seconds, with fraction of msecs- See Also:
- Constant Field Values
-
TAGS_FORMAT
public static final Tag[] TAGS_FORMAT
the output formats
-
m_OutputFormat
public int m_OutputFormat
the format of the output
-
-
Constructor Detail
-
Clock
public Clock()
automatically starts the clock with FORMAT_SECONDS format and CPU time if available- See Also:
m_OutputFormat
-
Clock
public Clock(int format)
automatically starts the clock with the given output format and CPU time if available- Parameters:
format- the output format- See Also:
m_OutputFormat
-
Clock
public Clock(boolean start)
starts the clock depending onstartimmediately with the FORMAT_SECONDS output format and CPU time if available- Parameters:
start- whether to start the clock immediately- See Also:
m_OutputFormat
-
Clock
public Clock(boolean start, int format)starts the clock depending onstartimmediately, using CPU time if available- Parameters:
start- whether to start the clock immediatelyformat- the format- See Also:
m_OutputFormat
-
-
Method Detail
-
isCpuTime
public boolean isCpuTime()
whether the measurement is based on the msecs returned from the System class or on the more accurate CPU time. Also depends on whether the usage of the CPU time was disabled or enabled.- Returns:
- true if the more accurate CPU time of the thread is used and the use of CPU time hasn't been disabled
- See Also:
System.currentTimeMillis(),ThreadMXBean.isThreadCpuTimeEnabled(),getUseCpuTime()
-
setUseCpuTime
public void setUseCpuTime(boolean value)
enables/disables the use of CPU time (if measurement of CPU time is available). The actual use of CPU time still depends on whether the system supports it. Resets the current timer, if running.- Parameters:
value- if true the CPU time is used (if possible)
-
getUseCpuTime
public boolean getUseCpuTime()
returns whether the use of CPU is time is enabled/disabled (regardless whether the system supports it or not)- Returns:
- true the CPU time is used (if possible)
-
start
public void start()
saves the current system time (or CPU time) in msec as start time- See Also:
m_Start
-
stop
public void stop()
saves the current system (or CPU time) in msec as stop time- See Also:
m_Stop
-
getStart
public long getStart()
returns the start time- Returns:
- the start time
-
getStop
public long getStop()
returns the stop time or, if still running, the current time- Returns:
- the stop time
-
isRunning
public boolean isRunning()
whether the time is still being clocked- Returns:
- true if the time is still being clocked
-
setOutputFormat
public void setOutputFormat(int value)
sets the format of the output- Parameters:
value- the format of the output- See Also:
m_OutputFormat
-
getOutputFormat
public int getOutputFormat()
returns the output format- Returns:
- the output format
- See Also:
m_OutputFormat
-
toString
public java.lang.String toString()
returns the elapsed time, getStop() - getStart(), as string- Overrides:
toStringin classjava.lang.Object- Returns:
- the elapsed time as string
- See Also:
getStart(),getStop()
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Returns:
- the revision
-
-