Squid Web Cache v8/master
Loading...
Searching...
No Matches
Stopwatch Class Reference

#include <Stopwatch.h>

Public Types

using Clock = std::chrono::steady_clock
 the underlying time measuring mechanism
 

Public Member Functions

 Stopwatch ()
 
bool running () const
 whether we are currently measuring time (i.e. between resume() and pause())
 
bool ran () const
 whether we ever measured time (i.e. resume() has been called)
 
Clock::duration total () const
 
void resume ()
 
void pause ()
 ends the current measurement period if needed; requires prior resume()
 

Private Attributes

Clock::time_point runStart_
 when the current period was initiated
 
Clock::duration subtotal_
 the sum of all finished periods
 
uint64_t resumes_ = 0
 the total number of resume() calls
 
uint64_t pauses_ = 0
 the total number of pause() calls
 

Detailed Description

Quickly accumulates related real-time (a.k.a. "physical time" or "wall clock") periods. Continues to run if the caller is blocked on a system call. Usually suitable for measuring CPU overheads of non-sleeping code sequences.

Definition at line 18 of file Stopwatch.h.

Member Typedef Documentation

◆ Clock

using Stopwatch::Clock = std::chrono::steady_clock

Definition at line 35 of file Stopwatch.h.

Constructor & Destructor Documentation

◆ Stopwatch()

Stopwatch::Stopwatch ( )

Definition at line 16 of file Stopwatch.cc.

Member Function Documentation

◆ pause()

void Stopwatch::pause ( )

ends the current measurement period if needed; each pause() call requires a prior dedicated resume() call

Definition at line 41 of file Stopwatch.cc.

References debugs, pauses_, resumes_, running(), runStart_, and subtotal_.

Referenced by PeeringActivityTimer::stop().

◆ ran()

bool Stopwatch::ran ( ) const
inline

Definition at line 43 of file Stopwatch.h.

References resumes_.

Referenced by Format::Format::assemble().

◆ resume()

void Stopwatch::resume ( )

(re)starts or continues the current measurement period; each resume() call must be paired with a dedicated future pause() call

Definition at line 31 of file Stopwatch.cc.

References debugs, resumes_, running(), runStart_, and subtotal_.

Referenced by PeeringActivityTimer::PeeringActivityTimer(), CodeContext::Entering(), and main().

◆ running()

bool Stopwatch::running ( ) const
inline

Definition at line 40 of file Stopwatch.h.

References pauses_, and resumes_.

Referenced by pause(), resume(), and total().

◆ total()

Stopwatch::Clock::duration Stopwatch::total ( ) const

the sum of all measurement period durations (or zero) includes the current measurement period, if any

Definition at line 22 of file Stopwatch.cc.

References running(), runStart_, and subtotal_.

Referenced by Format::Format::assemble(), and main().

Member Data Documentation

◆ pauses_

uint64_t Stopwatch::pauses_ = 0
private

Definition at line 63 of file Stopwatch.h.

Referenced by pause(), and running().

◆ resumes_

uint64_t Stopwatch::resumes_ = 0
private

Definition at line 62 of file Stopwatch.h.

Referenced by pause(), ran(), resume(), and running().

◆ runStart_

Clock::time_point Stopwatch::runStart_
private

Definition at line 58 of file Stopwatch.h.

Referenced by pause(), resume(), and total().

◆ subtotal_

Clock::duration Stopwatch::subtotal_
private

Definition at line 60 of file Stopwatch.h.

Referenced by pause(), resume(), and total().


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