]>
Commit | Line | Data |
---|---|---|
bbc27441 AJ |
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 | ||
582c2af2 | 9 | #include "squid.h" |
75072239 | 10 | #include "adaptation/icap/History.h" |
582c2af2 | 11 | #include "Debug.h" |
3ff65596 AR |
12 | #include "globals.h" |
13 | #include "SquidTime.h" | |
14 | ||
5038f9d8 AR |
15 | Adaptation::Icap::History::History(): |
16 | logType(LOG_TAG_NONE), req_sz(0), | |
e1381638 | 17 | pastTime(0), concurrencyLevel(0) |
3ff65596 AR |
18 | { |
19 | } | |
20 | ||
e1381638 | 21 | void Adaptation::Icap::History::start(const char *context) |
3ff65596 AR |
22 | { |
23 | if (!concurrencyLevel++) | |
24 | currentStart = current_time; | |
25 | ||
26 | debugs(93,4, HERE << "start " << context << " level=" << concurrencyLevel | |
e1381638 | 27 | << " time=" << pastTime << ' ' << this); |
3ff65596 AR |
28 | } |
29 | ||
e1381638 | 30 | void Adaptation::Icap::History::stop(const char *context) |
3ff65596 AR |
31 | { |
32 | if (!concurrencyLevel) { | |
e0236918 | 33 | debugs(93, DBG_IMPORTANT, HERE << "Internal error: poor history accounting " << this); |
3ff65596 AR |
34 | return; |
35 | } | |
36 | ||
37 | const int current = currentTime(); | |
38 | debugs(93,4, HERE << "stop " << context << " level=" << concurrencyLevel << | |
e1381638 AJ |
39 | " time=" << pastTime << '+' << current << ' ' << this); |
40 | ||
3ff65596 AR |
41 | if (!--concurrencyLevel) |
42 | pastTime += current; | |
43 | } | |
44 | ||
45 | int Adaptation::Icap::History::processingTime() const | |
46 | { | |
47 | const int total = pastTime + currentTime(); | |
48 | debugs(93,7, HERE << " current total: " << total << ' ' << this); | |
49 | return total; | |
50 | } | |
51 | ||
52 | int Adaptation::Icap::History::currentTime() const | |
53 | { | |
54 | return concurrencyLevel > 0 ? | |
e1381638 | 55 | max(0, tvSubMsec(currentStart, current_time)) : 0; |
3ff65596 | 56 | } |