]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/History.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / icap / History.cc
1 /*
2 * Copyright (C) 1996-2019 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 "adaptation/icap/History.h"
11 #include "Debug.h"
12 #include "globals.h"
13 #include "SquidTime.h"
14
15 Adaptation::Icap::History::History():
16 req_sz(0),
17 concurrencyLevel(0)
18 {
19 memset(&currentStart, 0, sizeof(currentStart));
20 memset(&pastTime, 0, sizeof(pastTime));
21 }
22
23 void Adaptation::Icap::History::start(const char *context)
24 {
25 if (!concurrencyLevel++)
26 currentStart = current_time;
27
28 debugs(93,4, HERE << "start " << context << " level=" << concurrencyLevel
29 << " time=" << tvToMsec(pastTime) << ' ' << this);
30 }
31
32 void Adaptation::Icap::History::stop(const char *context)
33 {
34 if (!concurrencyLevel) {
35 debugs(93, DBG_IMPORTANT, HERE << "Internal error: poor history accounting " << this);
36 return;
37 }
38
39 struct timeval current;
40 currentTime(current);
41 debugs(93,4, HERE << "stop " << context << " level=" << concurrencyLevel <<
42 " time=" << tvToMsec(pastTime) << '+' << tvToMsec(current) << ' ' << this);
43
44 if (!--concurrencyLevel)
45 tvAssignAdd(pastTime, current);
46 }
47
48 void
49 Adaptation::Icap::History::processingTime(timeval &total) const
50 {
51 currentTime(total);
52 tvAssignAdd(total, pastTime);
53 debugs(93,7, HERE << " current total: " << tvToMsec(total) << ' ' << this);
54 }
55
56 void
57 Adaptation::Icap::History::currentTime(timeval &current) const
58 {
59 if (concurrencyLevel > 0)
60 tvSub(current, currentStart, current_time);
61 else {
62 current.tv_sec = 0;
63 current.tv_usec = 0;
64 }
65 }
66