]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/adaptation/icap/History.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / adaptation / icap / History.cc
index a32b96619e57ef96ffecaec65a00ca29e30ec0bf..a75d44faff667f665efd60cdca94e93695f1b588 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -8,17 +8,16 @@
 
 #include "squid.h"
 #include "adaptation/icap/History.h"
-#include "Debug.h"
+#include "debug/Stream.h"
 #include "globals.h"
-#include "SquidTime.h"
+#include "time/gadgets.h"
 
 Adaptation::Icap::History::History():
-        logType(LOG_TAG_NONE),
-        req_sz(0),
-        pastTime(0),
-        concurrencyLevel(0)
+    req_sz(0),
+    concurrencyLevel(0)
 {
     memset(&currentStart, 0, sizeof(currentStart));
+    memset(&pastTime, 0, sizeof(pastTime));
 }
 
 void Adaptation::Icap::History::start(const char *context)
@@ -26,34 +25,42 @@ void Adaptation::Icap::History::start(const char *context)
     if (!concurrencyLevel++)
         currentStart = current_time;
 
-    debugs(93,4, HERE << "start " << context << " level=" << concurrencyLevel
-           << " time=" << pastTime << ' ' << this);
+    debugs(93,4, "start " << context << " level=" << concurrencyLevel
+           << " time=" << tvToMsec(pastTime) << ' ' << this);
 }
 
 void Adaptation::Icap::History::stop(const char *context)
 {
     if (!concurrencyLevel) {
-        debugs(93, DBG_IMPORTANT, HERE << "Internal error: poor history accounting " << this);
+        debugs(93, DBG_IMPORTANT, "ERROR: Squid BUG: poor history accounting " << this);
         return;
     }
 
-    const int current = currentTime();
-    debugs(93,4, HERE << "stop " << context << " level=" << concurrencyLevel <<
-           " time=" << pastTime << '+' << current << ' ' << this);
+    struct timeval current;
+    currentTime(current);
+    debugs(93,4, "stop " << context << " level=" << concurrencyLevel <<
+           " time=" << tvToMsec(pastTime) << '+' << tvToMsec(current) << ' ' << this);
 
     if (!--concurrencyLevel)
-        pastTime += current;
+        tvAssignAdd(pastTime, current);
 }
 
-int Adaptation::Icap::History::processingTime() const
+void
+Adaptation::Icap::History::processingTime(timeval &total) const
 {
-    const int total = pastTime + currentTime();
-    debugs(93,7, HERE << " current total: " << total << ' ' << this);
-    return total;
+    currentTime(total);
+    tvAssignAdd(total, pastTime);
+    debugs(93,7, " current total: " << tvToMsec(total) << ' ' << this);
 }
 
-int Adaptation::Icap::History::currentTime() const
+void
+Adaptation::Icap::History::currentTime(timeval &current) const
 {
-    return concurrencyLevel > 0 ?
-           max(0, tvSubMsec(currentStart, current_time)) : 0;
+    if (concurrencyLevel > 0)
+        tvSub(current, currentStart, current_time);
+    else {
+        current.tv_sec = 0;
+        current.tv_usec = 0;
+    }
 }
+