Stopwatch.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "base/Stopwatch.h"
11 #include "debug/Stream.h"
12 
13 static_assert(Stopwatch::Clock::is_steady,
14  "Stopwatch::Clock is suitable for measuring real-time intervals");
15 
17  subtotal_(Clock::duration::zero())
18 {
19 }
20 
21 Stopwatch::Clock::duration
23 {
24  auto result = subtotal_;
25  if (running())
26  result += Clock::now() - runStart_;
27  return result;
28 }
29 
30 void
32 {
33  if (!running()) {
34  runStart_ = Clock::now();
35  debugs(1, 7, "period " << resumes_<< " started after " << subtotal_.count());
36  }
37  ++resumes_;
38 }
39 
42 {
43  ++pauses_;
44  if (!running()) {
45  const auto runtime = Clock::now() - runStart_;
46  subtotal_ += runtime;
47  debugs(1, 7, "period " << resumes_ << " ran for " << runtime.count());
48  }
49 }
50 
Clock::time_point runStart_
when the current period was initiated
Definition: Stopwatch.h:58
void pause()
ends the current measurement period if needed; requires prior resume()
Definition: Stopwatch.cc:41
uint64_t resumes_
the total number of resume() calls
Definition: Stopwatch.h:62
std::chrono::steady_clock Clock
the underlying time measuring mechanism
Definition: Stopwatch.h:35
void resume()
Definition: Stopwatch.cc:31
bool running() const
whether we are currently measuring time (i.e. between resume() and pause())
Definition: Stopwatch.h:40
Clock::duration total() const
Definition: Stopwatch.cc:22
Clock::duration subtotal_
the sum of all finished periods
Definition: Stopwatch.h:60
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
uint64_t pauses_
the total number of pause() calls
Definition: Stopwatch.h:63

 

Introduction

Documentation

Support

Miscellaneous