Peano
Loading...
Searching...
No Matches
tarch::timing::Watch Class Reference

A simple class that has to be included to measure the clock ticks required for an operation. More...

#include <Watch.h>

Collaboration diagram for tarch::timing::Watch:

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.
 

Detailed Description

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.

Version
Revision
1.9
Author
Tobias Weinzierl, Tobias Neckel

Definition at line 45 of file Watch.h.

Constructor & Destructor Documentation

◆ Watch()

tarch::timing::Watch::Watch ( const std::string & className,
const std::string & operationName,
bool plotResultInDestructor,
bool startToTickImmediately = true )

Construct a watch.

Parameters
classNameName of the class the watch is used within (for log).
operationNameName of the operation the watch is used within.
extendedWatchTypeBool for extended.

Definition at line 10 of file Watch.cpp.

References start().

Here is the call graph for this function:

◆ ~Watch()

tarch::timing::Watch::~Watch ( )
virtual

For standard version (): Stops the watch and plots the time spent.

For the extended version, this is the usual destructor without any special actions.

Definition at line 31 of file Watch.cpp.

References logInfo.

Member Function Documentation

◆ getCalendarTime()

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().

Here is the caller graph for this function:

◆ getCPUTicks()

std::clock_t tarch::timing::Watch::getCPUTicks ( )

Equals getCPUTime() but returns the clock ticks instead of the time in seconds.

Definition at line 71 of file Watch.cpp.

◆ getCPUTime()

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.

Returns
CPU time in seconds

Definition at line 64 of file Watch.cpp.

Referenced by peano4::parallel::SpacetreeSet::finishAllOutstandingSendsAndReceives(), and peano4::parallel::SpacetreeSet::traverse().

Here is the caller graph for this function:

◆ isOn()

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.

Definition at line 77 of file Watch.cpp.

◆ start()

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.

See also
stopTimer()

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().

Here is the caller graph for this function:

◆ stop()

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().

Here is the caller graph for this function:

Field Documentation

◆ _elapsedClockTicks

std::clock_t tarch::timing::Watch::_elapsedClockTicks
private

Holds the elapsed processor time.

Definition at line 80 of file Watch.h.

◆ _elapsedTime

double tarch::timing::Watch::_elapsedTime
private

Holds the elapsed calendar time.

Definition at line 85 of file Watch.h.

◆ _isRunning

bool tarch::timing::Watch::_isRunning
private

Has stopTimer() been called before.

Definition at line 90 of file Watch.h.

◆ _log

tarch::logging::Log tarch::timing::Watch::_log
private

Log device the result is written to.

Definition at line 50 of file Watch.h.

◆ _operationName

std::string tarch::timing::Watch::_operationName
private

Stores the name of the operation the watch is used within.

Definition at line 61 of file Watch.h.

◆ _plotResultInDestructor

bool tarch::timing::Watch::_plotResultInDestructor
private

Flag to distinguish the (original) standard watch.

Is used in the destructor.

Definition at line 56 of file Watch.h.

◆ _startClockTicks

std::clock_t tarch::timing::Watch::_startClockTicks
private

Holds the clock ticks at the beginning of the time measurement.

Definition at line 66 of file Watch.h.

◆ _startTime

std::chrono::steady_clock::time_point tarch::timing::Watch::_startTime
private

Holds the time at the beginning of the time measurement.

Definition at line 71 of file Watch.h.


The documentation for this class was generated from the following files: