]> 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-2014 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 logType(LOG_TAG_NONE),
17 req_sz(0),
18 concurrencyLevel(0)
19 {
20 memset(&currentStart, 0, sizeof(currentStart));
21 memset(&pastTime, 0, sizeof(pastTime));
22 }
23
24 void Adaptation::Icap::History::start(const char *context)
25 {
26 if (!concurrencyLevel++)
27 currentStart = current_time;
28
29 debugs(93,4, HERE << "start " << context << " level=" << concurrencyLevel
30 << " time=" << tvToMsec(pastTime) << ' ' << this);
31 }
32
33 void Adaptation::Icap::History::stop(const char *context)
34 {
35 if (!concurrencyLevel) {
36 debugs(93, DBG_IMPORTANT, HERE << "Internal error: poor history accounting " << this);
37 return;
38 }
39
40 struct timeval current;
41 currentTime(current);
42 debugs(93,4, HERE << "stop " << context << " level=" << concurrencyLevel <<
43 " time=" << tvToMsec(pastTime) << '+' << tvToMsec(current) << ' ' << this);
44
45 if (!--concurrencyLevel)
46 tvAssignAdd(pastTime, current);
47 }
48
49 void
50 Adaptation::Icap::History::processingTime(timeval &total) const
51 {
52 currentTime(total);
53 tvAssignAdd(total, pastTime);
54 debugs(93,7, HERE << " current total: " << tvToMsec(total) << ' ' << this);
55 }
56
57 void
58 Adaptation::Icap::History::currentTime(timeval &current) const
59 {
60 if (concurrencyLevel > 0)
61 tvSub(current, currentStart, current_time);
62 else {
63 current.tv_sec = 0;
64 current.tv_usec = 0;
65 }
66 }
67