]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/History.cc
Merge from trunk
[thirdparty/squid.git] / src / adaptation / icap / History.cc
1 #include "adaptation/icap/History.h"
2 #include "squid.h"
3 #include "globals.h"
4 #include "SquidTime.h"
5
6 Adaptation::Icap::History::History(): mergeOfIcapHeaders(hoRequest),
7 lastIcapHeader(hoRequest), logType(LOG_TAG_NONE), req_sz(0),
8 pastTime(0), concurrencyLevel(0)
9 {
10 }
11
12 Adaptation::Icap::History::History(const Adaptation::Icap::History& ih)
13 {
14 assign(ih);
15 }
16
17 Adaptation::Icap::History::~History()
18 {
19 mergeOfIcapHeaders.clean();
20 lastIcapHeader.clean();
21 rfc931.clean();
22 #if USE_SSL
23 ssluser.clean();
24 #endif
25 log_uri.clean();
26 }
27
28 void Adaptation::Icap::History::assign(const Adaptation::Icap::History& ih)
29 {
30 mergeOfIcapHeaders.clean();
31 mergeOfIcapHeaders.update(&ih.mergeOfIcapHeaders, NULL);
32 lastIcapHeader.clean();
33 lastIcapHeader.update(&ih.lastIcapHeader, NULL);
34 rfc931 = ih.rfc931;
35
36 #if USE_SSL
37 ssluser = ih.ssluser;
38 #endif
39
40 logType = ih.logType;
41 log_uri = ih.log_uri;
42 req_sz = ih.req_sz;
43 pastTime = ih.pastTime;
44 currentStart = ih.currentStart;
45 concurrencyLevel = ih.concurrencyLevel;
46 debugs(93,7, HERE << this << " = " << &ih);
47 }
48
49 Adaptation::Icap::History& Adaptation::Icap::History::operator=(const History& ih)
50 {
51 if (this != &ih)
52 assign(ih);
53 return *this;
54 }
55
56 void Adaptation::Icap::History::setIcapLastHeader(const HttpHeader * lih)
57 {
58 lastIcapHeader.clean();
59 lastIcapHeader.update(lih, NULL);
60 }
61
62 void Adaptation::Icap::History::mergeIcapHeaders(const HttpHeader * lih)
63 {
64 mergeOfIcapHeaders.update(lih, NULL);
65 mergeOfIcapHeaders.compact();
66 }
67
68 void Adaptation::Icap::History::start(const char *context)
69 {
70 if (!concurrencyLevel++)
71 currentStart = current_time;
72
73 debugs(93,4, HERE << "start " << context << " level=" << concurrencyLevel
74 << " time=" << pastTime << ' ' << this);
75 }
76
77 void Adaptation::Icap::History::stop(const char *context)
78 {
79 if (!concurrencyLevel) {
80 debugs(93,1, HERE << "Internal error: poor history accounting " << this);
81 return;
82 }
83
84 const int current = currentTime();
85 debugs(93,4, HERE << "stop " << context << " level=" << concurrencyLevel <<
86 " time=" << pastTime << '+' << current << ' ' << this);
87
88 if (!--concurrencyLevel)
89 pastTime += current;
90 }
91
92 int Adaptation::Icap::History::processingTime() const
93 {
94 const int total = pastTime + currentTime();
95 debugs(93,7, HERE << " current total: " << total << ' ' << this);
96 return total;
97 }
98
99 int Adaptation::Icap::History::currentTime() const
100 {
101 return concurrencyLevel > 0 ?
102 max(0, tvSubMsec(currentStart, current_time)) : 0;
103 }