![]() |
Peano
|
A simple class that has to be included to measure the clock ticks required for an operation. More...
#include <Watch.h>
Public Member Functions | |
Watch (const std::string &className, const std::string &operationName, bool plotResultInDestructor, bool startToTickImmediately=true) | |
Construct a watch. | |
virtual | ~Watch () |
For standard version (): Stops the watch and plots the time spent. | |
void | start () |
(Re)Start the Timer | |
void | stop () |
Stop timer. | |
double | getCPUTime () |
Return CPU Time in Seconds. | |
std::clock_t | getCPUTicks () |
Equals getCPUTime() but returns the clock ticks instead of the time in seconds. | |
double | getCalendarTime () |
This method returns the elapsed calendar time between the start and stop command of the timer, i.e., the real world time. | |
bool | isOn () const |
This operation returns whether the watch is currently on. | |
Private Attributes | |
tarch::logging::Log | _log |
Log device the result is written to. | |
bool | _plotResultInDestructor |
Flag to distinguish the (original) standard watch. | |
std::string | _operationName |
Stores the name of the operation the watch is used within. | |
std::clock_t | _startClockTicks |
Holds the clock ticks at the beginning of the time measurement. | |
std::chrono::steady_clock::time_point | _startTime |
Holds the time at the beginning of the time measurement. | |
std::clock_t | _elapsedClockTicks |
Holds the elapsed processor time. | |
double | _elapsedTime |
Holds the elapsed calendar time. | |
bool | _isRunning |
Has stopTimer() been called before. | |
A simple class that has to be included to measure the clock ticks required for an operation.
To use it you've to create an instance of this class at the beginning of the operation block you want to measure the time spent within it:
void anyOperation() { tarch::timing::Watch watch("MyClass", "anyOperation()"); ... }
The result the of the measurement is written to log.info level. Note that this operation works within operation blocks (e.g., a for-loop), too.
For an extended measurement of calender (i.e., user) time and a saving of the data and access via getters, we implemented parts of what Markus Langlotz gave us for the ancient stokes project. Additionally, the counter overflow and the non-access to the measured time were reasons for introducing this extended version. Furthermore, we now may choose specific computation intervals to be counted in between the start and the stop command.
|
virtual |
double tarch::timing::Watch::getCalendarTime | ( | ) |
This method returns the elapsed calendar time between the start and stop command of the timer, i.e., the real world time.
The result is given in seconds.
Definition at line 74 of file Watch.cpp.
Referenced by assessKernel(), tarch::logging::Statistics::initData(), main(), runBenchmarks(), and step().
std::clock_t tarch::timing::Watch::getCPUTicks | ( | ) |
Equals getCPUTime() but returns the clock ticks instead of the time in seconds.
double tarch::timing::Watch::getCPUTime | ( | ) |
Return CPU Time in Seconds.
This method returns the elapsed CPU time between the start and stop command of the timer, i.e., the clock ticks actually spent by the process. Take care: This counter might overflow, especially on a 32 bit architecture.
!!! Multithreading
If you use multithreading, CPU time sums up the clock ticks invested by the individual cores, i.e., if you switch from a one core to a dual core machine, the CPU time should roughly double.
Definition at line 64 of file Watch.cpp.
Referenced by peano4::parallel::SpacetreeSet::finishAllOutstandingSendsAndReceives(), and peano4::parallel::SpacetreeSet::traverse().
bool tarch::timing::Watch::isOn | ( | ) | const |
This operation returns whether the watch is currently on.
If the routine returns false, it is currently stopped. The concept of on/off is a logical concept. Internally, a watch simply administers system time snapshots, while the get routines return differences of these snapshots.
void tarch::timing::Watch::start | ( | ) |
(Re)Start the Timer
This method starts the timer. Actually, it restarts the time as the constructor also invokes this operation. You don't have to call start() after stop(). If you omit another call to start(), you just won't reset the baseline, i.e., all getXXXTime() calls will still refer to the same time zero when the Watch has been constructed.
Definition at line 48 of file Watch.cpp.
Referenced by kernel_impl.Enumerator::fetch(), kernel_impl.Enumerator::lower(), main(), kernel_impl.Enumerator::shift(), step(), kernel_impl.Enumerator::upper(), and Watch().
void tarch::timing::Watch::stop | ( | ) |
Stop timer.
This method stops the timer. You may stop a timer multiple time because the stop does not reset the start time. Please note that all the getters return meaningful results if and only if you call stopTimer().
Definition at line 55 of file Watch.cpp.
Referenced by assessKernel(), peano4::parallel::SpacetreeSet::finishAllOutstandingSendsAndReceives(), tarch::logging::Statistics::initData(), main(), runBenchmarks(), step(), and peano4::parallel::SpacetreeSet::traverse().
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |