]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/icap/History.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / icap / History.cc
CommitLineData
bbc27441 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
bbc27441
AJ
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 15Adaptation::Icap::History::History():
f53969cc
SM
16 logType(LOG_TAG_NONE),
17 req_sz(0),
18 concurrencyLevel(0)
3ff65596 19{
23541b3e 20 memset(&currentStart, 0, sizeof(currentStart));
01bd87d8 21 memset(&pastTime, 0, sizeof(pastTime));
3ff65596
AR
22}
23
e1381638 24void Adaptation::Icap::History::start(const char *context)
3ff65596
AR
25{
26 if (!concurrencyLevel++)
27 currentStart = current_time;
28
29 debugs(93,4, HERE << "start " << context << " level=" << concurrencyLevel
01bd87d8 30 << " time=" << tvToMsec(pastTime) << ' ' << this);
3ff65596
AR
31}
32
e1381638 33void Adaptation::Icap::History::stop(const char *context)
3ff65596
AR
34{
35 if (!concurrencyLevel) {
e0236918 36 debugs(93, DBG_IMPORTANT, HERE << "Internal error: poor history accounting " << this);
3ff65596
AR
37 return;
38 }
39
01bd87d8
CT
40 struct timeval current;
41 currentTime(current);
3ff65596 42 debugs(93,4, HERE << "stop " << context << " level=" << concurrencyLevel <<
01bd87d8 43 " time=" << tvToMsec(pastTime) << '+' << tvToMsec(current) << ' ' << this);
e1381638 44
3ff65596 45 if (!--concurrencyLevel)
01bd87d8 46 tvAssignAdd(pastTime, current);
3ff65596
AR
47}
48
01bd87d8
CT
49void
50Adaptation::Icap::History::processingTime(timeval &total) const
3ff65596 51{
01bd87d8
CT
52 currentTime(total);
53 tvAssignAdd(total, pastTime);
54 debugs(93,7, HERE << " current total: " << tvToMsec(total) << ' ' << this);
3ff65596
AR
55}
56
01bd87d8
CT
57void
58Adaptation::Icap::History::currentTime(timeval &current) const
3ff65596 59{
01bd87d8
CT
60 if (concurrencyLevel > 0)
61 tvSub(current, currentStart, current_time);
62 else {
63 current.tv_sec = 0;
64 current.tv_usec = 0;
65 }
3ff65596 66}
f53969cc 67