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