This class accumulates system, user, and wall times of the current process.

Synopsis

Declared in <bsls_stopwatch.h>

class Stopwatch;

Description

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

Member Functions

Name

Description

Stopwatch [constructor]

Constructors

~Stopwatch [destructor]

Destroy this stopwatch. Note that this method's definition is compiler generated.

accumulatedSystemTime

Return accumulated system CPU time in seconds.

accumulatedTimes

Load the accumulated system, user, and wall times in seconds.

accumulatedUserTime

Return accumulated user CPU time in seconds.

accumulatedWallTime

Return accumulated wall time in seconds.

elapsedTime

Return the accumulated elapsed wall time in seconds.

isRunning

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

reset

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

start

Start this stopwatch if it is not already running.

stop

Stop this stopwatch and cease accumulating elapsed times.

Static Data Members

Name

Description

k_COLLECT_WALL_AND_CPU_TIMES

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

k_COLLECT_WALL_TIME_ONLY

Collect wall time only (not CPU time).

Created with MrDocs