]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | Stopwatch::Stopwatch(): | |
17 | subtotal_(Clock::duration::zero()) | |
18 | { | |
19 | } | |
20 | ||
21 | Stopwatch::Clock::duration | |
22 | Stopwatch::total() const | |
23 | { | |
24 | auto result = subtotal_; | |
25 | if (running()) | |
26 | result += Clock::now() - runStart_; | |
27 | return result; | |
28 | } | |
29 | ||
30 | void | |
31 | Stopwatch::resume() | |
32 | { | |
33 | if (!running()) { | |
34 | runStart_ = Clock::now(); | |
35 | debugs(1, 7, "period " << resumes_<< " started after " << subtotal_.count()); | |
36 | } | |
37 | ++resumes_; | |
38 | } | |
39 | ||
40 | /// ends the current measurement period if needed; requires prior resume() | |
41 | void Stopwatch::pause() | |
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 |