]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
SourceLayout: shuffle kb_t to ByteCounter in libbase
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 30 Aug 2015 00:26:47 +0000 (17:26 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 30 Aug 2015 00:26:47 +0000 (17:26 -0700)
Also, move kb_incr() logic to ByteCounter operator +=

 There are no logic changes in this patch.

20 files changed:
src/ClientInfo.h
src/PeerDigest.h
src/StatCounters.h
src/base/ByteCounter.h [new file with mode: 0644]
src/base/Makefile.am
src/client_db.cc
src/client_side.cc
src/clients/Client.cc
src/clients/FtpClient.cc
src/gopher.cc
src/http.cc
src/icp_v2.cc
src/peer_digest.cc
src/servers/FtpServer.cc
src/tests/stub_tools.cc
src/tools.cc
src/tools.h
src/tunnel.cc
src/typedefs.h
src/whois.cc

index 365d36eb0342d996edecbb9a7297011b3f29917c..c84f7d3f78a1ab45673efbd51de1f0071e4e68ca 100644 (file)
@@ -9,12 +9,14 @@
 #ifndef SQUID__SRC_CLIENTINFO_H
 #define SQUID__SRC_CLIENTINFO_H
 
+#include "base/ByteCounter.h"
 #include "cbdata.h"
 #include "enums.h"
 #include "hash.h"
 #include "ip/Address.h"
 #include "LogTags.h"
 #include "typedefs.h"
+
 #include <deque>
 
 #if USE_DELAY_POOLS
@@ -31,9 +33,9 @@ public:
     struct {
         int result_hist[LOG_TYPE_MAX];
         int n_requests;
-        kb_t kbytes_in;
-        kb_t kbytes_out;
-        kb_t hit_kbytes_out;
+        ByteCounter kbytes_in;
+        ByteCounter kbytes_out;
+        ByteCounter hit_kbytes_out;
     } Http, Icp;
 
     struct {
index 44e7e41757c6932691b55921bb73902916eecf71..ab37dce501e5dbcd846abf8f12c27772202ff932 100644 (file)
@@ -12,7 +12,6 @@
 #if USE_CACHE_DIGESTS
 
 #include "cbdata.h"
-/* for CacheDigestGuessStats */
 #include "StatCounters.h"
 
 class Version
@@ -106,7 +105,7 @@ public:
 
         struct {
             int msgs;
-            kb_t kbytes;
+            ByteCounter kbytes;
         } sent, recv;
     } stats;
 };
index 62a5443a2f2577c3361cb89fb402beeaa31d3b52..6d5f86fc940689bf5ea7d6a77ed8c0ba753de444 100644 (file)
@@ -9,6 +9,7 @@
 #ifndef STATCOUNTERS_H_
 #define STATCOUNTERS_H_
 
+#include "base/ByteCounter.h"
 #include "StatHist.h"
 
 #if USE_CACHE_DIGESTS
@@ -39,9 +40,9 @@ public:
         int mem_hits;
         int disk_hits;
         int errors;
-        kb_t kbytes_in;
-        kb_t kbytes_out;
-        kb_t hit_kbytes_out;
+        ByteCounter kbytes_in;
+        ByteCounter kbytes_out;
+        ByteCounter hit_kbytes_out;
         StatHist missSvcTime;
         StatHist nearMissSvcTime;
         StatHist nearHitSvcTime;
@@ -54,8 +55,8 @@ public:
         struct {
             int requests;
             int errors;
-            kb_t kbytes_in;
-            kb_t kbytes_out;
+            ByteCounter kbytes_in;
+            ByteCounter kbytes_out;
         } all , http, ftp, other;
     } server;
 
@@ -70,12 +71,12 @@ public:
         int hits_recv;
         int replies_queued;
         int replies_dropped;
-        kb_t kbytes_sent;
-        kb_t q_kbytes_sent;
-        kb_t r_kbytes_sent;
-        kb_t kbytes_recv;
-        kb_t q_kbytes_recv;
-        kb_t r_kbytes_recv;
+        ByteCounter kbytes_sent;
+        ByteCounter q_kbytes_sent;
+        ByteCounter r_kbytes_sent;
+        ByteCounter kbytes_recv;
+        ByteCounter q_kbytes_recv;
+        ByteCounter r_kbytes_recv;
         StatHist querySvcTime;
         StatHist replySvcTime;
         int query_timeouts;
@@ -97,9 +98,9 @@ public:
 
     struct {
         int times_used;
-        kb_t kbytes_sent;
-        kb_t kbytes_recv;
-        kb_t memory;
+        ByteCounter kbytes_sent;
+        ByteCounter kbytes_recv;
+        ByteCounter memory;
         int msgs_sent;
         int msgs_recv;
 #if USE_CACHE_DIGESTS
diff --git a/src/base/ByteCounter.h b/src/base/ByteCounter.h
new file mode 100644 (file)
index 0000000..44362cc
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_BYTECOUNTER_H
+#define SQUID_SRC_BYTECOUNTER_H
+
+/// counter for accumulating byte values
+class ByteCounter
+{
+public:
+    ByteCounter() : bytes(0), kb(0) {}
+
+    ByteCounter &operator +=(size_t v) {
+        bytes += v;
+        kb += (bytes >> 10);
+        bytes &= 0x3FF;
+        return *this;
+    }
+
+public:
+    size_t bytes;
+    size_t kb;
+};
+
+#endif /* SQUID_SRC_BYTECOUNTER_H */
+
index cd03165a177103fd3034a2d301422ea3ff836455..4a43969a413f28d8f7021e7988df3342ce9346ae 100644 (file)
@@ -19,6 +19,7 @@ libbase_la_SOURCES = \
        AsyncJobCalls.h \
        AsyncCallQueue.cc \
        AsyncCallQueue.h \
+       ByteCounter.h \
        CbcPointer.h \
        CbDataList.h \
        CharacterSet.h \
index 87817b3661f3971aadc8d018c37b00cd662f4707..af4fcf7e8e47219bc04b5603b67c0ad0d873a2f9 100644 (file)
@@ -158,17 +158,17 @@ clientdbUpdate(const Ip::Address &addr, const LogTags &ltype, AnyP::ProtocolType
     if (p == AnyP::PROTO_HTTP) {
         ++ c->Http.n_requests;
         ++ c->Http.result_hist[ltype.oldType];
-        kb_incr(&c->Http.kbytes_out, size);
+        c->Http.kbytes_out += size;
 
         if (ltype.isTcpHit())
-            kb_incr(&c->Http.hit_kbytes_out, size);
+            c->Http.hit_kbytes_out += size;
     } else if (p == AnyP::PROTO_ICP) {
         ++ c->Icp.n_requests;
         ++ c->Icp.result_hist[ltype.oldType];
-        kb_incr(&c->Icp.kbytes_out, size);
+        c->Icp.kbytes_out += size;
 
         if (LOG_UDP_HIT == ltype.oldType)
-            kb_incr(&c->Icp.hit_kbytes_out, size);
+            c->Icp.hit_kbytes_out += size;
     }
 
     c->last_seen = squid_curtime;
index 84ef380593ef947855f20f259dcb28cf8c62456f..a0b054306ea4bca636e82811b8d14dbed372bfdd 100644 (file)
@@ -1611,10 +1611,10 @@ clientUpdateSocketStats(const LogTags &logType, size_t size)
     if (size == 0)
         return;
 
-    kb_incr(&statCounter.client_http.kbytes_out, size);
+    statCounter.client_http.kbytes_out += size;
 
     if (logType.isTcpHit())
-        kb_incr(&statCounter.client_http.hit_kbytes_out, size);
+        statCounter.client_http.hit_kbytes_out += size;
 }
 
 /**
@@ -3122,7 +3122,7 @@ ConnStateData::clientReadRequest(const CommIoCbParams &io)
         return;
 
     case Comm::OK:
-        kb_incr(&(statCounter.client_http.kbytes_in), rd.size);
+        statCounter.client_http.kbytes_in += rd.size;
         if (!receivedFirstByte_)
             receivedFirstByte();
         // may comm_close or setReplyToError
index abfcff2c999b925f81e0731091456068834c35ee..3a2c234491e9f6db6ea3164f2a5fa8a176a325b1 100644 (file)
@@ -349,7 +349,7 @@ Client::sentRequestBody(const CommIoCbParams &io)
 
     if (io.size > 0) {
         fd_bytes(io.fd, io.size, FD_WRITE);
-        kb_incr(&(statCounter.server.all.kbytes_out), io.size);
+        statCounter.server.all.kbytes_out += io.size;
         // kids should increment their counters
     }
 
index b496f7582538cef7024a5778ddfa678256eb6053..7720ae1b1f35bb3174ffab0a58e46d0cfe1531a4 100644 (file)
@@ -331,8 +331,8 @@ Ftp::Client::readControlReply(const CommIoCbParams &io)
     debugs(9, 3, "FD " << io.fd << ", Read " << io.size << " bytes");
 
     if (io.size > 0) {
-        kb_incr(&(statCounter.server.all.kbytes_in), io.size);
-        kb_incr(&(statCounter.server.ftp.kbytes_in), io.size);
+        statCounter.server.all.kbytes_in += io.size;
+        statCounter.server.ftp.kbytes_in += io.size;
     }
 
     if (io.flag == Comm::ERR_CLOSING)
@@ -808,8 +808,8 @@ Ftp::Client::writeCommandCallback(const CommIoCbParams &io)
 
     if (io.size > 0) {
         fd_bytes(io.fd, io.size, FD_WRITE);
-        kb_incr(&(statCounter.server.all.kbytes_out), io.size);
-        kb_incr(&(statCounter.server.ftp.kbytes_out), io.size);
+        statCounter.server.all.kbytes_out += io.size;
+        statCounter.server.ftp.kbytes_out += io.size;
     }
 
     if (io.flag == Comm::ERR_CLOSING)
@@ -894,8 +894,8 @@ Ftp::Client::dataRead(const CommIoCbParams &io)
     debugs(9, 3, "FD " << io.fd << " Read " << io.size << " bytes");
 
     if (io.size > 0) {
-        kb_incr(&(statCounter.server.all.kbytes_in), io.size);
-        kb_incr(&(statCounter.server.ftp.kbytes_in), io.size);
+        statCounter.server.all.kbytes_in += io.size;
+        statCounter.server.ftp.kbytes_in += io.size;
     }
 
     if (io.flag == Comm::ERR_CLOSING)
@@ -1020,7 +1020,7 @@ void
 Ftp::Client::sentRequestBody(const CommIoCbParams &io)
 {
     if (io.size > 0)
-        kb_incr(&(statCounter.server.ftp.kbytes_out), io.size);
+        statCounter.server.ftp.kbytes_out += io.size;
     ::Client::sentRequestBody(io);
 }
 
index a482624ec04c38f00309661cdb094b1637dbeaa0..3dcaf9cb8a8cd5759cfac0baafcdd5b5489eeebd 100644 (file)
@@ -752,8 +752,8 @@ gopherReadReply(const Comm::ConnectionPointer &conn, char *buf, size_t len, Comm
         delayId.bytesIn(len);
 #endif
 
-        kb_incr(&(statCounter.server.all.kbytes_in), len);
-        kb_incr(&(statCounter.server.other.kbytes_in), len);
+        statCounter.server.all.kbytes_in += len;
+        statCounter.server.other.kbytes_in += len;
     }
 
     debugs(10, 5, HERE << conn << " read len=" << len);
@@ -826,8 +826,8 @@ gopherSendComplete(const Comm::ConnectionPointer &conn, char *buf, size_t size,
 
     if (size > 0) {
         fd_bytes(conn->fd, size, FD_WRITE);
-        kb_incr(&(statCounter.server.all.kbytes_out), size);
-        kb_incr(&(statCounter.server.other.kbytes_out), size);
+        statCounter.server.all.kbytes_out += size;
+        statCounter.server.other.kbytes_out += size;
     }
 
     if (errflag) {
index 20c5eb5194c170f9996aeabe1a531ad018740209..33ea69a3346d7009d19f8ba9843f3bc21a36bd05 100644 (file)
@@ -1204,8 +1204,8 @@ HttpStateData::readReply(const CommIoCbParams &io)
         delayId.bytesIn(rd.size);
 #endif
 
-        kb_incr(&(statCounter.server.all.kbytes_in), rd.size);
-        kb_incr(&(statCounter.server.http.kbytes_in), rd.size);
+        statCounter.server.all.kbytes_in += rd.size;
+        statCounter.server.http.kbytes_in += rd.size;
         ++ IOStats.Http.reads;
 
         int bin = 0;
@@ -1593,8 +1593,8 @@ HttpStateData::wroteLast(const CommIoCbParams &io)
 
     if (io.size > 0) {
         fd_bytes(io.fd, io.size, FD_WRITE);
-        kb_incr(&(statCounter.server.all.kbytes_out), io.size);
-        kb_incr(&(statCounter.server.http.kbytes_out), io.size);
+        statCounter.server.all.kbytes_out += io.size;
+        statCounter.server.http.kbytes_out += io.size;
     }
 
     if (io.flag == Comm::ERR_CLOSING)
@@ -2458,7 +2458,7 @@ void
 HttpStateData::sentRequestBody(const CommIoCbParams &io)
 {
     if (io.size > 0)
-        kb_incr(&statCounter.server.http.kbytes_out, io.size);
+        statCounter.server.http.kbytes_out += io.size;
 
     Client::sentRequestBody(io);
 }
index 4773c8fccdd7954f89a14e28f92c7306b8c27ef2..27b3726ec20b5bef5f4930443b4f4392b6e30207 100644 (file)
@@ -777,14 +777,14 @@ icpCount(void *buf, int which, size_t len, int delay)
 
     if (SENT == which) {
         ++statCounter.icp.pkts_sent;
-        kb_incr(&statCounter.icp.kbytes_sent, len);
+        statCounter.icp.kbytes_sent += len;
 
         if (ICP_QUERY == icp->opcode) {
             ++statCounter.icp.queries_sent;
-            kb_incr(&statCounter.icp.q_kbytes_sent, len);
+            statCounter.icp.q_kbytes_sent += len;
         } else {
             ++statCounter.icp.replies_sent;
-            kb_incr(&statCounter.icp.r_kbytes_sent, len);
+            statCounter.icp.r_kbytes_sent += len;
             /* this is the sent-reply service time */
             statCounter.icp.replySvcTime.count(delay);
         }
@@ -793,14 +793,14 @@ icpCount(void *buf, int which, size_t len, int delay)
             ++statCounter.icp.hits_sent;
     } else if (RECV == which) {
         ++statCounter.icp.pkts_recv;
-        kb_incr(&statCounter.icp.kbytes_recv, len);
+        statCounter.icp.kbytes_recv += len;
 
         if (ICP_QUERY == icp->opcode) {
             ++statCounter.icp.queries_recv;
-            kb_incr(&statCounter.icp.q_kbytes_recv, len);
+            statCounter.icp.q_kbytes_recv += len;
         } else {
             ++statCounter.icp.replies_recv;
-            kb_incr(&statCounter.icp.r_kbytes_recv, len);
+            statCounter.icp.r_kbytes_recv += len;
             /* statCounter.icp.querySvcTime set in clientUpdateCounters */
         }
 
index 970b50e50a51467e8f7b22a1cc4287df9ea482b0..80ae96be51ff80edaa907973244ecba353113b94 100644 (file)
@@ -853,8 +853,8 @@ peerDigestPDFinish(DigestFetchState * fetch, int pcb_valid, int err)
 
     pd->times.received = squid_curtime;
     pd->times.req_delay = fetch->resp_time;
-    kb_incr(&pd->stats.sent.kbytes, (size_t) fetch->sent.bytes);
-    kb_incr(&pd->stats.recv.kbytes, (size_t) fetch->recv.bytes);
+    pd->stats.sent.kbytes += fetch->sent.bytes;
+    pd->stats.recv.kbytes += fetch->recv.bytes;
     pd->stats.sent.msgs += fetch->sent.msg;
     pd->stats.recv.msgs += fetch->recv.msg;
 
@@ -902,12 +902,9 @@ peerDigestFetchFinish(DigestFetchState * fetch, int err)
     }
 
     /* update global stats */
-    kb_incr(&statCounter.cd.kbytes_sent, (size_t) fetch->sent.bytes);
-
-    kb_incr(&statCounter.cd.kbytes_recv, (size_t) fetch->recv.bytes);
-
+    statCounter.cd.kbytes_sent += fetch->sent.bytes;
+    statCounter.cd.kbytes_recv += fetch->recv.bytes;
     statCounter.cd.msgs_sent += fetch->sent.msg;
-
     statCounter.cd.msgs_recv += fetch->recv.msg;
 
     delete fetch;
@@ -1028,7 +1025,7 @@ peerDigestSetCBlock(PeerDigest * pd, const char *buf)
         pd->cd = cacheDigestCreate(cblock.capacity, cblock.bits_per_entry);
 
         if (cblock.mask_size >= freed_size)
-            kb_incr(&statCounter.cd.memory, cblock.mask_size - freed_size);
+            statCounter.cd.memory += (cblock.mask_size - freed_size);
     }
 
     assert(pd->cd);
index 8ce0bd103386f0c61e65b28e9e4ed267480e5fdf..9c60b337750f88bd6570c0224aa02e654c13a5f2 100644 (file)
@@ -172,7 +172,7 @@ Ftp::Server::readUploadData(const CommIoCbParams &io)
 
     if (io.flag == Comm::OK && bodyPipe != NULL) {
         if (io.size > 0) {
-            kb_incr(&(statCounter.client_http.kbytes_in), io.size);
+            statCounter.client_http.kbytes_in += io.size;
 
             char *const current_buf = uploadBuf + uploadAvailSize;
             if (io.buf != current_buf)
index 3090f35f5888b245e4922faf6c7c246f59e2ce8d..fff72e09ed78bca80083f825472c4add8561882e 100644 (file)
@@ -68,7 +68,6 @@ void setMaxFD(void) STUB
 void setSystemLimits(void) STUB
 void squid_signal(int sig, SIGHDLR * func, int flags) STUB
 void logsFlush(void) STUB
-void kb_incr(kb_t * k, size_t v) STUB
 void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm) STUB
 void parseEtcHosts(void) STUB
 int getMyPort(void) STUB_RETVAL(0)
index 84ed0231569fde6429e22c45ebf29dbd62be41ea..5523e45531d7052b3ef170ac12f525376008ea8f 100644 (file)
@@ -960,14 +960,6 @@ logsFlush(void)
         fflush(debug_log);
 }
 
-void
-kb_incr(kb_t * k, size_t v)
-{
-    k->bytes += v;
-    k->kb += (k->bytes >> 10);
-    k->bytes &= 0x3FF;
-}
-
 void
 debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm)
 {
index afd055c7e5848be238a0920921a158f537b3bf04..09dd88eea69cdd37d2016c7652b3246fc4f43906 100644 (file)
@@ -22,7 +22,6 @@ extern int DebugSignal;
 /// Default is APP_SHORTNAME ('squid').
 extern SBuf service_name;
 
-void kb_incr(kb_t *, size_t);
 void parseEtcHosts(void);
 int getMyPort(void);
 void setUmask(mode_t mask);
index b5467a9242cfe113e5fbb38c3429bfbf44929486..dbb890407929ce7788ebe41f07e1d91315b466c0 100644 (file)
@@ -368,8 +368,8 @@ TunnelStateData::readServer(char *, size_t len, Comm::Flag errcode, int xerrno)
 
     if (len > 0) {
         server.bytesIn(len);
-        kb_incr(&(statCounter.server.all.kbytes_in), len);
-        kb_incr(&(statCounter.server.other.kbytes_in), len);
+        statCounter.server.all.kbytes_in += len;
+        statCounter.server.other.kbytes_in += len;
     }
 
     if (keepGoingAfterRead(len, errcode, xerrno, server, client))
@@ -389,8 +389,8 @@ TunnelStateData::readConnectResponseDone(char *, size_t len, Comm::Flag errcode,
     if (len > 0) {
         connectRespBuf->appended(len);
         server.bytesIn(len);
-        kb_incr(&(statCounter.server.all.kbytes_in), len);
-        kb_incr(&(statCounter.server.other.kbytes_in), len);
+        statCounter.server.all.kbytes_in += len;
+        statCounter.server.other.kbytes_in += len;
     }
 
     if (keepGoingAfterRead(len, errcode, xerrno, server, client))
@@ -526,7 +526,7 @@ TunnelStateData::readClient(char *, size_t len, Comm::Flag errcode, int xerrno)
 
     if (len > 0) {
         client.bytesIn(len);
-        kb_incr(&(statCounter.client_http.kbytes_in), len);
+        statCounter.client_http.kbytes_in += len;
     }
 
     if (keepGoingAfterRead(len, errcode, xerrno, client, server))
@@ -620,8 +620,8 @@ TunnelStateData::writeServerDone(char *, size_t len, Comm::Flag flag, int xerrno
     }
 
     /* Valid data */
-    kb_incr(&(statCounter.server.all.kbytes_out), len);
-    kb_incr(&(statCounter.server.other.kbytes_out), len);
+    statCounter.server.all.kbytes_out += len;
+    statCounter.server.other.kbytes_out += len;
     client.dataSent(len);
 
     /* If the other end has closed, so should we */
@@ -689,7 +689,7 @@ TunnelStateData::writeClientDone(char *, size_t len, Comm::Flag flag, int xerrno
     }
 
     /* Valid data */
-    kb_incr(&(statCounter.client_http.kbytes_out), len);
+    statCounter.client_http.kbytes_out += len;
     server.dataSent(len);
 
     /* If the other end has closed, so should we */
index dd097730233570a4f6a05a8aa825c64872700d1c..0022fbe06d5640473fa4f4e9f3878fd878c2b34b 100644 (file)
@@ -17,11 +17,6 @@ typedef signed int sdirno;
 typedef uint32_t nfmark_t;
 typedef unsigned char tos_t;
 
-typedef struct {
-    size_t bytes;
-    size_t kb;
-} kb_t;
-
 typedef struct _CommWriteStateData CommWriteStateData;
 
 #if SQUID_SNMP
index 25b5972c9144edaad19968937450ac1710f35269..4a830f6074915607e377e413acb4bd65a6593dd8 100644 (file)
@@ -139,8 +139,8 @@ WhoisState::readReply(const Comm::ConnectionPointer &conn, char *aBuffer, size_t
         if (!dataWritten)
             setReplyToOK(entry);
 
-        kb_incr(&(statCounter.server.all.kbytes_in), aBufferLength);
-        kb_incr(&(statCounter.server.http.kbytes_in), aBufferLength);
+        statCounter.server.all.kbytes_in += aBufferLength;
+        statCounter.server.http.kbytes_in += aBufferLength;
 
         /* No range support, we always grab it all */
         dataWritten = true;