BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsls::Stopwatch Class Reference

#include <bsls_stopwatch.h>

Public Member Functions

 Stopwatch ()
 
void reset ()
 
void start (bool collectCpuTimes=false)
 
void stop ()
 
double accumulatedSystemTime () const
 
void accumulatedTimes (double *systemTime, double *userTime, double *wallTime) const
 
double accumulatedUserTime () const
 
double accumulatedWallTime () const
 
double elapsedTime () const
 
bool isRunning () const
 

Static Public Attributes

static const bool k_COLLECT_WALL_TIME_ONLY = false
 
static const bool k_COLLECT_WALL_AND_CPU_TIMES = true
 

Detailed Description

The class provides an accumulator for the system, user, and wall times of the current process. A stopwatch can be in either the STOPPED (initial) state or the RUNNING state. It potentially tracks three values: the accumulated system time, the accumulated user time, and the accumulated wall time (all in seconds and all initially set to zero). Whether or not system and user times are accumulated is conditional on how the stopwatch is started (see the start method). While in the RUNNING state, a stopwatch accumulates the above values and it retains the values if put into the STOPPED state (unless reset is called). The accumulated times can be accessed at any time and in either state (RUNNING or STOPPED).

See bsls_stopwatch

Constructor & Destructor Documentation

◆ Stopwatch()

bsls::Stopwatch::Stopwatch ( )
inline

Create a stopwatch in the STOPPED state having total accumulated system, user, and wall times all equal to 0.0.

Member Function Documentation

◆ accumulatedSystemTime()

double bsls::Stopwatch::accumulatedSystemTime ( ) const
inline

Return the total (instantaneous and quiescent) elapsed system time (in seconds) accumulated by this stopwatch, or 0 if the collection of CPU times is disabled.

◆ accumulatedTimes()

void bsls::Stopwatch::accumulatedTimes ( double *  systemTime,
double *  userTime,
double *  wallTime 
) const

Load into the specified systemTime, userTime and wallTime the total (instantaneous and quiescent) elapsed system, user, and wall times (all in seconds) accumulated by this stopwatch. Note that this method attempts to retrieve all of the values at the same time (atomically), if the underlying platform supports it.

◆ accumulatedUserTime()

double bsls::Stopwatch::accumulatedUserTime ( ) const
inline

Return the total (instantaneous and quiescent) elapsed user time (in seconds) accumulated by this stopwatch, or 0 if the collection of CPU times is disabled.

◆ accumulatedWallTime()

double bsls::Stopwatch::accumulatedWallTime ( ) const
inline

Return the total (instantaneous and quiescent) elapsed wall time (in seconds) accumulated by this stopwatch.

◆ elapsedTime()

double bsls::Stopwatch::elapsedTime ( ) const
inline

Return the total (instantaneous and quiescent) elapsed wall time (in seconds) accumulated by this stopwatch. Note that this method is equivalent to accumulatedWallTime.

◆ isRunning()

bool bsls::Stopwatch::isRunning ( ) const
inline

Return true if this stopwatch is in the RUNNING state, and false otherwise.

◆ reset()

void bsls::Stopwatch::reset ( )
inline

Place this stopwatch in the STOPPED state, unconditionally stopping the accumulation of elapsed times, and set the quiescent elapsed times to 0.0.

◆ start()

void bsls::Stopwatch::start ( bool  collectCpuTimes = false)
inline

Place this stopwatch in the RUNNING state and begin accumulating elapsed times if this object was in the STOPPED state. Optionally specify a collectCpuTimes flag indicating whether CPU times should be collected. If collectCpuTimes is not specified, then CPU times are not collected. Note that the instantaneous total elapsed times are available from the RUNNING state. Also note that disabling collection of CPU times will result in fewer systems calls and therefore faster measurements. Also note that collectCpuTimes may be expressed using the one of the class level constants k_COLLECT_WALL_TIME_ONLY, and k_COLLECT_WALL_AND_CPU_TIMES for easier immediate understanding of the meaning of the client code.

◆ stop()

void bsls::Stopwatch::stop ( )
inline

Place this stopwatch in the STOPPED state, unconditionally stopping the accumulation of elapsed times. Note that the quiescent accumulated elapsed times are available while in the STOPPED state.

Member Data Documentation

◆ k_COLLECT_WALL_AND_CPU_TIMES

const bool bsls::Stopwatch::k_COLLECT_WALL_AND_CPU_TIMES = true
static

For readability/ease of understanding of code that calls the start(bool) method use these constants as arguments.

◆ k_COLLECT_WALL_TIME_ONLY

const bool bsls::Stopwatch::k_COLLECT_WALL_TIME_ONLY = false
static

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