]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3381: 32-bit overflow assertion in StatHist
authorFrancesco Chemolli <kinkie@squid-cache.org>
Sat, 3 Mar 2012 23:19:03 +0000 (16:19 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 3 Mar 2012 23:19:03 +0000 (16:19 -0700)
- StatHist refactoring
- StatCounters untangling from global symbol table
- Added StatHist unit tests, and moved algorithm consistency checks there.
- Expanded storage for histograms to 64-bit unsigned. (bug 3381)
- Inlined StatHist constructor, destructor and assignment operator.
- added protection against self-assignment
- Implemented stubs for StatHist.cc and mem.cc

57 files changed:
src/CacheDigest.cc
src/DiskIO/DiskDaemon/DiskdFile.cc
src/DiskIO/DiskDaemon/DiskdIOStrategy.cc
src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc
src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc
src/DiskIO/IpcIo/IpcIoFile.cc
src/HttpHdrCc.cc
src/HttpHdrSc.cc
src/HttpHdrScTarget.cc
src/HttpHeader.cc
src/HttpHeaderStat.h [new file with mode: 0644]
src/Makefile.am
src/PeerDigest.h
src/Server.cc
src/StatCounters.cc [new file with mode: 0644]
src/StatCounters.h [new file with mode: 0644]
src/StatHist.cc
src/StatHist.h [new file with mode: 0644]
src/client_db.cc
src/client_side.cc
src/comm.cc
src/comm/ModDevPoll.cc
src/comm/ModEpoll.cc
src/comm/ModPoll.cc
src/comm/ModSelect.cc
src/comm/ModSelectWin32.cc
src/comm/TcpAcceptor.cc
src/comm/Write.cc
src/disk.cc
src/fqdncache.cc
src/fs/ufs/store_dir_ufs.cc
src/ftp.cc
src/globals.h
src/gopher.cc
src/htcp.cc
src/http.cc
src/icp_v2.cc
src/ipcache.cc
src/main.cc
src/protos.h
src/snmp_agent.cc
src/stat.cc
src/store.cc
src/store_client.cc
src/store_rebuild.cc
src/store_swapin.cc
src/store_swapout.cc
src/structs.h
src/tests/stub_StatHist.cc
src/tests/stub_mem.cc [new file with mode: 0644]
src/tests/stub_stmem.cc
src/tests/testStatHist.cc [new file with mode: 0644]
src/tests/testStatHist.h [new file with mode: 0644]
src/tunnel.cc
src/typedefs.h
src/unlinkd.cc
src/whois.cc

index 8a960665603ac44a6256e8bde76addf1120f18ba..b2f2cdb9716efab0ecc5aa5a7f01d8d779272cf1 100644 (file)
@@ -34,6 +34,7 @@
  */
 
 #include "squid-old.h"
+#include "StatCounters.h"
 #include "Store.h"
 
 #if USE_CACHE_DIGESTS
@@ -176,7 +177,7 @@ cacheDigestAdd(CacheDigest * cd, const cache_key * key)
             on_xition_cnt++;
         }
 
-        statHistCount(&statCounter.cd.on_xition_count, on_xition_cnt);
+        statCounter.cd.on_xition_count.count(on_xition_cnt);
     }
 #endif
     cd->count++;
@@ -235,30 +236,30 @@ cacheDigestBitUtil(const CacheDigest * cd)
 }
 
 void
-cacheDigestGuessStatsUpdate(cd_guess_stats * stats, int real_hit, int guess_hit)
+cacheDigestGuessStatsUpdate(CacheDigestGuessStats * stats, int real_hit, int guess_hit)
 {
     assert(stats);
 
     if (real_hit) {
         if (guess_hit)
-            stats->true_hits++;
+            ++stats->trueHits;
         else
-            stats->false_misses++;
+            ++stats->falseMisses;
     } else {
         if (guess_hit)
-            stats->false_hits++;
+            ++stats->falseHits;
         else
-            stats->true_misses++;
+            ++stats->trueMisses;
     }
 }
 
 void
-cacheDigestGuessStatsReport(const cd_guess_stats * stats, StoreEntry * sentry, const char *label)
+cacheDigestGuessStatsReport(const CacheDigestGuessStats * stats, StoreEntry * sentry, const char *label)
 {
-    const int true_count = stats->true_hits + stats->true_misses;
-    const int false_count = stats->false_hits + stats->false_misses;
-    const int hit_count = stats->true_hits + stats->false_hits;
-    const int miss_count = stats->true_misses + stats->false_misses;
+    const int true_count = stats->trueHits + stats->trueMisses;
+    const int false_count = stats->falseHits + stats->falseMisses;
+    const int hit_count = stats->trueHits + stats->falseHits;
+    const int miss_count = stats->trueMisses + stats->falseMisses;
     const int tot_count = true_count + false_count;
 
     assert(label);
@@ -273,19 +274,19 @@ cacheDigestGuessStatsReport(const cd_guess_stats * stats, StoreEntry * sentry, c
     storeAppendPrintf(sentry, "guess\t hit\t\t miss\t\t total\t\t\n");
     storeAppendPrintf(sentry, " \t #\t %%\t #\t %%\t #\t %%\t\n");
     storeAppendPrintf(sentry, "true\t %d\t %.2f\t %d\t %.2f\t %d\t %.2f\n",
-                      stats->true_hits, xpercent(stats->true_hits, tot_count),
-                      stats->true_misses, xpercent(stats->true_misses, tot_count),
+                      stats->trueHits, xpercent(stats->trueHits, tot_count),
+                      stats->trueMisses, xpercent(stats->trueMisses, tot_count),
                       true_count, xpercent(true_count, tot_count));
     storeAppendPrintf(sentry, "false\t %d\t %.2f\t %d\t %.2f\t %d\t %.2f\n",
-                      stats->false_hits, xpercent(stats->false_hits, tot_count),
-                      stats->false_misses, xpercent(stats->false_misses, tot_count),
+                      stats->falseHits, xpercent(stats->falseHits, tot_count),
+                      stats->falseMisses, xpercent(stats->falseMisses, tot_count),
                       false_count, xpercent(false_count, tot_count));
     storeAppendPrintf(sentry, "all\t %d\t %.2f\t %d\t %.2f\t %d\t %.2f\n",
                       hit_count, xpercent(hit_count, tot_count),
                       miss_count, xpercent(miss_count, tot_count),
                       tot_count, xpercent(tot_count, tot_count));
     storeAppendPrintf(sentry, "\tclose_hits: %d ( %d%%) /* cd said hit, doc was in the peer cache, but we got a miss */\n",
-                      stats->close_hits, xpercentInt(stats->close_hits, stats->false_hits));
+                      stats->closeHits, xpercentInt(stats->closeHits, stats->falseHits));
 }
 
 void
index 4a6f955d8ada31a7258f0b41773ac685d574b0ea..af376dcb8cb5796766eb93351dd046a33fc95e6c 100644 (file)
@@ -47,6 +47,7 @@
 #include "DiskIO/IORequestor.h"
 #include "DiskIO/ReadRequest.h"
 #include "DiskIO/WriteRequest.h"
+#include "StatCounters.h"
 CBDATA_CLASS_INIT(DiskdFile);
 
 void *
@@ -275,7 +276,7 @@ DiskdFile::completed(diomsg *M)
 void
 DiskdFile::openDone(diomsg *M)
 {
-    statCounter.syscalls.disk.opens++;
+    ++statCounter.syscalls.disk.opens;
     debugs(79, 3, "storeDiskdOpenDone: status " << M->status);
 
     if (M->status < 0) {
@@ -292,7 +293,7 @@ DiskdFile::openDone(diomsg *M)
 void
 DiskdFile::createDone(diomsg *M)
 {
-    statCounter.syscalls.disk.opens++;
+    ++statCounter.syscalls.disk.opens;
     debugs(79, 3, "storeDiskdCreateDone: status " << M->status);
 
     if (M->status < 0) {
@@ -355,7 +356,7 @@ DiskdFile::ioCompleted()
 void
 DiskdFile::closeDone(diomsg * M)
 {
-    statCounter.syscalls.disk.closes++;
+    ++statCounter.syscalls.disk.closes;
     debugs(79, 3, "DiskdFile::closeDone: status " << M->status);
 
     if (M->status < 0) {
@@ -376,7 +377,7 @@ DiskdFile::closeDone(diomsg * M)
 void
 DiskdFile::readDone(diomsg * M)
 {
-    statCounter.syscalls.disk.reads++;
+    ++statCounter.syscalls.disk.reads;
     debugs(79, 3, "DiskdFile::readDone: status " << M->status);
     assert (M->requestor);
     ReadRequest::Pointer readRequest = dynamic_cast<ReadRequest *>(M->requestor);
@@ -400,7 +401,7 @@ DiskdFile::readDone(diomsg * M)
 void
 DiskdFile::writeDone(diomsg *M)
 {
-    statCounter.syscalls.disk.writes++;
+    ++statCounter.syscalls.disk.writes;
     debugs(79, 3, "storeDiskdWriteDone: status " << M->status);
     assert (M->requestor);
     WriteRequest::Pointer writeRequest = dynamic_cast<WriteRequest *>(M->requestor);
index ee2f3d706b1dc3ccfd2a8ae679edaf06f3ff7456..1c0b937e5bcc25ff7c3e2a6e43fc7dc3820b1ee9 100644 (file)
@@ -46,6 +46,7 @@
 #include "diomsg.h"
 /* for statfs */
 #include "Store.h"
+#include "StatCounters.h"
 #include "SquidTime.h"
 
 diskd_stats_t diskd_stats;
@@ -293,7 +294,7 @@ void
 DiskdIOStrategy::unlinkDone(diomsg * M)
 {
     debugs(79, 3, "storeDiskdUnlinkDone: file " << shm.buf + M->shm_offset << " status " << M->status);
-    statCounter.syscalls.disk.unlinks++;
+    ++statCounter.syscalls.disk.unlinks;
 
     if (M->status < 0)
         diskd_stats.unlink.fail++;
index a6badd437f195991c824f283bfa892a87e467cc5..19cfc6222cce0a0f761bf9d72b2ff889648e621c 100644 (file)
@@ -41,6 +41,7 @@
 #include "DiskIO/IORequestor.h"
 #include "DiskIO/ReadRequest.h"
 #include "DiskIO/WriteRequest.h"
+#include "StatCounters.h"
 
 /* === PUBLIC =========================================================== */
 
@@ -83,7 +84,7 @@ DiskThreadsDiskFile::~DiskThreadsDiskFile()
 void
 DiskThreadsDiskFile::open(int flags, mode_t mode, RefCount<IORequestor> callback)
 {
-    statCounter.syscalls.disk.opens++;
+    ++statCounter.syscalls.disk.opens;
 #if !ASYNC_OPEN
 
     fd = file_open(path_, flags);
@@ -118,7 +119,7 @@ DiskThreadsDiskFile::read(ReadRequest * request)
     debugs(79, 3, "DiskThreadsDiskFile::read: " << this << ", size " << request->len);
     assert (fd > -1);
     assert (ioRequestor.getRaw());
-    statCounter.syscalls.disk.reads++;
+    ++statCounter.syscalls.disk.reads;
     ++inProgressIOs;
 #if ASYNC_READ
 
@@ -132,7 +133,7 @@ DiskThreadsDiskFile::read(ReadRequest * request)
 void
 DiskThreadsDiskFile::create(int flags, mode_t mode, RefCount<IORequestor> callback)
 {
-    statCounter.syscalls.disk.opens++;
+    ++statCounter.syscalls.disk.opens;
 #if !ASYNC_CREATE
 
     int fd = file_open(path_, flags);
@@ -203,7 +204,7 @@ DiskThreadsDiskFile::openDone(int unused, const char *unused2, int anFD, int err
 void DiskThreadsDiskFile::doClose()
 {
     if (fd > -1) {
-        statCounter.syscalls.disk.closes++;
+        ++statCounter.syscalls.disk.closes;
 #if ASYNC_CLOSE
 
         aioClose(fd);
@@ -246,7 +247,7 @@ void
 DiskThreadsDiskFile::write(WriteRequest * writeRequest)
 {
     debugs(79, 3, "DiskThreadsDiskFile::write: FD " << fd);
-    statCounter.syscalls.disk.writes++;
+    ++statCounter.syscalls.disk.writes;
     ++inProgressIOs;
 #if ASYNC_WRITE
 
index 7e2e16e206ce7ccb6419722cd5c988c79d676f84..e490f392c94bd0ffb251afffc9f8d1ff8476c7f2 100644 (file)
@@ -40,6 +40,7 @@
 #include "DiskThreadsIOStrategy.h"
 #include "fde.h"
 #include "mgr/Registration.h"
+#include "StatCounters.h"
 /* for statfs */
 #include "Store.h"
 
@@ -263,6 +264,6 @@ DiskThreadsIOStrategy::unlinkdUseful() const
 void
 DiskThreadsIOStrategy::unlinkFile(char const *path)
 {
-    statCounter.syscalls.disk.unlinks++;
+    ++statCounter.syscalls.disk.unlinks;
     aioUnlink(path, NULL, NULL);
 }
index a648f1fa0f4c0766417a896c24693a47c7191296..30f9c585f7da132e9f86e0c727ff21c16dd59c31 100644 (file)
@@ -17,6 +17,7 @@
 #include "ipc/StrandSearch.h"
 #include "ipc/UdsOp.h"
 #include "ipc/mem/Pages.h"
+#include "StatCounters.h"
 #include "SquidTime.h"
 
 CBDATA_CLASS_INIT(IpcIoFile);
@@ -628,7 +629,7 @@ diskerRead(IpcIoMsg &ipcIo)
 
     char *const buf = Ipc::Mem::PagePointer(ipcIo.page);
     const ssize_t read = pread(TheFile, buf, min(ipcIo.len, Ipc::Mem::PageSize()), ipcIo.offset);
-    statCounter.syscalls.disk.reads++;
+    ++statCounter.syscalls.disk.reads;
     fd_bytes(TheFile, read, FD_READ);
 
     if (read >= 0) {
@@ -650,7 +651,7 @@ diskerWrite(IpcIoMsg &ipcIo)
 {
     const char *const buf = Ipc::Mem::PagePointer(ipcIo.page);
     const ssize_t wrote = pwrite(TheFile, buf, min(ipcIo.len, Ipc::Mem::PageSize()), ipcIo.offset);
-    statCounter.syscalls.disk.writes++;
+    ++statCounter.syscalls.disk.writes;
     fd_bytes(TheFile, wrote, FD_WRITE);
 
     if (wrote >= 0) {
index 6d543d7b0263484f08c5b8c2dd9b1e93d1fd32c7..4d86e7e461c9fb8ac1e255bb8f351de14184f6b6 100644 (file)
 
 #include "squid-old.h"
 #include "base/StringArea.h"
-#include "Store.h"
 #include "HttpHeader.h"
+#include "HttpHeaderStat.h"
 #include "HttpHdrCc.h"
+#include "StatHist.h"
+#include "Store.h"
 
 #if HAVE_MAP
 #include <map>
@@ -285,7 +287,7 @@ httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist)
 
     for (c = CC_PUBLIC; c < CC_ENUM_END; ++c)
         if (cc->isSet(c))
-            statHistCount(hist, c);
+            hist->count(c);
 }
 
 void
index 938c79cdeb21b534dc4486ebad864c506d446cbb..1b554518bd3e5bbd26d42f0cad870358d47ff338 100644 (file)
@@ -39,6 +39,7 @@
 #include "squid-old.h"
 #include "Store.h"
 #include "HttpHeader.h"
+#include "HttpHeaderStat.h"
 #include "HttpHdrSc.h"
 
 #if HAVE_MAP
index 5a78eb901a81b7d46dfdb3af182fb8b3409e8f03..cc9571ad6c4892e23d57416883d23f85415f365e 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "squid-old.h"
 #include "HttpHdrSc.h"
+#include "StatHist.h"
 
 extern http_hdr_sc_type &operator++ (http_hdr_sc_type &aHeader);
 /* copies non-extant fields from new_sc to this sc */
@@ -71,5 +72,5 @@ HttpHdrScTarget::updateStats(StatHist * hist) const
 
     for (c = SC_NO_STORE; c < SC_ENUM_END; ++c)
         if (isSet(c))
-            statHistCount(hist, c);
+            hist->count(c);
 }
index 12cb2c4a2214600225716d4049c825640d057dd0..cf398e7f23e49fbd8c06d3fadf894bc5cd9c4a3f 100644 (file)
 #include "HttpHdrCc.h"
 #include "HttpHdrSc.h"
 #include "HttpHeader.h"
+#include "HttpHeaderStat.h"
 #include "MemBuf.h"
 #include "mgr/Registration.h"
 #include "rfc1123.h"
+#include "StatHist.h"
 #include "Store.h"
 #include "TimeOrTag.h"
 
@@ -374,10 +376,10 @@ httpHeaderStatInit(HttpHeaderStat * hs, const char *label)
     assert(label);
     memset(hs, 0, sizeof(HttpHeaderStat));
     hs->label = label;
-    statHistEnumInit(&hs->hdrUCountDistr, 32); /* not a real enum */
-    statHistEnumInit(&hs->fieldTypeDistr, HDR_ENUM_END);
-    statHistEnumInit(&hs->ccTypeDistr, CC_ENUM_END);
-    statHistEnumInit(&hs->scTypeDistr, SC_ENUM_END);
+    hs->hdrUCountDistr.enumInit(32);   /* not a real enum */
+    hs->fieldTypeDistr.enumInit(HDR_ENUM_END);
+    hs->ccTypeDistr.enumInit(CC_ENUM_END);
+    hs->scTypeDistr.enumInit(SC_ENUM_END);
 }
 
 /*
@@ -444,7 +446,7 @@ HttpHeader::clean()
 
     if (owner <= hoReply) {
         if (0 != entries.count)
-            statHistCount(&HttpHeaderStats[owner].hdrUCountDistr, entries.count);
+            HttpHeaderStats[owner].hdrUCountDistr.count(entries.count);
 
         HttpHeaderStats[owner].destroyedCount++;
 
@@ -456,7 +458,7 @@ HttpHeader::clean()
             if (e->id < 0 || e->id >= HDR_ENUM_END) {
                 debugs(55, 0, "HttpHeader::clean BUG: entry[" << pos << "] is invalid (" << e->id << "). Ignored.");
             } else {
-                statHistCount(&HttpHeaderStats[owner].fieldTypeDistr, e->id);
+                HttpHeaderStats[owner].fieldTypeDistr.count(e->id);
                 /* yes, this deletion leaves us in an inconsistent state */
                 delete e;
             }
@@ -1691,19 +1693,19 @@ httpHeaderStatDump(const HttpHeaderStat * hs, StoreEntry * e)
     storeAppendPrintf(e, "\nField type distribution\n");
     storeAppendPrintf(e, "%2s\t %-20s\t %5s\t %6s\n",
                       "id", "name", "count", "#/header");
-    statHistDump(&hs->fieldTypeDistr, e, httpHeaderFieldStatDumper);
+    hs->fieldTypeDistr.dump(e, httpHeaderFieldStatDumper);
     storeAppendPrintf(e, "\nCache-control directives distribution\n");
     storeAppendPrintf(e, "%2s\t %-20s\t %5s\t %6s\n",
                       "id", "name", "count", "#/cc_field");
-    statHistDump(&hs->ccTypeDistr, e, httpHdrCcStatDumper);
+    hs->ccTypeDistr.dump(e, httpHdrCcStatDumper);
     storeAppendPrintf(e, "\nSurrogate-control directives distribution\n");
     storeAppendPrintf(e, "%2s\t %-20s\t %5s\t %6s\n",
                       "id", "name", "count", "#/sc_field");
-    statHistDump(&hs->scTypeDistr, e, httpHdrScStatDumper);
+    hs->scTypeDistr.dump(e, httpHdrScStatDumper);
     storeAppendPrintf(e, "\nNumber of fields per header distribution\n");
     storeAppendPrintf(e, "%2s\t %-5s\t %5s\t %6s\n",
                       "id", "#flds", "count", "%total");
-    statHistDump(&hs->hdrUCountDistr, e, httpHeaderFldsPerHdrDumper);
+    hs->hdrUCountDistr.dump(e, httpHeaderFldsPerHdrDumper);
     dump_stat = NULL;
 }
 
diff --git a/src/HttpHeaderStat.h b/src/HttpHeaderStat.h
new file mode 100644 (file)
index 0000000..7fcff9d
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * HttpHeaderStat.h
+ *
+ *  Created on: Dec 9, 2011
+ *      Author: kinkie
+ */
+
+#ifndef HTTPHEADERSTAT_H_
+#define HTTPHEADERSTAT_H_
+
+/* per header statistics */
+
+#include "StatHist.h"
+class HttpHeaderStat
+{
+public:
+    const char *label;
+    HttpHeaderMask *owner_mask;
+
+    StatHist hdrUCountDistr;
+    StatHist fieldTypeDistr;
+    StatHist ccTypeDistr;
+    StatHist scTypeDistr;
+
+    int parsedCount;
+    int ccParsedCount;
+    int scParsedCount;
+    int destroyedCount;
+    int busyDestroyedCount;
+};
+
+
+#endif /* HTTPHEADERSTAT_H_ */
index f4bb1e239891a068657f5772487872f887a8c9fd..639882be33a03657a14037bd798bc5d8090d1956 100644 (file)
@@ -358,6 +358,7 @@ squid_SOURCES = \
        HttpHdrScTarget.h \
        HttpHdrContRange.cc \
        HttpHdrContRange.h \
+       HttpHeaderStat.h \
        HttpHeader.cc \
        HttpHeader.h \
        HttpHeaderMask.h \
@@ -429,6 +430,9 @@ squid_SOURCES = \
        SquidMath.cc \
        SquidNew.cc \
        stat.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
        StatHist.cc \
        String.cc \
        stmem.cc \
@@ -1016,6 +1020,7 @@ check_PROGRAMS+=\
        tests/testString \
        tests/testURL \
        tests/testConfigParser \
+       tests/testStatHist \
        $(STORE_TESTS)
 
 ## NP: required to run the above list. check_PROGRAMS only builds the binaries...
@@ -1086,6 +1091,9 @@ tests_testHttpReply_SOURCES=\
        tests/stub_cache_manager.cc \
        tests/stub_debug.cc \
        tests/stub_HelperChildConfig.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
        tests/stub_StatHist.cc \
        tests/stub_store.cc \
        tests/stub_store_stats.cc \
@@ -1112,27 +1120,7 @@ tests_testHttpReply_LDADD=\
        $(XTRA_LIBS)
 tests_testHttpReply_DEPENDENCIES= $(SQUID_CPPUNIT_LA)
 
-## Tests for the ACLMaxUserIP class
-## acl needs wordlist. wordlist needs MemBug
-## MemBuf needs mem, MemBuf needs event,
-## event needs cbdata.
-## ACLMaxUserUP needs $(AUTH_LIBS)
-## ACLMaxUserIP needs ACLChecklist
-## AuthUser request needs HttpHeader, which brings in 
-##     ETag.cc \
-##     HttpHeader.cc \
-##     HttpHeaderTools.cc \
-##     HttpHdrContRange.cc \
-##     HttpHdrCc.cc \
-##     HttpHdrRange.cc \
-##     HttpHdrSc.cc \
-##     HttpHdrScTarget.cc \
-##     Packer.cc \
-##     StatHist.cc \
-##     String.cc \
-##
-##     disk.cc \
-##     fs/libfs.la \
+
 tests_testACLMaxUserIP_SOURCES= \
        cbdata.cc \
        ClientInfo.h \
@@ -1163,7 +1151,9 @@ tests_testACLMaxUserIP_SOURCES= \
        Packer.cc \
        Parsing.cc \
        SquidMath.cc \
-       StatHist.cc \
+       StatCounters.h \
+       StatHist.h \
+       tests/stub_StatHist.cc \
        stmem.cc \
        String.cc \
        store_dir.cc \
@@ -1362,7 +1352,10 @@ tests_testCacheManager_SOURCES = \
        SquidMath.h \
        SquidMath.cc \
        stat.cc \
-       StatHist.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
+       tests/stub_StatHist.cc \
        stmem.cc \
        store.cc \
        store_client.cc \
@@ -1483,7 +1476,10 @@ tests_testDiskIO_SOURCES = \
        Parsing.cc \
        refresh.cc \
        RemovalPolicy.cc \
-       StatHist.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
+       tests/stub_StatHist.cc \
        stmem.cc \
        StoreFileSystem.cc \
        StoreIOState.cc \
@@ -1688,6 +1684,9 @@ tests_testEvent_SOURCES = \
        SquidMath.cc \
        SquidMath.h \
        stat.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
        StatHist.cc \
        stmem.cc \
        store.cc \
@@ -1879,6 +1878,9 @@ tests_testEventLoop_SOURCES = \
        SquidMath.h \
        SquidMath.cc \
        stat.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
        StatHist.cc \
        stmem.cc \
        store.cc \
@@ -2066,6 +2068,9 @@ tests_test_http_range_SOURCES = \
        SquidMath.h \
        SquidMath.cc \
        stat.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
        StatHist.cc \
        stmem.cc \
        store.cc \
@@ -2291,6 +2296,9 @@ tests_testHttpRequest_SOURCES = \
        SquidMath.h \
        SquidMath.cc \
        stat.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
        StatHist.cc \
        stmem.cc \
        store.cc \
@@ -2406,6 +2414,9 @@ tests_testStore_SOURCES= \
        Parsing.cc \
        RemovalPolicy.cc \
        refresh.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
        StatHist.cc \
        stmem.cc \
        store.cc \
@@ -2638,6 +2649,9 @@ tests_testUfs_SOURCES = \
        HttpHdrSc.cc \
        HttpHdrScTarget.cc \
        url.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
        StatHist.cc \
        HttpHdrRange.cc \
        ETag.cc \
@@ -2731,7 +2745,10 @@ tests_testRock_SOURCES = \
        Packer.cc \
        Parsing.cc \
        RemovalPolicy.cc \
-       StatHist.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
+       tests/stub_StatHist.cc \
        stmem.cc \
        store.cc \
        StoreFileSystem.cc \
@@ -2899,9 +2916,10 @@ tests_testCoss_SOURCES = \
        HttpHdrSc.cc \
        HttpHdrScTarget.cc \
        url.cc \
-       StatHist.cc \
-       HttpHdrRange.cc \
-       ETag.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
+       tests/stub_StatHist.cc \
        tests/stub_errorpage.cc \
        tests/stub_HttpRequest.cc \
        tests/stub_access_log.cc \
@@ -3033,9 +3051,10 @@ tests_testNull_SOURCES = \
        HttpHdrSc.cc \
        HttpHdrScTarget.cc \
        url.cc \
-       StatHist.cc \
-       HttpHdrRange.cc \
-       ETag.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
+       tests/stub_StatHist.cc \
        tests/stub_errorpage.cc \
        tests/stub_HttpRequest.cc \
        tests/stub_access_log.cc \
@@ -3184,7 +3203,10 @@ tests_testURL_SOURCES = \
        SquidMath.h \
        SquidMath.cc \
        stat.cc \
-       StatHist.cc \
+       StatCounters.h \
+       StatCounters.cc \
+       StatHist.h \
+       tests/stub_StatHist.cc \
        stmem.cc \
        store.cc \
        store_client.cc \
@@ -3304,6 +3326,41 @@ tests_testConfigParser_LDADD = \
 tests_testConfigParser_LDFLAGS = $(LIBADD_DL)
 tests_testConfigParser_DEPENDENCIES = \
        $(SQUID_CPPUNIT_LA)
+       
+tests_testStatHist_SOURCES = \
+       cbdata.cc \
+       MemBuf.cc \
+       StatHist.cc \
+       StatHist.h \
+       String.cc \
+       tests/stub_cache_manager.cc \
+       tests/stub_comm.cc \
+       tests/stub_debug.cc \
+       tests/stub_DelayId.cc \
+       tests/stub_HelperChildConfig.cc \
+       tests/stub_mem.cc \
+       tests/stub_MemObject.cc \
+       tests/stub_mime.cc \
+       tests/stub_pconn.cc \
+       tests/stub_stmem.cc \
+       tests/stub_store.cc \
+       tests/stub_store_stats.cc \
+       tests/stub_tools.cc \
+       tests/testMain.cc \
+       tests/testStatHist.cc \
+       tests/testStatHist.h \
+       time.cc
+nodist_tests_testStatHist_SOURCES = \
+       $(TESTSOURCES)
+tests_testStatHist_LDFLAGS = $(LIBADD_DL)
+tests_testStatHist_LDADD = \
+       base/libbase.la \
+       $(top_builddir)/lib/libmiscutil.la \
+       $(SQUID_CPPUNIT_LIBS) \
+       $(SQUID_CPPUNIT_LA) \
+       $(COMPAT_LIB)
+tests_testStatHist_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
+
 
 TESTS += testHeaders
 
index 7a7af382da5650b6f017461cb03488b627466422..696dc8f3778a6521ca2881d2ed511ec8b6c97853 100644 (file)
@@ -40,6 +40,9 @@
 
 #include "cbdata.h"
 
+/* for CacheDigestGuessStats */
+#include "StatCounters.h"
+
 struct _Version {
     short int current;         /* current version */
     short int required;                /* minimal version that can safely handle current version */
@@ -116,7 +119,7 @@ public:
     } times;
 
     struct {
-        cd_guess_stats guess;
+        CacheDigestGuessStats guess;
         int used_count;
 
         struct {
index 945af7e4824f484b2ec24c13de0414df15a4ec47..beffab6a461875de617b311f77316b3607b38758 100644 (file)
@@ -44,6 +44,7 @@
 #include "HttpReply.h"
 #include "errorpage.h"
 #include "err_detail_type.h"
+#include "StatCounters.h"
 #include "SquidTime.h"
 
 #if USE_ADAPTATION
@@ -365,7 +366,7 @@ ServerStateData::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);
+        kb_incr(&(statCounter.server.all.kbytes_out), io.size);
         // kids should increment their counters
     }
 
diff --git a/src/StatCounters.cc b/src/StatCounters.cc
new file mode 100644 (file)
index 0000000..34379fa
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ *  AUTHOR: Francesco Chemolli (Harvest-derived)
+ *
+ */
+
+#include "squid.h"
+#include "StatCounters.h"
+
+StatCounters statCounter;
diff --git a/src/StatCounters.h b/src/StatCounters.h
new file mode 100644 (file)
index 0000000..cfedcad
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * AUTHOR: Francesco Chemolli (Harvest-derived)
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ *
+ */
+#ifndef STATCOUNTERS_H_
+#define STATCOUNTERS_H_
+
+#include "StatHist.h"
+
+#if USE_CACHE_DIGESTS
+/** statistics for cache digests and other hit "predictors" */
+class CacheDigestGuessStats
+{
+public:
+    int trueHits;
+    int falseHits;
+    int trueMisses;
+    int falseMisses;
+    int closeHits;     /// \todo: temporary remove it later
+};
+#endif
+
+
+/** General collection of process-wide statistics.
+ *
+ * \note if you add a field to StatCounters,
+ * you MUST sync statCountersInitSpecial, statCountersClean, and statCountersCopy
+ */
+class StatCounters
+{
+public:
+    struct {
+        int clients;
+        int requests;
+        int hits;
+        int mem_hits;
+        int disk_hits;
+        int errors;
+        kb_t kbytes_in;
+        kb_t kbytes_out;
+        kb_t hit_kbytes_out;
+        StatHist missSvcTime;
+        StatHist nearMissSvcTime;
+        StatHist nearHitSvcTime;
+        StatHist hitSvcTime;
+        StatHist allSvcTime;
+    } client_http;
+
+    struct {
+
+        struct {
+            int requests;
+            int errors;
+            kb_t kbytes_in;
+            kb_t kbytes_out;
+        } all , http, ftp, other;
+    } server;
+
+    struct {
+        int pkts_sent;
+        int queries_sent;
+        int replies_sent;
+        int pkts_recv;
+        int queries_recv;
+        int replies_recv;
+        int hits_sent;
+        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;
+        StatHist querySvcTime;
+        StatHist replySvcTime;
+        int query_timeouts;
+        int times_used;
+    } icp;
+
+    struct {
+        int pkts_sent;
+        int pkts_recv;
+    } htcp;
+
+    struct {
+        int requests;
+    } unlink;
+
+    struct {
+        StatHist svcTime;
+    } dns;
+
+    struct {
+        int times_used;
+        kb_t kbytes_sent;
+        kb_t kbytes_recv;
+        kb_t memory;
+        int msgs_sent;
+        int msgs_recv;
+#if USE_CACHE_DIGESTS
+
+        CacheDigestGuessStats guess;
+#endif
+
+        StatHist on_xition_count;
+    } cd;
+
+    struct {
+        int times_used;
+    } netdb;
+    int page_faults;
+    unsigned long int select_loops;
+    int select_fds;
+    double select_time;
+    double cputime;
+
+    struct timeval timestamp;
+    StatHist comm_icp_incoming;
+    StatHist comm_dns_incoming;
+    StatHist comm_http_incoming;
+    StatHist select_fds_hist;
+
+    struct {
+        struct {
+            int opens;
+            int closes;
+            int reads;
+            int writes;
+            int seeks;
+            int unlinks;
+        } disk;
+
+        struct {
+            int accepts;
+            int sockets;
+            int connects;
+            int binds;
+            int closes;
+            int reads;
+            int writes;
+            int recvfroms;
+            int sendtos;
+        } sock;
+        int selects;
+    } syscalls;
+    int aborted_requests;
+
+    struct {
+        int files_cleaned;
+        int outs;
+        int ins;
+    } swap;
+
+private:
+};
+
+extern StatCounters statCounter;
+
+#endif /* STATCOUNTERS_H_ */
index 6b82e9bfd5e229d2514738f5caec3b83085bd028..9e5d0ddcc1bfe6383a51599c8f1650468f562cf8 100644 (file)
@@ -1,7 +1,5 @@
 
 /*
- * $Id$
- *
  * DEBUG: section 62    Generic Histogram
  * AUTHOR: Duane Wessels
  *
  *
  */
 
-/*
- * Important restrictions on val_in and val_out functions:
- *
- *   - val_in:  ascending, defined on [0, oo), val_in(0) == 0;
- *   - val_out: x == val_out(val_in(x)) where val_in(x) is defined
- *
- *  In practice, the requirements are less strict,
- *  but then it gets hard to define them without math notation.
- *  val_in is applied after offseting the value but before scaling
- *  See log and linear based histograms for examples
- */
-
 #include "squid.h"
-#include "Store.h"
+#include "StatHist.h"
 
 /* Local functions */
-static void statHistInit(StatHist * H, int capacity, hbase_f * val_in, hbase_f * val_out, double min, double max);
-static int statHistBin(const StatHist * H, double v);
-static double statHistVal(const StatHist * H, int bin);
 static StatHistBinDumper statHistBinDumper;
 
 namespace Math
@@ -62,158 +45,114 @@ hbase_f Null;
 };
 
 /* low level init, higher level functions has less params */
-static void
-statHistInit(StatHist * H, int capacity, hbase_f * val_in, hbase_f * val_out, double min, double max)
-{
-    assert(H);
-    assert(capacity > 0);
-    assert(val_in && val_out);
-    /* check before we divide to get scale */
-    assert(val_in(max - min) > 0);
-    H->bins = (int *)xcalloc(capacity, sizeof(int));
-    H->min = min;
-    H->max = max;
-    H->capacity = capacity;
-    H->scale = capacity / val_in(max - min);
-    H->val_in = val_in;
-    H->val_out = val_out;
-
-    /* HPUX users: If you get one of the assertions below, please send
-     * [at least] the values of all variables involved in the assertions
-     * when reporting a bug!
-     */
-
-    /* check that functions are valid */
-    /* a min value should go into bin[0] */
-    assert(statHistBin(H, min) == 0);
-    /* a max value should go into the last bin */
-    assert(statHistBin(H, max) == H->capacity - 1);
-    /* it is hard to test val_out, here is a crude test */
-    assert(((int) floor(0.99 + statHistVal(H, 0) - min)) == 0);
-}
-
 void
-statHistClean(StatHist * H)
+StatHist::init(unsigned int newCapacity, hbase_f * val_in_, hbase_f * val_out_, double newMin, double newMax)
 {
-    xfree(H->bins);
-    H->bins = NULL;
+    /* check before we divide to get scale_ */
+    assert(val_in_(newMax - newMin) > 0);
+    min_ = newMin;
+    max_ = newMax;
+    capacity_ = newCapacity;
+    val_in = val_in_;
+    val_out = val_out_;
+    bins = static_cast<bins_type *>(xcalloc(capacity_, sizeof(bins_type)));
+    scale_ = capacity_ / val_in(max_ - min_);
 }
 
-/* assumes that somebody already called init for Dest */
 void
-statHistCopy(StatHist * Dest, const StatHist * Orig)
+StatHist::clear()
 {
-    assert(Dest);
-    assert(Orig);
-    debugs(62, 3, "statHistCopy: Dest=" << Dest << ", Orig=" << Orig);
-    assert(Dest->bins);
-    /* better be safe than sorry */
-    debugs(62, 3, "statHistCopy: capacity " << Dest->capacity << " " << Orig->capacity);
-    assert(Dest->capacity == Orig->capacity);
-    debugs(62, 3, "statHistCopy: min " << Dest->min << " " << Orig->min  );
-    assert(Dest->min == Orig->min);
-    debugs(62, 3, "statHistCopy: max " << Dest->max << " " << Orig->max  );
-    assert(Dest->max == Orig->max);
-    debugs(62, 3, "statHistCopy: scale " << Dest->scale << " " << Orig->scale  );
-    assert(fabs(Dest->scale - Orig->scale) < 0.0000001);
-    assert(Dest->val_in == Orig->val_in);
-    assert(Dest->val_out == Orig->val_out);
-    /* actual copy */
-    debugs(62, 3, "statHistCopy: copying " <<
-           (long int) (Dest->capacity * sizeof(*Dest->bins)) << " bytes to " <<
-           Dest->bins << " from " << Orig->bins);
-
-    memcpy(Dest->bins, Orig->bins, Dest->capacity * sizeof(*Dest->bins));
+    for (unsigned int i=0; i<capacity_; ++i)
+        bins[i]=0;
 }
 
-/*
- * same as statHistCopy but will do nothing if capacities do not match; the
- * latter happens, for example, when #peers changes during reconfiguration;
- * if it happens too often we should think about more general solution..
- */
-void
-statHistSafeCopy(StatHist * Dest, const StatHist * Orig)
+StatHist::StatHist(const StatHist &src) :
+        capacity_(src.capacity_), min_(src.min_), max_(src.max_),
+        scale_(src.scale_), val_in(src.val_in), val_out(src.val_out)
 {
-    assert(Dest && Orig);
-    assert(Dest->bins);
-
-    if (Dest->capacity == Orig->capacity)
-        statHistCopy(Dest, Orig);
+    if (src.bins!=NULL) {
+        bins = static_cast<bins_type *>(xcalloc(src.capacity_, sizeof(int)));
+        memcpy(bins,src.bins,capacity_*sizeof(*bins));
+    }
 }
 
 void
-statHistCount(StatHist * H, double val)
+StatHist::count(double val)
 {
-    const int bin = statHistBin(H, val);
-    assert(H->bins);           /* make sure it got initialized */
-    assert(0 <= bin && bin < H->capacity);
-    H->bins[bin]++;
+    if (bins==NULL) //do not count before initialization or after destruction
+        return;
+    const unsigned int bin = findBin(val);
+    ++bins[bin];
 }
 
-static int
-statHistBin(const StatHist * H, double v)
+unsigned int
+StatHist::findBin(double v)
 {
-    int bin;
-#if BROKEN_STAT_HIST_BIN
-
-    return 0;
-    /* NOTREACHED */
-#endif
 
-    v -= H->min;               /* offset */
+    v -= min_;         /* offset */
 
     if (v <= 0.0)              /* too small */
         return 0;
 
-    bin = (int) floor(H->scale * H->val_in(v) + 0.5);
+    unsigned int bin;
+    double tmp_bin=floor(scale_ * val_in(v) + 0.5);
 
-    if (bin < 0)               /* should not happen */
-        bin = 0;
+    if (tmp_bin < 0.0) // should not happen
+        return 0;
+    bin = static_cast <unsigned int>(tmp_bin);
 
-    if (bin >= H->capacity)    /* too big */
-        bin = H->capacity - 1;
+    if (bin >= capacity_)      /* too big */
+        bin = capacity_ - 1;
 
     return bin;
 }
 
-static double
-statHistVal(const StatHist * H, int bin)
+double
+StatHist::val(unsigned int bin) const
 {
-    return H->val_out((double) bin / H->scale) + H->min;
+    return val_out((double) bin / scale_) + min_;
 }
 
 double
-statHistDeltaMedian(const StatHist * A, const StatHist * B)
+statHistDeltaMedian(const StatHist & A, const StatHist & B)
 {
     return statHistDeltaPctile(A, B, 0.5);
 }
 
 double
-statHistDeltaPctile(const StatHist * A, const StatHist * B, double pctile)
+statHistDeltaPctile(const StatHist & A, const StatHist & B, double pctile)
+{
+    return A.deltaPctile(B, pctile);
+}
+
+double
+StatHist::deltaPctile(const StatHist & B, double pctile) const
 {
-    int i;
-    int s1 = 0;
-    int h = 0;
-    int a = 0;
-    int b = 0;
-    int I = 0;
-    int J = A->capacity;
-    int K;
+    unsigned int i;
+    bins_type s1 = 0;
+    bins_type h = 0;
+    bins_type a = 0;
+    bins_type b = 0;
+    unsigned int I = 0;
+    unsigned int J = capacity_;
+    unsigned int K;
     double f;
-    int *D = (int *)xcalloc(A->capacity, sizeof(int));
-    assert(A->capacity == B->capacity);
 
-    for (i = 0; i < A->capacity; i++) {
-        D[i] = B->bins[i] - A->bins[i];
+    assert(capacity_ == B.capacity_);
+
+    int *D = static_cast<int *>(xcalloc(capacity_, sizeof(int)));
+
+    for (i = 0; i < capacity_; ++i) {
+        D[i] = B.bins[i] - bins[i];
         assert(D[i] >= 0);
     }
 
-    for (i = 0; i < A->capacity; i++)
+    for (i = 0; i < capacity_; ++i)
         s1 += D[i];
 
     h = int(s1 * pctile);
 
-    for (i = 0; i < A->capacity; i++) {
+    for (i = 0; i < capacity_; ++i) {
         J = i;
         b += D[J];
 
@@ -241,9 +180,9 @@ statHistDeltaPctile(const StatHist * A, const StatHist * B, double pctile)
 
     f = (h - a) / (b - a);
 
-    K = (int) floor(f * (double) (J - I) + I);
+    K = (unsigned int) floor(f * (double) (J - I) + I);
 
-    return statHistVal(A, K);
+    return val(K);
 }
 
 static void
@@ -255,18 +194,17 @@ statHistBinDumper(StoreEntry * sentry, int idx, double val, double size, int cou
 }
 
 void
-statHistDump(const StatHist * H, StoreEntry * sentry, StatHistBinDumper * bd)
+StatHist::dump(StoreEntry * sentry, StatHistBinDumper * bd) const
 {
-    int i;
-    double left_border = H->min;
+    double left_border = min_;
 
     if (!bd)
         bd = statHistBinDumper;
 
-    for (i = 0; i < H->capacity; i++) {
-        const double right_border = statHistVal(H, i + 1);
+    for (unsigned int i = 0; i < capacity_; ++i) {
+        const double right_border = val(i + 1);
         assert(right_border - left_border > 0.0);
-        bd(sentry, i, left_border, right_border - left_border, H->bins[i]);
+        bd(sentry, i, left_border, right_border - left_border, bins[i]);
         left_border = right_border;
     }
 }
@@ -286,9 +224,9 @@ Math::Exp(double x)
 }
 
 void
-statHistLogInit(StatHist * H, int capacity, double min, double max)
+StatHist::logInit(unsigned int capacity, double min, double max)
 {
-    statHistInit(H, capacity, Math::Log, Math::Exp, min, max);
+    init(capacity, Math::Log, Math::Exp, min, max);
 }
 
 /* linear histogram for enums */
@@ -300,9 +238,9 @@ Math::Null(double x)
 }
 
 void
-statHistEnumInit(StatHist * H, int last_enum)
+StatHist::enumInit(unsigned int last_enum)
 {
-    statHistInit(H, last_enum + 3, Math::Null, Math::Null, (double) -1, (double) (last_enum + 1 + 1));
+    init(last_enum + 3, Math::Null, Math::Null, -1.0, (2.0 + last_enum));
 }
 
 void
@@ -313,12 +251,6 @@ statHistEnumDumper(StoreEntry * sentry, int idx, double val, double size, int co
                           idx, (int) val, count);
 }
 
-void
-statHistIntInit(StatHist * H, int n)
-{
-    statHistInit(H, n, Math::Null, Math::Null, (double) 0, (double) n - 1);
-}
-
 void
 statHistIntDumper(StoreEntry * sentry, int idx, double val, double size, int count)
 {
diff --git a/src/StatHist.h b/src/StatHist.h
new file mode 100644 (file)
index 0000000..576525d
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ */
+
+#ifndef STATHIST_H_
+#define STATHIST_H_
+
+/* for StoreEntry */
+#include "Store.h"
+
+
+/// function signature for in/out StatHist adaptation
+typedef double hbase_f(double);
+
+/// function signature for StatHist dumping functions
+typedef void StatHistBinDumper(StoreEntry *, int idx, double val, double size, int count);
+
+/** Generic histogram class
+ *
+ * see important comments on hbase_f restrictions in StatHist.cc
+ */
+class StatHist
+{
+public:
+    /**
+     * \note the default constructor doesn't fully initialize.
+     *       you have to call one of the *init functions to specialize the
+     *       histogram
+     * \todo merge functionality from the *init functions to the constructor and
+     *       drop these
+     * \todo specialize the class in a small hierarchy so that all
+     *       relevant initializations are done at build-time
+     */
+    StatHist();
+    StatHist(const StatHist&); //not needed
+    ~StatHist();
+
+    typedef uint64_t bins_type;
+
+    StatHist &operator=(const StatHist &);
+
+    /** clear the contents of the histograms
+     *
+     * \todo remove: this function has been replaced in its purpose
+     *       by the destructor
+     */
+    void clear();
+
+    /** Calculate the percentile for value pctile for the difference between
+     *  this and the supplied histogram.
+     */
+    double deltaPctile(const StatHist &B, double pctile) const;
+    /** obtain the output-transformed value from the specified bin
+     *
+     */
+    double val(unsigned int bin) const;
+    /** increment the counter for the histogram entry
+     * associated to the supplied value
+     */
+    void count(double val);
+    /** iterate the supplied bd function over the histogram values
+     */
+    void dump(StoreEntry *sentry, StatHistBinDumper * bd) const;
+    /** Initialize the Histogram using a logarithmic values distribution
+     */
+    void logInit(unsigned int capacity, double min, double max);
+    /** initialize the histogram to count occurrences in an enum-represented set
+     */
+    void enumInit(unsigned int last_enum);
+protected:
+    /** low-level initialize function. called by *Init high-level functions
+     * \note Important restrictions on val_in and val_out functions:
+     *
+     *   - val_in:  ascending, defined on [0, oo), val_in(0) == 0;
+     *   - val_out: x == val_out(val_in(x)) where val_in(x) is defined
+     *
+     *  In practice, the requirements are less strict,
+     *  but then it gets hard to define them without math notation.
+     *  val_in is applied after offseting the value but before scaling
+     *  See log and linear based histograms for examples
+     */
+    void init(unsigned int capacity, hbase_f * val_in, hbase_f * val_out, double min, double max);
+    /// find what entry in the histogram corresponds to v, by applying
+    /// the preset input transformation function
+    unsigned int findBin(double v);
+    /// the histogram counters
+    bins_type *bins;
+    unsigned int capacity_;
+    /// minimum value to be stored, corresponding to the first bin
+    double min_;
+    /// value of the maximum counter in the histogram
+    double max_;
+    /// scaling factor when looking for a bin
+    double scale_;
+    hbase_f *val_in;        /* e.g., log() for log-based histogram */
+    hbase_f *val_out;       /* e.g., exp() for log based histogram */
+};
+
+double statHistDeltaMedian(const StatHist & A, const StatHist & B);
+double statHistDeltaPctile(const StatHist & A, const StatHist & B, double pctile);
+StatHistBinDumper statHistEnumDumper;
+StatHistBinDumper statHistIntDumper;
+
+inline StatHist&
+StatHist::operator =(const StatHist & src)
+{
+    if (this==&src) //handle self-assignment
+        return *this;
+    xfree(bins); // xfree can handle NULL pointers, no need to check
+    capacity_=src.capacity_;
+    bins = static_cast<bins_type *>(xcalloc(src.capacity_, sizeof(bins_type)));
+    min_=src.min_;
+    max_=src.max_;
+    scale_=src.scale_;
+    val_in=src.val_in;
+    val_out=src.val_out;
+    memcpy(bins,src.bins,capacity_*sizeof(*bins));
+    return *this;
+}
+
+inline
+StatHist::StatHist() :
+        bins(NULL), capacity_(0), min_(0), max_(0),
+        scale_(1.0), val_in(NULL), val_out(NULL)
+{}
+
+inline
+StatHist::~StatHist()
+{
+    xfree(bins); //can handle case of bins being NULL
+    bins=NULL;
+    capacity_=0; //mark as destructed, may be needed for troubleshooting
+}
+
+#endif /* STATHIST_H_ */
index c549f411690bb7af4e18e727ba6700191e05d6ae..0df881542eb2765a5324574fb0b4bc4ef5e530d6 100644 (file)
@@ -40,6 +40,7 @@
 #include "mgr/Registration.h"
 #include "SquidMath.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "Store.h"
 
 
@@ -92,7 +93,7 @@ clientdbAdd(const Ip::Address &addr)
     c->prevTime=current_dtime;/* put current time to have something sensible here */
 #endif
     hash_join(client_table, &c->hash);
-    statCounter.client_http.clients++;
+    ++statCounter.client_http.clients;
 
     if ((statCounter.client_http.clients > max_clients) && !cleanup_running && cleanup_scheduled < 2) {
         cleanup_scheduled++;
@@ -404,7 +405,7 @@ clientdbGC(void *unused)
 
         clientdbFreeItem(c);
 
-        statCounter.client_http.clients--;
+        --statCounter.client_http.clients;
 
         cleanup_removed++;
     }
index 5870dfa8ede28b0742b5279a272e988f4fda8925..2b9d35adbf2dbc68427c73cdb34e7691c199b486 100644 (file)
 #include "MemObject.h"
 #include "ProtoPort.h"
 #include "rfc1738.h"
+#include "StatCounters.h"
+#include "StatHist.h"
 #include "SquidTime.h"
 #if USE_SSL
 #include "ssl/context_storage.h"
@@ -425,21 +427,21 @@ clientIdentDone(const char *ident, void *data)
 void
 clientUpdateStatCounters(log_type logType)
 {
-    statCounter.client_http.requests++;
+    ++statCounter.client_http.requests;
 
     if (logTypeIsATcpHit(logType))
-        statCounter.client_http.hits++;
+        ++statCounter.client_http.hits;
 
     if (logType == LOG_TCP_HIT)
-        statCounter.client_http.disk_hits++;
+        ++statCounter.client_http.disk_hits;
     else if (logType == LOG_TCP_MEM_HIT)
-        statCounter.client_http.mem_hits++;
+        ++statCounter.client_http.mem_hits;
 }
 
 void
 clientUpdateStatHistCounters(log_type logType, int svc_time)
 {
-    statHistCount(&statCounter.client_http.all_svc_time, svc_time);
+    statCounter.client_http.allSvcTime.count(svc_time);
     /**
      * The idea here is not to be complete, but to get service times
      * for only well-defined types.  For example, we don't include
@@ -450,11 +452,11 @@ clientUpdateStatHistCounters(log_type logType, int svc_time)
     switch (logType) {
 
     case LOG_TCP_REFRESH_UNMODIFIED:
-        statHistCount(&statCounter.client_http.nh_svc_time, svc_time);
+        statCounter.client_http.nearHitSvcTime.count(svc_time);
         break;
 
     case LOG_TCP_IMS_HIT:
-        statHistCount(&statCounter.client_http.nm_svc_time, svc_time);
+        statCounter.client_http.nearMissSvcTime.count(svc_time);
         break;
 
     case LOG_TCP_HIT:
@@ -462,13 +464,13 @@ clientUpdateStatHistCounters(log_type logType, int svc_time)
     case LOG_TCP_MEM_HIT:
 
     case LOG_TCP_OFFLINE_HIT:
-        statHistCount(&statCounter.client_http.hit_svc_time, svc_time);
+        statCounter.client_http.hitSvcTime.count(svc_time);
         break;
 
     case LOG_TCP_MISS:
 
     case LOG_TCP_CLIENT_REFRESH_MISS:
-        statHistCount(&statCounter.client_http.miss_svc_time, svc_time);
+        statCounter.client_http.missSvcTime.count(svc_time);
         break;
 
     default:
@@ -512,8 +514,7 @@ clientUpdateHierCounters(HierarchyLogEntry * someEntry)
         i = &someEntry->ping;
 
         if (clientPingHasFinished(i))
-            statHistCount(&statCounter.icp.query_svc_time,
-                          tvSubUsec(i->start, i->stop));
+            statCounter.icp.querySvcTime.count(tvSubUsec(i->start, i->stop));
 
         if (i->timeout)
             statCounter.icp.query_timeouts++;
@@ -2832,7 +2833,7 @@ ConnStateData::clientReadRequest(const CommIoCbParams &io)
 
     if (io.flag == COMM_OK) {
         if (io.size > 0) {
-            kb_incr(&statCounter.client_http.kbytes_in, io.size);
+            kb_incr(&(statCounter.client_http.kbytes_in), io.size);
 
             // may comm_close or setReplyToError
             if (!handleReadData(io.buf, io.size))
index 0fde2694bbde305051c3792220306fd514f64edb..e39f66b1a847aea161b47a23012f67fc0b1e550f 100644 (file)
@@ -57,6 +57,7 @@
 #include "ip/QosConfig.h"
 #include "ip/tools.h"
 #include "ClientInfo.h"
+#include "StatCounters.h"
 #if USE_SSL
 #include "ssl/support.h"
 #endif
index 9fb29d62d572fba109c096e567e2fa10d932d0dd..525587f719bfe9088bc2243bda3a0319a79e27f7 100644 (file)
@@ -59,6 +59,8 @@
 #include "fde.h"
 #include "mgr/Registration.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
+#include "StatHist.h"
 #include "Store.h"
 
 #if HAVE_SYS_DEVPOLL_H
@@ -172,10 +174,9 @@ comm_update_fd(int fd, int events)
 
 static void commIncomingStats(StoreEntry *sentry)
 {
-    StatCounters *f = &statCounter;
     storeAppendPrintf(sentry, "Total number of devpoll loops: %ld\n", statCounter.select_loops);
     storeAppendPrintf(sentry, "Histogram of returned filedescriptors\n");
-    statHistDump(&f->select_fds_hist, sentry, statHistIntDumper);
+    statCounter.select_fds_hist.dump(sentry, statHistIntDumper);
 }
 
 
@@ -377,7 +378,7 @@ Comm::DoSelect(int msec)
     PROF_stop(comm_check_incoming);
     getCurrentTime();
 
-    statHistCount(&statCounter.select_fds_hist, num);
+    statCounter.select_fds_hist.count(num);
 
     if (num == 0)
         return COMM_TIMEOUT; /* no error */
index 22f134db940a05bd4d846a15b943a3afca15013c..9a8f986905a2d78c69d20e899fc72275e6d87440 100644 (file)
@@ -60,6 +60,8 @@
 #include "fde.h"
 #include "mgr/Registration.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
+#include "StatHist.h"
 #include "Store.h"
 
 #define DEBUG_EPOLL 0
@@ -227,7 +229,7 @@ commIncomingStats(StoreEntry * sentry)
     StatCounters *f = &statCounter;
     storeAppendPrintf(sentry, "Total number of epoll(2) loops: %ld\n", statCounter.select_loops);
     storeAppendPrintf(sentry, "Histogram of returned filedescriptors\n");
-    statHistDump(&f->select_fds_hist, sentry, statHistIntDumper);
+    f->select_fds_hist.dump(sentry, statHistIntDumper);
 }
 
 /**
@@ -274,7 +276,7 @@ Comm::DoSelect(int msec)
     PROF_stop(comm_check_incoming);
     getCurrentTime();
 
-    statHistCount(&statCounter.select_fds_hist, num);
+    statCounter.select_fds_hist.count(num);
 
     if (num == 0)
         return COMM_TIMEOUT;           /* No error.. */
index 95f585390cf3b8ce032a17ac41cdaf7df7283d28..2ee0ab388ff27ae7f90cb274cc5f2a153a2a5737 100644 (file)
@@ -41,6 +41,7 @@
 #include "ICP.h"
 #include "mgr/Registration.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "Store.h"
 
 #if HAVE_POLL_H
@@ -305,7 +306,7 @@ comm_poll_icp_incoming(void)
     if (nevents > INCOMING_ICP_MAX)
         nevents = INCOMING_ICP_MAX;
 
-    statHistCount(&statCounter.comm_icp_incoming, nevents);
+    statCounter.comm_icp_incoming.count(nevents);
 }
 
 static void
@@ -339,7 +340,7 @@ comm_poll_http_incoming(void)
     if (nevents > INCOMING_HTTP_MAX)
         nevents = INCOMING_HTTP_MAX;
 
-    statHistCount(&statCounter.comm_http_incoming, nevents);
+    statCounter.comm_http_incoming.count(nevents);
 }
 
 /* poll all sockets; call handlers for those that are ready. */
@@ -449,7 +450,7 @@ Comm::DoSelect(int msec)
         getCurrentTime();
 
         debugs(5, num ? 5 : 8, "comm_poll: " << num << "+" << npending << " FDs ready");
-        statHistCount(&statCounter.select_fds_hist, num);
+        statCounter.select_fds_hist.count(num);
 
         if (num == 0 && npending == 0)
             continue;
@@ -620,7 +621,7 @@ comm_poll_dns_incoming(void)
     if (nevents > INCOMING_DNS_MAX)
         nevents = INCOMING_DNS_MAX;
 
-    statHistCount(&statCounter.comm_dns_incoming, nevents);
+    statCounter.comm_dns_incoming.count(nevents);
 }
 
 
@@ -641,7 +642,6 @@ Comm::SelectLoopInit(void)
 static void
 commIncomingStats(StoreEntry * sentry)
 {
-    StatCounters *f = &statCounter;
     storeAppendPrintf(sentry, "Current incoming_icp_interval: %d\n",
                       incoming_icp_interval >> INCOMING_FACTOR);
     storeAppendPrintf(sentry, "Current incoming_dns_interval: %d\n",
@@ -651,11 +651,11 @@ commIncomingStats(StoreEntry * sentry)
     storeAppendPrintf(sentry, "\n");
     storeAppendPrintf(sentry, "Histogram of events per incoming socket type\n");
     storeAppendPrintf(sentry, "ICP Messages handled per comm_poll_icp_incoming() call:\n");
-    statHistDump(&f->comm_icp_incoming, sentry, statHistIntDumper);
+    statCounter.comm_icp_incoming.dump(sentry, statHistIntDumper);
     storeAppendPrintf(sentry, "DNS Messages handled per comm_poll_dns_incoming() call:\n");
-    statHistDump(&f->comm_dns_incoming, sentry, statHistIntDumper);
+    statCounter.comm_dns_incoming.dump(sentry, statHistIntDumper);
     storeAppendPrintf(sentry, "HTTP Messages handled per comm_poll_http_incoming() call:\n");
-    statHistDump(&f->comm_http_incoming, sentry, statHistIntDumper);
+    statCounter.comm_http_incoming.dump(sentry, statHistIntDumper);
 }
 
 /* Called by async-io or diskd to speed up the polling */
index bcc62cb13224dd1faf46168a51aa9887d32fdb4c..c882569be760a10e571aed119bb3322b5eb1daf9 100644 (file)
@@ -40,6 +40,8 @@
 #include "ICP.h"
 #include "mgr/Registration.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
+#include "StatHist.h"
 #include "Store.h"
 #include "fde.h"
 
@@ -299,7 +301,7 @@ comm_select_icp_incoming(void)
     if (nevents > INCOMING_ICP_MAX)
         nevents = INCOMING_ICP_MAX;
 
-    statHistCount(&statCounter.comm_icp_incoming, nevents);
+    statCounter.comm_icp_incoming.count(nevents);
 }
 
 static void
@@ -330,7 +332,7 @@ comm_select_http_incoming(void)
     if (nevents > INCOMING_HTTP_MAX)
         nevents = INCOMING_HTTP_MAX;
 
-    statHistCount(&statCounter.comm_http_incoming, nevents);
+    statCounter.comm_http_incoming.count(nevents);
 }
 
 #define DEBUG_FDBITS 0
@@ -470,7 +472,7 @@ Comm::DoSelect(int msec)
 
         debugs(5, num ? 5 : 8, "comm_select: " << num << "+" << pending << " FDs ready");
 
-        statHistCount(&statCounter.select_fds_hist, num);
+        statCounter.select_fds_hist.count(num);
 
         if (num == 0 && pending == 0)
             continue;
@@ -660,7 +662,7 @@ comm_select_dns_incoming(void)
     if (nevents > INCOMING_DNS_MAX)
         nevents = INCOMING_DNS_MAX;
 
-    statHistCount(&statCounter.comm_dns_incoming, nevents);
+    statCounter.comm_dns_incoming.count(nevents);
 }
 
 void
@@ -752,7 +754,6 @@ examine_select(fd_set * readfds, fd_set * writefds)
 static void
 commIncomingStats(StoreEntry * sentry)
 {
-    StatCounters *f = &statCounter;
     storeAppendPrintf(sentry, "Current incoming_icp_interval: %d\n",
                       incoming_icp_interval >> INCOMING_FACTOR);
     storeAppendPrintf(sentry, "Current incoming_dns_interval: %d\n",
@@ -762,11 +763,11 @@ commIncomingStats(StoreEntry * sentry)
     storeAppendPrintf(sentry, "\n");
     storeAppendPrintf(sentry, "Histogram of events per incoming socket type\n");
     storeAppendPrintf(sentry, "ICP Messages handled per comm_select_icp_incoming() call:\n");
-    statHistDump(&f->comm_icp_incoming, sentry, statHistIntDumper);
+    statCounter.comm_icp_incoming.dump(sentry, statHistIntDumper);
     storeAppendPrintf(sentry, "DNS Messages handled per comm_select_dns_incoming() call:\n");
-    statHistDump(&f->comm_dns_incoming, sentry, statHistIntDumper);
+    statCounter.comm_dns_incoming.dump(sentry, statHistIntDumper);
     storeAppendPrintf(sentry, "HTTP Messages handled per comm_select_http_incoming() call:\n");
-    statHistDump(&f->comm_http_incoming, sentry, statHistIntDumper);
+    statCounter.comm_http_incoming.dump(sentry, statHistIntDumper);
 }
 
 void
index 27e80a9708941e467f48c4c9031110785a0bd1bf..5eb36a2af403691c2a2874efc001f7f2937f75f4 100644 (file)
@@ -40,6 +40,8 @@
 #include "fde.h"
 #include "mgr/Registration.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
+#include "StatHist.h"
 #include "Store.h"
 
 static int MAX_POLL_TIME = 1000;       /* see also Comm::QuickPollRequired() */
@@ -302,7 +304,7 @@ comm_select_icp_incoming(void)
     if (nevents > INCOMING_ICP_MAX)
         nevents = INCOMING_ICP_MAX;
 
-    statHistCount(&statCounter.comm_icp_incoming, nevents);
+    statCounter.comm_icp_incoming.count(nevents);
 }
 
 static void
@@ -333,7 +335,7 @@ comm_select_http_incoming(void)
     if (nevents > INCOMING_HTTP_MAX)
         nevents = INCOMING_HTTP_MAX;
 
-    statHistCount(&statCounter.comm_http_incoming, nevents);
+    statCounter.comm_http_incoming.count(nevents);
 }
 
 #define DEBUG_FDBITS 0
@@ -470,7 +472,7 @@ Comm::DoSelect(int msec)
 
         debugs(5, num ? 5 : 8, "comm_select: " << num << "+" << pending << " FDs ready");
 
-        statHistCount(&statCounter.select_fds_hist, num);
+        statCounter.select_fds_hist.count(num);
 
         if (num == 0 && pending == 0)
             continue;
@@ -682,7 +684,7 @@ comm_select_dns_incoming(void)
     if (nevents > INCOMING_DNS_MAX)
         nevents = INCOMING_DNS_MAX;
 
-    statHistCount(&statCounter.comm_dns_incoming, nevents);
+    statCounter.comm_dns_incoming.count(nevents);
 }
 
 void
@@ -774,7 +776,6 @@ examine_select(fd_set * readfds, fd_set * writefds)
 static void
 commIncomingStats(StoreEntry * sentry)
 {
-    StatCounters *f = &statCounter;
     storeAppendPrintf(sentry, "Current incoming_icp_interval: %d\n",
                       incoming_icp_interval >> INCOMING_FACTOR);
     storeAppendPrintf(sentry, "Current incoming_dns_interval: %d\n",
@@ -784,11 +785,11 @@ commIncomingStats(StoreEntry * sentry)
     storeAppendPrintf(sentry, "\n");
     storeAppendPrintf(sentry, "Histogram of events per incoming socket type\n");
     storeAppendPrintf(sentry, "ICP Messages handled per comm_select_icp_incoming() call:\n");
-    statHistDump(&f->comm_icp_incoming, sentry, statHistIntDumper);
+    statCounter.comm_icp_incoming.dump(sentry, statHistIntDumper);
     storeAppendPrintf(sentry, "DNS Messages handled per comm_select_dns_incoming() call:\n");
-    statHistDump(&f->comm_dns_incoming, sentry, statHistIntDumper);
+    statCounter.comm_dns_incoming.dump(sentry, statHistIntDumper);
     storeAppendPrintf(sentry, "HTTP Messages handled per comm_select_http_incoming() call:\n");
-    statHistDump(&f->comm_http_incoming, sentry, statHistIntDumper);
+    statCounter.comm_http_incoming.dump(sentry, statHistIntDumper);
 }
 
 void
index e6791fbb19195608ba5323675a6299e600b16d61..f8ceeedb6992a7839eba89da2e4b254d1f9e656e 100644 (file)
@@ -44,6 +44,7 @@
 #include "ip/Intercept.h"
 #include "protos.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 
 namespace Comm
 {
@@ -296,7 +297,7 @@ comm_err_t
 Comm::TcpAcceptor::oldAccept(Comm::ConnectionPointer &details)
 {
     PROF_start(comm_accept);
-    statCounter.syscalls.sock.accepts++;
+    ++statCounter.syscalls.sock.accepts;
     int sock;
     struct addrinfo *gai = NULL;
     details->local.InitAddrInfo(gai);
index ec656fb7c0ba879a82d7c78e24f7cc97f593c9ba..641e7bda8fa41e75addefc31ea841c18e4cf2501 100644 (file)
@@ -6,6 +6,7 @@
 #include "comm/IoCallback.h"
 #include "comm/Write.h"
 #include "fde.h"
+#include "StatCounters.h"
 #include "SquidTime.h"
 #include "MemBuf.h"
 
@@ -108,7 +109,7 @@ Comm::HandleWrite(int fd, void *data)
 #endif /* USE_DELAY_POOLS */
 
     fd_bytes(fd, len, FD_WRITE);
-    statCounter.syscalls.sock.writes++;
+    ++statCounter.syscalls.sock.writes;
     // After each successful partial write,
     // reset fde::writeStart to the current time.
     fd_table[fd].writeStart = squid_curtime;
index 9dad9c5778c3a55d2aea162d7c0bcc68401a4ba6..92724c54a6dfa0ada86d0616811302b738fc9b6c 100644 (file)
@@ -36,6 +36,7 @@
 #include "comm/Loops.h"
 #include "fde.h"
 #include "MemBuf.h"
+#include "StatCounters.h"
 
 static PF diskHandleRead;
 static PF diskHandleWrite;
@@ -442,7 +443,7 @@ diskHandleRead(int fd, void *data)
 #endif
         debugs(6, 3, "diskHandleRead: FD " << fd << " seeking to offset " << ctrl_dat->offset);
         lseek(fd, ctrl_dat->offset, SEEK_SET); /* XXX ignore return? */
-        statCounter.syscalls.disk.seeks++;
+        ++statCounter.syscalls.disk.seeks;
         F->disk.offset = ctrl_dat->offset;
     }
 
index 22c02fb32275a4fa30497f99ff651d4a87332f4b..ad1a5f60b74fe54beb38e8202d3b9b3dc41a9d81 100644 (file)
@@ -39,6 +39,7 @@
 #include "mgr/Registration.h"
 #include "SquidDns.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "Store.h"
 #include "wordlist.h"
 
@@ -502,7 +503,7 @@ fqdncacheHandleReply(void *data, rfc1035_rr * answers, int na, const char *error
     static_cast<generic_cbdata *>(data)->unwrap(&f);
     ++FqdncacheStats.replies;
     const int age = f->age();
-    statHistCount(&statCounter.dns.svc_time, age);
+    statCounter.dns.svcTime.count(age);
 #if USE_DNSHELPER
 
     fqdncacheParse(f, reply);
index 0341b4bbbb1c674703dfbe7acd6cc488e6103f6d..4e950a940791eb52aab85db0caf890fc27ad2d83 100644 (file)
@@ -45,6 +45,7 @@
 #include "Parsing.h"
 #include "SquidMath.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "SwapDir.h"
 #include "swap_log_op.h"
 
@@ -1146,7 +1147,7 @@ UFSSwapDir::DirClean(int swap_index)
         debugs(36, 3, "storeDirClean: Cleaning file "<< std::setfill('0') << std::hex << std::uppercase << std::setw(8) << files[n]);
         snprintf(p2, MAXPATHLEN + 1, "%s/%08X", p1, files[n]);
         safeunlink(p2, 0);
-        statCounter.swap.files_cleaned++;
+        ++statCounter.swap.files_cleaned;
     }
 
     debugs(36, 3, "Cleaned " << k << " unused files from " << p1);
index e92ebd631efa9ecc1034f868b793a899f6c22925..8dd4d6c114b14bd3f73c61a6ad1f892d7cde5871 100644 (file)
@@ -54,6 +54,7 @@
 #include "Server.h"
 #include "SquidString.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "Store.h"
 #include "URLScheme.h"
 #include "wordlist.h"
@@ -1257,8 +1258,8 @@ FtpStateData::dataRead(const CommIoCbParams &io)
     debugs(9, 3, HERE << "ftpDataRead: 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);
+        kb_incr(&(statCounter.server.all.kbytes_in), io.size);
+        kb_incr(&(statCounter.server.ftp.kbytes_in), io.size);
     }
 
     if (io.flag == COMM_ERR_CLOSING)
@@ -1613,8 +1614,8 @@ FtpStateData::ftpWriteCommandCallback(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);
+        kb_incr(&(statCounter.server.all.kbytes_out), io.size);
+        kb_incr(&(statCounter.server.ftp.kbytes_out), io.size);
     }
 
     if (io.flag == COMM_ERR_CLOSING)
@@ -1754,8 +1755,8 @@ void FtpStateData::ftpReadControlReply(const CommIoCbParams &io)
     debugs(9, 3, "ftpReadControlReply: 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);
+        kb_incr(&(statCounter.server.all.kbytes_in), io.size);
+        kb_incr(&(statCounter.server.ftp.kbytes_in), io.size);
     }
 
     if (io.flag == COMM_ERR_CLOSING)
@@ -3319,7 +3320,7 @@ void
 FtpStateData::sentRequestBody(const CommIoCbParams &io)
 {
     if (io.size > 0)
-        kb_incr(&statCounter.server.ftp.kbytes_out, io.size);
+        kb_incr(&(statCounter.server.ftp.kbytes_out), io.size);
     ServerStateData::sentRequestBody(io);
 }
 
index c20e713b5e0b2decd9dd7c35e13e9e349a15de0a..4165e0090cebbdb9083a440fdb3d2ee6b0c157b6 100644 (file)
@@ -41,7 +41,7 @@
 /* for ERROR_BUF_SZ, BUFSIZ, MAXHTTPPORTS */
 #include "defines.h"
 
-/* for iostats, StatCounters */
+/* for iostats */
 #include "structs.h"
 
 
@@ -109,7 +109,6 @@ extern "C" {
     extern int shutting_down;  /* 0 */
     extern int reconfiguring;  /* 0 */
     extern time_t hit_only_mode_until; /* 0 */
-    extern StatCounters statCounter;
     extern double request_failure_ratio;       /* 0.0 */
     extern int store_hash_buckets;     /* 0 */
     extern hash_table *store_table;    /* NULL */
index 3e83bb010f884371420ee582c28f8fa17d6e3ba4..e560f04e68aee345e37dfd70bb8e9eb0e368a2b7 100644 (file)
@@ -48,6 +48,7 @@
 #include "MemBuf.h"
 #include "forward.h"
 #include "rfc1738.h"
+#include "StatCounters.h"
 #include "SquidTime.h"
 
 /**
@@ -769,8 +770,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);
+        kb_incr(&(statCounter.server.all.kbytes_in), len);
+        kb_incr(&(statCounter.server.other.kbytes_in), len);
     }
 
     debugs(10, 5, HERE << conn << " read len=" << len);
@@ -844,8 +845,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);
+        kb_incr(&(statCounter.server.all.kbytes_out), size);
+        kb_incr(&(statCounter.server.other.kbytes_out), size);
     }
 
     if (errflag) {
index 87861f887e2654f5726aaa90e846c3d9839047f6..b243ee55e50bb4e8168bac31eb2a0b1eb1a4f97e 100644 (file)
@@ -47,6 +47,7 @@
 #include "ip/tools.h"
 #include "MemBuf.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "Store.h"
 #include "StoreClient.h"
 #include "compat/xalloc.h"
index 95b7fed3549cc238bd41477bdb856c01625fe15d..63f78bac35fc5e354348fd9c604f29a8259f55cf 100644 (file)
@@ -68,6 +68,7 @@
 #include "protos.h"
 #include "rfc1738.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "Store.h"
 
 
@@ -1095,8 +1096,8 @@ HttpStateData::readReply(const CommIoCbParams &io)
         delayId.bytesIn(len);
 #endif
 
-        kb_incr(&statCounter.server.all.kbytes_in, len);
-        kb_incr(&statCounter.server.http.kbytes_in, len);
+        kb_incr(&(statCounter.server.all.kbytes_in), len);
+        kb_incr(&(statCounter.server.http.kbytes_in), len);
         IOStats.Http.reads++;
 
         for (clen = len - 1, bin = 0; clen; bin++)
@@ -1451,8 +1452,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);
+        kb_incr(&(statCounter.server.all.kbytes_out), io.size);
+        kb_incr(&(statCounter.server.http.kbytes_out), io.size);
     }
 
     if (io.flag == COMM_ERR_CLOSING)
index e0aa6b809195a934f2232b575704c3b43f2bec01..436f36df848827280976acc8f6bce2363dafbd0e 100644 (file)
@@ -46,6 +46,7 @@
 #include "acl/Acl.h"
 #include "AccessLogEntry.h"
 #include "wordlist.h"
+#include "StatCounters.h"
 #include "SquidTime.h"
 #include "SwapDir.h"
 #include "icmp/net_db.h"
@@ -810,7 +811,7 @@ icpCount(void *buf, int which, size_t len, int delay)
             statCounter.icp.replies_sent++;
             kb_incr(&statCounter.icp.r_kbytes_sent, len);
             /* this is the sent-reply service time */
-            statHistCount(&statCounter.icp.reply_svc_time, delay);
+            statCounter.icp.replySvcTime.count(delay);
         }
 
         if (ICP_HIT == icp->opcode)
@@ -825,7 +826,7 @@ icpCount(void *buf, int which, size_t len, int delay)
         } else {
             statCounter.icp.replies_recv++;
             kb_incr(&statCounter.icp.r_kbytes_recv, len);
-            /* statCounter.icp.query_svc_time set in clientUpdateCounters */
+            /* statCounter.icp.querySvcTime set in clientUpdateCounters */
         }
 
         if (ICP_HIT == icp->opcode)
index 727b2b4b0606ce7e9fd894eed72958e8b5ab7a48..19b0f31a4e2de7992444243caaabdbcba331767f 100644 (file)
@@ -41,6 +41,7 @@
 #include "mgr/Registration.h"
 #include "SquidDns.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "Store.h"
 #include "wordlist.h"
 
@@ -598,7 +599,7 @@ ipcacheHandleReply(void *data, rfc1035_rr * answers, int na, const char *error_m
     static_cast<generic_cbdata *>(data)->unwrap(&i);
     IpcacheStats.replies++;
     const int age = i->age();
-    statHistCount(&statCounter.dns.svc_time, age);
+    statCounter.dns.svcTime.count(age);
 
 #if USE_DNSHELPER
     ipcacheParse(i, reply);
index 6b12880f4ec935c08797db636ce5928caf4f2dd1..8c9a850b9720e4b3cd3765df6d17e145a72de582 100644 (file)
@@ -83,6 +83,7 @@
 #include "ipc/Strand.h"
 #include "ip/tools.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "SwapDir.h"
 #include "forward.h"
 #include "MemPool.h"
index 23af5517b433a2888dd9c7aa20613d3b97751eab..f8227bbb5f94cf28e223599f37aee0fb71bffeaf 100644 (file)
@@ -200,6 +200,8 @@ SQUIDCEXTERN const char *httpMakeVaryMark(HttpRequest * request, HttpReply const
 #include "HttpStatusCode.h"
 SQUIDCEXTERN const char *httpStatusString(http_status status);
 
+class StatHist;
+
 /* Http Cache Control Header Field */
 SQUIDCEXTERN void httpHdrCcInitModule(void);
 SQUIDCEXTERN void httpHdrCcCleanModule(void);
@@ -374,21 +376,6 @@ SQUIDCEXTERN double statRequestHitMemoryRatio(int minutes);
 SQUIDCEXTERN double statRequestHitDiskRatio(int minutes);
 SQUIDCEXTERN double statByteHitRatio(int minutes);
 
-/* StatHist */
-SQUIDCEXTERN void statHistClean(StatHist * H);
-SQUIDCEXTERN void statHistCount(StatHist * H, double val);
-SQUIDCEXTERN void statHistCopy(StatHist * Dest, const StatHist * Orig);
-SQUIDCEXTERN void statHistSafeCopy(StatHist * Dest, const StatHist * Orig);
-SQUIDCEXTERN double statHistDeltaMedian(const StatHist * A, const StatHist * B);
-SQUIDCEXTERN double statHistDeltaPctile(const StatHist * A, const StatHist * B, double pctile);
-SQUIDCEXTERN void statHistDump(const StatHist * H, StoreEntry * sentry, StatHistBinDumper * bd);
-SQUIDCEXTERN void statHistLogInit(StatHist * H, int capacity, double min, double max);
-SQUIDCEXTERN void statHistEnumInit(StatHist * H, int last_enum);
-SQUIDCEXTERN void statHistIntInit(StatHist * H, int n);
-SQUIDCEXTERN StatHistBinDumper statHistEnumDumper;
-SQUIDCEXTERN StatHistBinDumper statHistIntDumper;
-
-
 /* mem */
 SQUIDCEXTERN void memClean(void);
 SQUIDCEXTERN void memInitModule(void);
@@ -612,7 +599,7 @@ SQUIDCEXTERN pid_t ipcCreate(int type,
                              int *wfd,
                              void **hIpc);
 
-
+class CacheDigestGuessStats;
 /* CacheDigest */
 SQUIDCEXTERN CacheDigest *cacheDigestCreate(int capacity, int bpe);
 SQUIDCEXTERN void cacheDigestDestroy(CacheDigest * cd);
@@ -624,8 +611,8 @@ SQUIDCEXTERN void cacheDigestAdd(CacheDigest * cd, const cache_key * key);
 SQUIDCEXTERN void cacheDigestDel(CacheDigest * cd, const cache_key * key);
 SQUIDCEXTERN size_t cacheDigestCalcMaskSize(int cap, int bpe);
 SQUIDCEXTERN int cacheDigestBitUtil(const CacheDigest * cd);
-SQUIDCEXTERN void cacheDigestGuessStatsUpdate(cd_guess_stats * stats, int real_hit, int guess_hit);
-SQUIDCEXTERN void cacheDigestGuessStatsReport(const cd_guess_stats * stats, StoreEntry * sentry, const char *label);
+SQUIDCEXTERN void cacheDigestGuessStatsUpdate(CacheDigestGuessStats * stats, int real_hit, int guess_hit);
+SQUIDCEXTERN void cacheDigestGuessStatsReport(const CacheDigestGuessStats * stats, StoreEntry * sentry, const char *label);
 SQUIDCEXTERN void cacheDigestReport(CacheDigest * cd, const char *label, StoreEntry * e);
 
 SQUIDCEXTERN void internalStart(const Comm::ConnectionPointer &clientConn, HttpRequest *, StoreEntry *);
@@ -669,87 +656,88 @@ SQUIDCEXTERN int gethostname(char *, int);
 /*
  * hack to allow snmp access to the statistics counters
  */
-SQUIDCEXTERN StatCounters *snmpStatGet(int);
+class StatCounters;
+        SQUIDCEXTERN StatCounters *snmpStatGet(int);
 
-/* Vary support functions */
-SQUIDCEXTERN int varyEvaluateMatch(StoreEntry * entry, HttpRequest * req);
+        /* Vary support functions */
+        SQUIDCEXTERN int varyEvaluateMatch(StoreEntry * entry, HttpRequest * req);
 
-/* CygWin & Windows NT Port */
-/* win32.c */
+        /* CygWin & Windows NT Port */
+        /* win32.c */
 #if _SQUID_WINDOWS_
-SQUIDCEXTERN int WIN32_Subsystem_Init(int *, char ***);
-SQUIDCEXTERN void WIN32_sendSignal(int);
-SQUIDCEXTERN void WIN32_Abort(int);
-SQUIDCEXTERN void WIN32_Exit(void);
-SQUIDCEXTERN void WIN32_SetServiceCommandLine(void);
-SQUIDCEXTERN void WIN32_InstallService(void);
-SQUIDCEXTERN void WIN32_RemoveService(void);
-SQUIDCEXTERN int SquidMain(int, char **);
+        SQUIDCEXTERN int WIN32_Subsystem_Init(int *, char ***);
+        SQUIDCEXTERN void WIN32_sendSignal(int);
+        SQUIDCEXTERN void WIN32_Abort(int);
+        SQUIDCEXTERN void WIN32_Exit(void);
+        SQUIDCEXTERN void WIN32_SetServiceCommandLine(void);
+        SQUIDCEXTERN void WIN32_InstallService(void);
+        SQUIDCEXTERN void WIN32_RemoveService(void);
+        SQUIDCEXTERN int SquidMain(int, char **);
 #endif /* _SQUID_WINDOWS_ */
 #if _SQUID_MSWIN_
 
-SQUIDCEXTERN int WIN32_pipe(int[2]);
+        SQUIDCEXTERN int WIN32_pipe(int[2]);
 
-SQUIDCEXTERN int WIN32_getrusage(int, struct rusage *);
-SQUIDCEXTERN void WIN32_ExceptionHandlerInit(void);
+            SQUIDCEXTERN int WIN32_getrusage(int, struct rusage *);
+    SQUIDCEXTERN void WIN32_ExceptionHandlerInit(void);
 
-SQUIDCEXTERN int Win32__WSAFDIsSet(int fd, fd_set* set);
-SQUIDCEXTERN DWORD WIN32_IpAddrChangeMonitorInit();
+    SQUIDCEXTERN int Win32__WSAFDIsSet(int fd, fd_set* set);
+    SQUIDCEXTERN DWORD WIN32_IpAddrChangeMonitorInit();
 
 #endif
 
-/* external_acl.c */
-class external_acl;
-        SQUIDCEXTERN void parse_externalAclHelper(external_acl **);
+    /* external_acl.c */
+    class external_acl;
+            SQUIDCEXTERN void parse_externalAclHelper(external_acl **);
 
-        SQUIDCEXTERN void dump_externalAclHelper(StoreEntry * sentry, const char *name, const external_acl *);
+            SQUIDCEXTERN void dump_externalAclHelper(StoreEntry * sentry, const char *name, const external_acl *);
 
-        SQUIDCEXTERN void free_externalAclHelper(external_acl **);
+            SQUIDCEXTERN void free_externalAclHelper(external_acl **);
 
-        typedef void EAH(void *data, void *result);
-        class ACLChecklist;
-            SQUIDCEXTERN void externalAclLookup(ACLChecklist * ch, void *acl_data, EAH * handler, void *data);
+            typedef void EAH(void *data, void *result);
+            class ACLChecklist;
+                SQUIDCEXTERN void externalAclLookup(ACLChecklist * ch, void *acl_data, EAH * handler, void *data);
 
-            SQUIDCEXTERN void externalAclInit(void);
+                SQUIDCEXTERN void externalAclInit(void);
 
-            SQUIDCEXTERN void externalAclShutdown(void);
+                SQUIDCEXTERN void externalAclShutdown(void);
 
-            SQUIDCEXTERN char *strtokFile(void);
+                SQUIDCEXTERN char *strtokFile(void);
 
 #if USE_WCCPv2
 
-            SQUIDCEXTERN void parse_wccp2_method(int *v);
-            SQUIDCEXTERN void free_wccp2_method(int *v);
-            SQUIDCEXTERN void dump_wccp2_method(StoreEntry * e, const char *label, int v);
-            SQUIDCEXTERN void parse_wccp2_amethod(int *v);
-            SQUIDCEXTERN void free_wccp2_amethod(int *v);
-            SQUIDCEXTERN void dump_wccp2_amethod(StoreEntry * e, const char *label, int v);
+                SQUIDCEXTERN void parse_wccp2_method(int *v);
+                SQUIDCEXTERN void free_wccp2_method(int *v);
+                SQUIDCEXTERN void dump_wccp2_method(StoreEntry * e, const char *label, int v);
+                SQUIDCEXTERN void parse_wccp2_amethod(int *v);
+                SQUIDCEXTERN void free_wccp2_amethod(int *v);
+                SQUIDCEXTERN void dump_wccp2_amethod(StoreEntry * e, const char *label, int v);
 
-            SQUIDCEXTERN void parse_wccp2_service(void *v);
-            SQUIDCEXTERN void free_wccp2_service(void *v);
-            SQUIDCEXTERN void dump_wccp2_service(StoreEntry * e, const char *label, void *v);
+                SQUIDCEXTERN void parse_wccp2_service(void *v);
+                SQUIDCEXTERN void free_wccp2_service(void *v);
+                SQUIDCEXTERN void dump_wccp2_service(StoreEntry * e, const char *label, void *v);
 
-            SQUIDCEXTERN int check_null_wccp2_service(void *v);
+                SQUIDCEXTERN int check_null_wccp2_service(void *v);
 
-            SQUIDCEXTERN void parse_wccp2_service_info(void *v);
+                SQUIDCEXTERN void parse_wccp2_service_info(void *v);
 
-            SQUIDCEXTERN void free_wccp2_service_info(void *v);
+                SQUIDCEXTERN void free_wccp2_service_info(void *v);
 
-            SQUIDCEXTERN void dump_wccp2_service_info(StoreEntry * e, const char *label, void *v);
+                SQUIDCEXTERN void dump_wccp2_service_info(StoreEntry * e, const char *label, void *v);
 
 #endif
 
 #if USE_AUTH
 
 #if HAVE_AUTH_MODULE_NEGOTIATE && HAVE_KRB5 && HAVE_GSSAPI
-            /* upstream proxy authentication */
-            SQUIDCEXTERN char *peer_proxy_negotiate_auth(char *principal_name, char *proxy);
+                /* upstream proxy authentication */
+                SQUIDCEXTERN char *peer_proxy_negotiate_auth(char *principal_name, char *proxy);
 #endif
 
-                namespace Auth {
-        /* call to ensure the auth component schemes exist. */
-        extern void Init(void);
-        } // namespace Auth
+                    namespace Auth {
+            /* call to ensure the auth component schemes exist. */
+            extern void Init(void);
+            } // namespace Auth
 
 #endif /* USE_AUTH */
 
index 1c36cc50ec5a944e7cec49de615e3aa286934ba6..e220c7871fdd0c614f77a4be1959dc3fb618414d 100644 (file)
@@ -36,6 +36,8 @@
 #include "cache_snmp.h"
 #include "Store.h"
 #include "mem_node.h"
+#include "StatCounters.h"
+#include "StatHist.h"
 #include "SquidMath.h"
 #include "SquidTime.h"
 
@@ -572,35 +574,35 @@ snmp_prfProtoFn(variable_list * Var, snint * ErrP)
             break;
 
         case PERF_MEDIAN_HTTP_ALL:
-            x = statHistDeltaMedian(&l->client_http.all_svc_time,
-                                    &f->client_http.all_svc_time);
+            x = statHistDeltaMedian(l->client_http.allSvcTime,
+                                    f->client_http.allSvcTime);
             break;
 
         case PERF_MEDIAN_HTTP_MISS:
-            x = statHistDeltaMedian(&l->client_http.miss_svc_time,
-                                    &f->client_http.miss_svc_time);
+            x = statHistDeltaMedian(l->client_http.missSvcTime,
+                                    f->client_http.missSvcTime);
             break;
 
         case PERF_MEDIAN_HTTP_NM:
-            x = statHistDeltaMedian(&l->client_http.nm_svc_time,
-                                    &f->client_http.nm_svc_time);
+            x = statHistDeltaMedian(l->client_http.nearMissSvcTime,
+                                    f->client_http.nearMissSvcTime);
             break;
 
         case PERF_MEDIAN_HTTP_HIT:
-            x = statHistDeltaMedian(&l->client_http.hit_svc_time,
-                                    &f->client_http.hit_svc_time);
+            x = statHistDeltaMedian(l->client_http.hitSvcTime,
+                                    f->client_http.hitSvcTime);
             break;
 
         case PERF_MEDIAN_ICP_QUERY:
-            x = statHistDeltaMedian(&l->icp.query_svc_time, &f->icp.query_svc_time);
+            x = statHistDeltaMedian(l->icp.querySvcTime, f->icp.querySvcTime);
             break;
 
         case PERF_MEDIAN_ICP_REPLY:
-            x = statHistDeltaMedian(&l->icp.reply_svc_time, &f->icp.reply_svc_time);
+            x = statHistDeltaMedian(l->icp.replySvcTime, f->icp.replySvcTime);
             break;
 
         case PERF_MEDIAN_DNS:
-            x = statHistDeltaMedian(&l->dns.svc_time, &f->dns.svc_time);
+            x = statHistDeltaMedian(l->dns.svcTime, f->dns.svcTime);
             break;
 
         case PERF_MEDIAN_RHR:
@@ -612,8 +614,8 @@ snmp_prfProtoFn(variable_list * Var, snint * ErrP)
             break;
 
         case PERF_MEDIAN_HTTP_NH:
-            x = statHistDeltaMedian(&l->client_http.nh_svc_time,
-                                    &f->client_http.nh_svc_time);
+            x = statHistDeltaMedian(l->client_http.nearHitSvcTime,
+                                    f->client_http.nearHitSvcTime);
             break;
 
         default:
index 447b09a36b992d2c1d9c7492fe1599c9da997922..22750b465d7fc71810d30b6195277dc5bd73f0b5 100644 (file)
@@ -54,6 +54,7 @@
 #include "MemBuf.h"
 #include "SquidMath.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "mgr/CountersAction.h"
 #include "mgr/FunAction.h"
 #include "mgr/InfoAction.h"
@@ -1090,16 +1091,16 @@ GetAvgStat(Mgr::IntervalActionData& stats, int minutes, int hours)
     stats.client_http_kbytes_in = XAVG(client_http.kbytes_in.kb);
     stats.client_http_kbytes_out = XAVG(client_http.kbytes_out.kb);
 
-    stats.client_http_all_median_svc_time = statHistDeltaMedian(&l->client_http.all_svc_time,
-                                            &f->client_http.all_svc_time) / 1000.0;
-    stats.client_http_miss_median_svc_time = statHistDeltaMedian(&l->client_http.miss_svc_time,
-            &f->client_http.miss_svc_time) / 1000.0;
-    stats.client_http_nm_median_svc_time = statHistDeltaMedian(&l->client_http.nm_svc_time,
-                                           &f->client_http.nm_svc_time) / 1000.0;
-    stats.client_http_nh_median_svc_time = statHistDeltaMedian(&l->client_http.nh_svc_time,
-                                           &f->client_http.nh_svc_time) / 1000.0;
-    stats.client_http_hit_median_svc_time = statHistDeltaMedian(&l->client_http.hit_svc_time,
-                                            &f->client_http.hit_svc_time) / 1000.0;
+    stats.client_http_all_median_svc_time = statHistDeltaMedian(l->client_http.allSvcTime,
+                                            f->client_http.allSvcTime) / 1000.0;
+    stats.client_http_miss_median_svc_time = statHistDeltaMedian(l->client_http.missSvcTime,
+            f->client_http.missSvcTime) / 1000.0;
+    stats.client_http_nm_median_svc_time = statHistDeltaMedian(l->client_http.nearMissSvcTime,
+                                           f->client_http.nearMissSvcTime) / 1000.0;
+    stats.client_http_nh_median_svc_time = statHistDeltaMedian(l->client_http.nearHitSvcTime,
+                                           f->client_http.nearHitSvcTime) / 1000.0;
+    stats.client_http_hit_median_svc_time = statHistDeltaMedian(l->client_http.hitSvcTime,
+                                            f->client_http.hitSvcTime) / 1000.0;
 
     stats.server_all_requests = XAVG(server.all.requests);
     stats.server_all_errors = XAVG(server.all.errors);
@@ -1136,12 +1137,12 @@ GetAvgStat(Mgr::IntervalActionData& stats, int minutes, int hours)
     stats.icp_q_kbytes_recv = XAVG(icp.q_kbytes_recv.kb);
     stats.icp_r_kbytes_recv = XAVG(icp.r_kbytes_recv.kb);
 
-    stats.icp_query_median_svc_time = statHistDeltaMedian(&l->icp.query_svc_time,
-                                      &f->icp.query_svc_time) / 1000000.0;
-    stats.icp_reply_median_svc_time = statHistDeltaMedian(&l->icp.reply_svc_time,
-                                      &f->icp.reply_svc_time) / 1000000.0;
-    stats.dns_median_svc_time = statHistDeltaMedian(&l->dns.svc_time,
-                                &f->dns.svc_time) / 1000.0;
+    stats.icp_query_median_svc_time = statHistDeltaMedian(l->icp.querySvcTime,
+                                      f->icp.querySvcTime) / 1000000.0;
+    stats.icp_reply_median_svc_time = statHistDeltaMedian(l->icp.replySvcTime,
+                                      f->icp.replySvcTime) / 1000000.0;
+    stats.dns_median_svc_time = statHistDeltaMedian(l->dns.svcTime,
+                                f->dns.svcTime) / 1000.0;
 
     stats.unlink_requests = XAVG(unlink.requests);
     stats.page_faults = XAVG(page_faults);
@@ -1150,7 +1151,7 @@ GetAvgStat(Mgr::IntervalActionData& stats, int minutes, int hours)
     stats.average_select_fd_period = f->select_fds > l->select_fds ?
                                      (f->select_time - l->select_time) / (f->select_fds - l->select_fds) : 0.0;
 
-    stats.median_select_fds = statHistDeltaMedian(&l->select_fds_hist, &f->select_fds_hist);
+    stats.median_select_fds = statHistDeltaMedian(l->select_fds_hist, f->select_fds_hist);
     stats.swap_outs = XAVG(swap.outs);
     stats.swap_ins = XAVG(swap.ins);
     stats.swap_files_cleaned = XAVG(swap.files_cleaned);
@@ -1485,28 +1486,28 @@ statCountersInitSpecial(StatCounters * C)
     /*
      * HTTP svc_time hist is kept in milli-seconds; max of 3 hours.
      */
-    statHistLogInit(&C->client_http.all_svc_time, 300, 0.0, 3600000.0 * 3.0);
-    statHistLogInit(&C->client_http.miss_svc_time, 300, 0.0, 3600000.0 * 3.0);
-    statHistLogInit(&C->client_http.nm_svc_time, 300, 0.0, 3600000.0 * 3.0);
-    statHistLogInit(&C->client_http.nh_svc_time, 300, 0.0, 3600000.0 * 3.0);
-    statHistLogInit(&C->client_http.hit_svc_time, 300, 0.0, 3600000.0 * 3.0);
+    C->client_http.allSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
+    C->client_http.missSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
+    C->client_http.nearMissSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
+    C->client_http.nearHitSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
+    C->client_http.hitSvcTime.logInit(300, 0.0, 3600000.0 * 3.0);
     /*
      * ICP svc_time hist is kept in micro-seconds; max of 1 minute.
      */
-    statHistLogInit(&C->icp.query_svc_time, 300, 0.0, 1000000.0 * 60.0);
-    statHistLogInit(&C->icp.reply_svc_time, 300, 0.0, 1000000.0 * 60.0);
+    C->icp.querySvcTime.logInit(300, 0.0, 1000000.0 * 60.0);
+    C->icp.replySvcTime.logInit(300, 0.0, 1000000.0 * 60.0);
     /*
      * DNS svc_time hist is kept in milli-seconds; max of 10 minutes.
      */
-    statHistLogInit(&C->dns.svc_time, 300, 0.0, 60000.0 * 10.0);
+    C->dns.svcTime.logInit(300, 0.0, 60000.0 * 10.0);
     /*
      * Cache Digest Stuff
      */
-    statHistEnumInit(&C->cd.on_xition_count, CacheDigestHashFuncCount);
-    statHistEnumInit(&C->comm_icp_incoming, INCOMING_ICP_MAX);
-    statHistEnumInit(&C->comm_dns_incoming, INCOMING_DNS_MAX);
-    statHistEnumInit(&C->comm_http_incoming, INCOMING_HTTP_MAX);
-    statHistIntInit(&C->select_fds_hist, 256); /* was SQUID_MAXFD, but it is way too much. It is OK to crop this statistics */
+    C->cd.on_xition_count.enumInit(CacheDigestHashFuncCount);
+    C->comm_icp_incoming.enumInit(INCOMING_ICP_MAX);
+    C->comm_dns_incoming.enumInit(INCOMING_DNS_MAX);
+    C->comm_http_incoming.enumInit(INCOMING_HTTP_MAX);
+    C->select_fds_hist.enumInit(256);  /* was SQUID_MAXFD, but it is way too much. It is OK to crop this statistics */
 }
 
 /* add special cases here as they arrive */
@@ -1514,19 +1515,19 @@ static void
 statCountersClean(StatCounters * C)
 {
     assert(C);
-    statHistClean(&C->client_http.all_svc_time);
-    statHistClean(&C->client_http.miss_svc_time);
-    statHistClean(&C->client_http.nm_svc_time);
-    statHistClean(&C->client_http.nh_svc_time);
-    statHistClean(&C->client_http.hit_svc_time);
-    statHistClean(&C->icp.query_svc_time);
-    statHistClean(&C->icp.reply_svc_time);
-    statHistClean(&C->dns.svc_time);
-    statHistClean(&C->cd.on_xition_count);
-    statHistClean(&C->comm_icp_incoming);
-    statHistClean(&C->comm_dns_incoming);
-    statHistClean(&C->comm_http_incoming);
-    statHistClean(&C->select_fds_hist);
+    C->client_http.allSvcTime.clear();
+    C->client_http.missSvcTime.clear();
+    C->client_http.nearMissSvcTime.clear();
+    C->client_http.nearHitSvcTime.clear();
+    C->client_http.hitSvcTime.clear();
+    C->icp.querySvcTime.clear();
+    C->icp.replySvcTime.clear();
+    C->dns.svcTime.clear();
+    C->cd.on_xition_count.clear();
+    C->comm_icp_incoming.clear();
+    C->comm_dns_incoming.clear();
+    C->comm_http_incoming.clear();
+    C->select_fds_hist.clear();
 }
 
 /* add special cases here as they arrive */
@@ -1540,42 +1541,42 @@ statCountersCopy(StatCounters * dest, const StatCounters * orig)
     statCountersInitSpecial(dest);
     /* now handle special cases */
     /* note: we assert that histogram capacities do not change */
-    statHistCopy(&dest->client_http.all_svc_time, &orig->client_http.all_svc_time);
-    statHistCopy(&dest->client_http.miss_svc_time, &orig->client_http.miss_svc_time);
-    statHistCopy(&dest->client_http.nm_svc_time, &orig->client_http.nm_svc_time);
-    statHistCopy(&dest->client_http.nh_svc_time, &orig->client_http.nh_svc_time);
-    statHistCopy(&dest->client_http.hit_svc_time, &orig->client_http.hit_svc_time);
-    statHistCopy(&dest->icp.query_svc_time, &orig->icp.query_svc_time);
-    statHistCopy(&dest->icp.reply_svc_time, &orig->icp.reply_svc_time);
-    statHistCopy(&dest->dns.svc_time, &orig->dns.svc_time);
-    statHistCopy(&dest->cd.on_xition_count, &orig->cd.on_xition_count);
-    statHistCopy(&dest->comm_icp_incoming, &orig->comm_icp_incoming);
-    statHistCopy(&dest->comm_http_incoming, &orig->comm_http_incoming);
-    statHistCopy(&dest->select_fds_hist, &orig->select_fds_hist);
+    dest->client_http.allSvcTime=orig->client_http.allSvcTime;
+    dest->client_http.missSvcTime=orig->client_http.missSvcTime;
+    dest->client_http.nearMissSvcTime=orig->client_http.nearMissSvcTime;
+    dest->client_http.nearHitSvcTime=orig->client_http.nearHitSvcTime;
+
+    dest->client_http.hitSvcTime=orig->client_http.hitSvcTime;
+    dest->icp.querySvcTime=orig->icp.querySvcTime;
+    dest->icp.replySvcTime=orig->icp.replySvcTime;
+    dest->dns.svcTime=orig->dns.svcTime;
+    dest->cd.on_xition_count=orig->cd.on_xition_count;
+    dest->comm_icp_incoming=orig->comm_icp_incoming;
+    dest->comm_http_incoming=orig->comm_http_incoming;
+    dest->select_fds_hist=orig->select_fds_hist;
 }
 
 static void
 statCountersHistograms(StoreEntry * sentry)
 {
-    StatCounters *f = &statCounter;
-    storeAppendPrintf(sentry, "client_http.all_svc_time histogram:\n");
-    statHistDump(&f->client_http.all_svc_time, sentry, NULL);
-    storeAppendPrintf(sentry, "client_http.miss_svc_time histogram:\n");
-    statHistDump(&f->client_http.miss_svc_time, sentry, NULL);
-    storeAppendPrintf(sentry, "client_http.nm_svc_time histogram:\n");
-    statHistDump(&f->client_http.nm_svc_time, sentry, NULL);
-    storeAppendPrintf(sentry, "client_http.nh_svc_time histogram:\n");
-    statHistDump(&f->client_http.nh_svc_time, sentry, NULL);
-    storeAppendPrintf(sentry, "client_http.hit_svc_time histogram:\n");
-    statHistDump(&f->client_http.hit_svc_time, sentry, NULL);
-    storeAppendPrintf(sentry, "icp.query_svc_time histogram:\n");
-    statHistDump(&f->icp.query_svc_time, sentry, NULL);
-    storeAppendPrintf(sentry, "icp.reply_svc_time histogram:\n");
-    statHistDump(&f->icp.reply_svc_time, sentry, NULL);
+    storeAppendPrintf(sentry, "client_http.allSvcTime histogram:\n");
+    statCounter.client_http.allSvcTime.dump(sentry, NULL);
+    storeAppendPrintf(sentry, "client_http.missSvcTime histogram:\n");
+    statCounter.client_http.missSvcTime.dump(sentry, NULL);
+    storeAppendPrintf(sentry, "client_http.nearMissSvcTime histogram:\n");
+    statCounter.client_http.nearMissSvcTime.dump(sentry, NULL);
+    storeAppendPrintf(sentry, "client_http.nearHitSvcTime histogram:\n");
+    statCounter.client_http.nearHitSvcTime.dump(sentry, NULL);
+    storeAppendPrintf(sentry, "client_http.hitSvcTime histogram:\n");
+    statCounter.client_http.hitSvcTime.dump(sentry, NULL);
+    storeAppendPrintf(sentry, "icp.querySvcTime histogram:\n");
+    statCounter.icp.querySvcTime.dump(sentry, NULL);
+    storeAppendPrintf(sentry, "icp.replySvcTime histogram:\n");
+    statCounter.icp.replySvcTime.dump(sentry, NULL);
     storeAppendPrintf(sentry, "dns.svc_time histogram:\n");
-    statHistDump(&f->dns.svc_time, sentry, NULL);
+    statCounter.dns.svcTime.dump(sentry, NULL);
     storeAppendPrintf(sentry, "select_fds_hist histogram:\n");
-    statHistDump(&f->select_fds_hist, sentry, NULL);
+    statCounter.select_fds_hist.dump(sentry, NULL);
 }
 
 static void
@@ -1871,31 +1872,31 @@ statPctileSvc(double pctile, int interval, int which)
     switch (which) {
 
     case PCTILE_HTTP:
-        x = statHistDeltaPctile(&l->client_http.all_svc_time, &f->client_http.all_svc_time, pctile);
+        x = statHistDeltaPctile(l->client_http.allSvcTime,f->client_http.allSvcTime, pctile);
         break;
 
     case PCTILE_HIT:
-        x = statHistDeltaPctile(&l->client_http.hit_svc_time, &f->client_http.hit_svc_time, pctile);
+        x = statHistDeltaPctile(l->client_http.hitSvcTime,f->client_http.hitSvcTime, pctile);
         break;
 
     case PCTILE_MISS:
-        x = statHistDeltaPctile(&l->client_http.miss_svc_time, &f->client_http.miss_svc_time, pctile);
+        x = statHistDeltaPctile(l->client_http.missSvcTime,f->client_http.missSvcTime, pctile);
         break;
 
     case PCTILE_NM:
-        x = statHistDeltaPctile(&l->client_http.nm_svc_time, &f->client_http.nm_svc_time, pctile);
+        x = statHistDeltaPctile(l->client_http.nearMissSvcTime,f->client_http.nearMissSvcTime, pctile);
         break;
 
     case PCTILE_NH:
-        x = statHistDeltaPctile(&l->client_http.nh_svc_time, &f->client_http.nh_svc_time, pctile);
+        x = statHistDeltaPctile(l->client_http.nearHitSvcTime,f->client_http.nearHitSvcTime, pctile);
         break;
 
     case PCTILE_ICP_QUERY:
-        x = statHistDeltaPctile(&l->icp.query_svc_time, &f->icp.query_svc_time, pctile);
+        x = statHistDeltaPctile(l->icp.querySvcTime,f->icp.querySvcTime, pctile);
         break;
 
     case PCTILE_DNS:
-        x = statHistDeltaPctile(&l->dns.svc_time, &f->dns.svc_time, pctile);
+        x = statHistDeltaPctile(l->dns.svcTime,f->dns.svcTime, pctile);
         break;
 
     default:
index 5969835eadd7dbd67ecea140d6a071ca436a7077..1c9a9e18a0dbcddca7b818f9ed7b9ecdca464067 100644 (file)
@@ -47,6 +47,7 @@
 #include "HttpRequest.h"
 #include "MemObject.h"
 #include "mem_node.h"
+#include "StatCounters.h"
 #include "StoreMeta.h"
 #include "SwapDir.h"
 #include "StoreIOState.h"
index 9789620666038c377cf6fa5d560877c6438282c4..8e022d8093de0078765a7a22b3f0acae8adefb57 100644 (file)
@@ -40,6 +40,7 @@
 #include "Store.h"
 #include "HttpReply.h"
 #include "MemObject.h"
+#include "StatCounters.h"
 #include "StoreMeta.h"
 #include "StoreMetaUnpacker.h"
 #if USE_DELAY_POOLS
index 87b334b96c5e810c4229fda9e81d7dbb2315d220..521cf26b689bb62d7ac9bc9d6f47acf97edd005a 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "squid-old.h"
 #include "event.h"
+#include "StatCounters.h"
 #include "Store.h"
 #include "SwapDir.h"
 #include "StoreSearch.h"
index 050c6828409dba9b5edd319878cc379baa5c9dc8..d7b81875a23c48beeb0dfb47d6966355ee075ceb 100644 (file)
@@ -34,6 +34,7 @@
  */
 
 #include "squid-old.h"
+#include "StatCounters.h"
 #include "StoreClient.h"
 #include "Store.h"
 
@@ -84,7 +85,7 @@ storeSwapInFileClosed(void *data, int errflag, StoreIOState::Pointer self)
         sc->callback(0, errflag ? true : false);
     }
 
-    statCounter.swap.ins++;
+    ++statCounter.swap.ins;
 }
 
 static void
index 278142633433c1368d07607d95418b0c5179c1c9..832a543d362ec1369b0a7d0fe0a9b061c0294152 100644 (file)
@@ -41,6 +41,7 @@
 #include "mem_node.h"
 #include "MemObject.h"
 #include "SwapDir.h"
+#include "StatCounters.h"
 #include "swap_log_op.h"
 
 static void storeSwapOutStart(StoreEntry * e);
@@ -348,7 +349,7 @@ storeSwapOutFileClosed(void *data, int errflag, StoreIOState::Pointer self)
             storeDirSwapLog(e, SWAP_LOG_ADD);
         }
 
-        statCounter.swap.outs++;
+        ++statCounter.swap.outs;
     }
 
     debugs(20, 3, "storeSwapOutFileClosed: " << __FILE__ << ":" << __LINE__);
index 07716eae47a20f55a1a12c4d1e6d677559c695c2..4351027fcea2250c19feae5da8651a257cb3a21d 100644 (file)
@@ -755,21 +755,6 @@ struct _domain_type {
     domain_type *next;
 };
 
-#if USE_CACHE_DIGESTS
-
-/* statistics for cache digests and other hit "predictors" */
-
-struct _cd_guess_stats {
-    /* public, read-only */
-    int true_hits;
-    int false_hits;
-    int true_misses;
-    int false_misses;
-    int close_hits;            /* tmp, remove it later */
-};
-
-#endif
-
 class PeerDigest;
 
 struct peer {
@@ -1085,171 +1070,6 @@ struct _refresh_t {
     int max_stale;
 };
 
-/*
- * "very generic" histogram;
- * see important comments on hbase_f restrictions in StatHist.c
- */
-
-struct _StatHist {
-    int *bins;
-    int capacity;
-    double min;
-    double max;
-    double scale;
-    hbase_f *val_in;           /* e.g., log() for log-based histogram */
-    hbase_f *val_out;          /* e.g., exp() for log based histogram */
-};
-
-/*
- * if you add a field to StatCounters,
- * you MUST sync statCountersInitSpecial, statCountersClean, and statCountersCopy
- */
-
-struct _StatCounters {
-
-    struct {
-        int clients;
-        int requests;
-        int hits;
-        int mem_hits;
-        int disk_hits;
-        int errors;
-        kb_t kbytes_in;
-        kb_t kbytes_out;
-        kb_t hit_kbytes_out;
-        StatHist miss_svc_time;
-        StatHist nm_svc_time;
-        StatHist nh_svc_time;
-        StatHist hit_svc_time;
-        StatHist all_svc_time;
-    } client_http;
-
-    struct {
-
-        struct {
-            int requests;
-            int errors;
-            kb_t kbytes_in;
-            kb_t kbytes_out;
-        } all , http, ftp, other;
-    } server;
-
-    struct {
-        int pkts_sent;
-        int queries_sent;
-        int replies_sent;
-        int pkts_recv;
-        int queries_recv;
-        int replies_recv;
-        int hits_sent;
-        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;
-        StatHist query_svc_time;
-        StatHist reply_svc_time;
-        int query_timeouts;
-        int times_used;
-    } icp;
-
-    struct {
-        int pkts_sent;
-        int pkts_recv;
-    } htcp;
-
-    struct {
-        int requests;
-    } unlink;
-
-    struct {
-        StatHist svc_time;
-    } dns;
-
-    struct {
-        int times_used;
-        kb_t kbytes_sent;
-        kb_t kbytes_recv;
-        kb_t memory;
-        int msgs_sent;
-        int msgs_recv;
-#if USE_CACHE_DIGESTS
-
-        cd_guess_stats guess;
-#endif
-
-        StatHist on_xition_count;
-    } cd;
-
-    struct {
-        int times_used;
-    } netdb;
-    int page_faults;
-    unsigned long int select_loops;
-    int select_fds;
-    double select_time;
-    double cputime;
-
-    struct timeval timestamp;
-    StatHist comm_icp_incoming;
-    StatHist comm_dns_incoming;
-    StatHist comm_http_incoming;
-    StatHist select_fds_hist;
-
-    struct {
-        struct {
-            int opens;
-            int closes;
-            int reads;
-            int writes;
-            int seeks;
-            int unlinks;
-        } disk;
-
-        struct {
-            int accepts;
-            int sockets;
-            int connects;
-            int binds;
-            int closes;
-            int reads;
-            int writes;
-            int recvfroms;
-            int sendtos;
-        } sock;
-        int selects;
-    } syscalls;
-    int aborted_requests;
-
-    struct {
-        int files_cleaned;
-        int outs;
-        int ins;
-    } swap;
-};
-
-/* per header statistics */
-
-struct _HttpHeaderStat {
-    const char *label;
-    HttpHeaderMask *owner_mask;
-
-    StatHist hdrUCountDistr;
-    StatHist fieldTypeDistr;
-    StatHist ccTypeDistr;
-    StatHist scTypeDistr;
-
-    int parsedCount;
-    int ccParsedCount;
-    int scParsedCount;
-    int destroyedCount;
-    int busyDestroyedCount;
-};
-
 
 struct _CacheDigest {
     /* public, read-only */
index 9bcc5857f16d01638f43649d8fd5e5496f78a457..cf0cfdfd4ea21c35ed458ce904ee9a616e0a69a3 100644 (file)
@@ -1,22 +1,39 @@
 #include "squid.h"
+#define STUB_API "StatHist.cc"
+#include "STUB.h"
+#include "StatHist.h"
 
-// for StatHist definitions
-#include "protos.h"
 
 void
-statHistDump(const StatHist * H, StoreEntry * sentry, StatHistBinDumper * bd)
-{
-    fatal("statHistDump: Not implemented");
-}
+StatHist::dump(StoreEntry * sentry, StatHistBinDumper * bd) const
+{}
 
 void
-statHistCount(StatHist * H, double val)
-{
-    fatal("statHistCount: Not implemented");
-}
+StatHist::enumInit(unsigned int i)
+{}
 
 void
-statHistEnumInit(StatHist * H, int last_enum)
-{
-//NO-OP    fatal("statHistEnumInit: Not implemented");
-}
+StatHist::count(double d)
+{}
+
+double
+statHistDeltaMedian(const StatHist & A, const StatHist & B)
+STUB_RETVAL(0.0)
+
+double
+statHistDeltaPctile(const StatHist & A, const StatHist & B, double pctile)
+STUB_RETVAL(0.0)
+
+void
+StatHist::clear()
+STUB
+
+void
+StatHist::logInit(unsigned int i, double d1, double d2)
+STUB
+
+class StoreEntry;
+void
+statHistIntDumper(StoreEntry * sentry, int idx, double val, double size, int count)
+STUB
+
diff --git a/src/tests/stub_mem.cc b/src/tests/stub_mem.cc
new file mode 100644 (file)
index 0000000..53cc877
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * stub file for mem.cc
+ */
+
+#include "squid.h"
+
+#define STUB_API "stub_mem.cc"
+#include "STUB.h"
+/* mem* definitions are still in protos.h */
+#include "protos.h"
+
+extern "C" void
+memFreeString(size_t size, void *buf)
+{
+    xfree(buf);
+}
+
+extern "C" void *
+memAllocString(size_t net_size, size_t * gross_size)
+{
+    *gross_size=net_size;
+    return xmalloc(net_size);
+}
+
+extern "C" void
+memFreeBuf(size_t size, void *buf)
+{
+    xfree(buf);
+}
+
+extern "C" void *
+memAllocBuf(size_t net_size, size_t * gross_size)
+{
+    *gross_size=net_size;
+    return xcalloc(1, net_size);
+}
+
+/* net_size is the new size, *gross size is the old gross size, to be changed to
+ * the new gross size as a side-effect.
+ */
+extern "C" void *
+memReallocBuf(void *oldbuf, size_t net_size, size_t * gross_size)
+{
+    void *rv=xrealloc(oldbuf,net_size);
+//    if (net_size > *gross_size)
+//        memset(rv+net_size,0,net_size-*gross_size);
+    *gross_size=net_size;
+    return rv;
+}
+
+static void
+cxx_xfree(void * ptr)
+{
+    xfree(ptr);
+}
+
+FREE *
+memFreeBufFunc(size_t size)
+{
+    return cxx_xfree;
+}
+
+void *
+memAllocate(mem_type type)
+STUB_RETVAL(NULL)
+
+void
+memFree(void *p, int type)
+STUB
index 951fbf209a6520bbe424037ecb828b46e4cb9c8d..27046c3a75bc2cdcc5664c2880b7a4bbde6a0120 100644 (file)
@@ -1,49 +1,12 @@
-/*
- * $Id$
- *
- * DEBUG: section 84    Helper process maintenance
- * AUTHOR: Robert Collins
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- */
-
 #include "squid.h"
 #include "stmem.h"
 
-mem_hdr::mem_hdr()
-{}
+#define STUB_API "stmem.cc"
+#include "tests/STUB.h"
 
-mem_hdr::~mem_hdr()
-{}
+mem_hdr::mem_hdr() STUB
+mem_hdr::~mem_hdr() STUB
+size_t mem_hdr::size() const STUB_RETVAL(0)
+int64_t mem_hdr::endOffset () const STUB_RETVAL(0)
+bool mem_hdr::write (StoreIOBuffer const &writeBuffer) STUB_RETVAL(false)
 
-size_t
-mem_hdr::size() const
-{
-    fatal ("Not implemented");
-    return 0;
-}
diff --git a/src/tests/testStatHist.cc b/src/tests/testStatHist.cc
new file mode 100644 (file)
index 0000000..8e03768
--- /dev/null
@@ -0,0 +1,78 @@
+#define SQUID_UNIT_TEST 1
+#include "squid.h"
+#include "testStatHist.h"
+#include "StatHist.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION(testStatHist);
+
+typedef enum {
+    ZERO, ONE, TWO, THREE, FOUR, FIVE
+} number ;
+
+class InspectingStatHist : public StatHist
+{
+public:
+    bool operator==(const InspectingStatHist &);
+    bins_type counter(double val) {
+        return bins[findBin(val)];
+    }
+};
+
+bool
+InspectingStatHist::operator ==(const InspectingStatHist & src)
+{
+    assert(bins != NULL && src.bins != NULL); // TODO: remove after initializing bins at construction time
+    if (capacity_ != src.capacity_ ||
+            min_!=src.min_ ||
+            max_!=src.max_ ||
+            scale_!=src.scale_ ||
+            val_in!=src.val_in ||
+            val_out!=src.val_out)
+        return false;
+    return (memcmp(bins,src.bins,capacity_*sizeof(*bins))==0);
+}
+
+
+
+void
+testStatHist::testStatHistBaseEquality()
+{
+    InspectingStatHist raw, test;
+    raw.enumInit(FIVE);
+    test.enumInit(FIVE);
+    CPPUNIT_ASSERT(raw==test);
+    test.count(ZERO);
+    CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw==test));
+}
+
+void
+testStatHist::testStatHistBaseAssignment()
+{
+    InspectingStatHist raw, test;
+    raw.enumInit(FIVE);
+    test.enumInit(FIVE);
+    test.count(ZERO);
+    CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(raw==test));
+    test=raw;
+    CPPUNIT_ASSERT(raw==test);
+}
+
+
+void
+testStatHist::testStatHistLog()
+{
+    const double min=0.0, max=10000.0;
+    const int capacity=10;
+    InspectingStatHist raw, test;
+    raw.logInit(capacity,min,max);
+    test=raw;
+    CPPUNIT_ASSERT(test.counter(min)==0);
+    test.count(min);
+    CPPUNIT_ASSERT(test.counter(min)==1);
+    CPPUNIT_ASSERT(test.counter(max)==0);
+    test.count(max);
+    CPPUNIT_ASSERT(test.counter(max)==1);
+    test=raw;
+    test.count(max);
+    //CPPUNIT_ASSERT(test.val(capacity-1)==1); //FIXME: val() returns a density
+}
diff --git a/src/tests/testStatHist.h b/src/tests/testStatHist.h
new file mode 100644 (file)
index 0000000..8a3af1a
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * StatHist unit test
+ */
+
+#ifndef TESTSTATHIST_H_
+#define TESTSTATHIST_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+
+class testStatHist : public CPPUNIT_NS::TestFixture
+{
+    CPPUNIT_TEST_SUITE( testStatHist );
+    CPPUNIT_TEST( testStatHistBaseEquality );
+    CPPUNIT_TEST( testStatHistBaseAssignment );
+    CPPUNIT_TEST( testStatHistLog );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+
+protected:
+    void testStatHistBaseEquality();
+    void testStatHistBaseAssignment();
+    void testStatHistLog();
+};
+
+#endif /* TESTSTATHIST_H_ */
index 7fa9f4993b1cc30d1dba137f0c1e316006629419..739ae2a59bdd823bf74002c5d3f2743f9308b8f6 100644 (file)
@@ -51,6 +51,7 @@
 #include "MemBuf.h"
 #include "http.h"
 #include "PeerSelectState.h"
+#include "StatCounters.h"
 
 class TunnelStateData
 {
@@ -249,8 +250,8 @@ TunnelStateData::readServer(char *buf, size_t len, comm_err_t errcode, int xerrn
 
     if (len > 0) {
         server.bytesIn(len);
-        kb_incr(&statCounter.server.all.kbytes_in, len);
-        kb_incr(&statCounter.server.other.kbytes_in, len);
+        kb_incr(&(statCounter.server.all.kbytes_in), len);
+        kb_incr(&(statCounter.server.other.kbytes_in), len);
     }
 
     copy (len, errcode, xerrno, server, client, WriteClientDone);
@@ -293,7 +294,7 @@ TunnelStateData::readClient(char *buf, size_t len, comm_err_t errcode, int xerrn
 
     if (len > 0) {
         client.bytesIn(len);
-        kb_incr(&statCounter.client_http.kbytes_in, len);
+        kb_incr(&(statCounter.client_http.kbytes_in), len);
     }
 
     copy (len, errcode, xerrno, client, server, WriteServerDone);
@@ -369,8 +370,8 @@ TunnelStateData::writeServerDone(char *buf, size_t len, comm_err_t flag, int xer
     }
 
     /* Valid data */
-    kb_incr(&statCounter.server.all.kbytes_out, len);
-    kb_incr(&statCounter.server.other.kbytes_out, len);
+    kb_incr(&(statCounter.server.all.kbytes_out), len);
+    kb_incr(&(statCounter.server.other.kbytes_out), len);
     client.dataSent(len);
 
     /* If the other end has closed, so should we */
@@ -432,7 +433,7 @@ TunnelStateData::writeClientDone(char *buf, size_t len, comm_err_t flag, int xer
     }
 
     /* Valid data */
-    kb_incr(&statCounter.client_http.kbytes_out, len);
+    kb_incr(&(statCounter.client_http.kbytes_out), len);
     server.dataSent(len);
 
     /* If the other end has closed, so should we */
index 5b37728abcfcf1e1751f7cfa8f28ba6d6d94ce73..85db56398243fe91769880787c7a03727554ec43 100644 (file)
@@ -55,8 +55,6 @@ typedef struct _dwrite_q dwrite_q;
 
 typedef struct _HttpHeaderFieldAttrs HttpHeaderFieldAttrs;
 
-typedef struct _HttpHeaderStat HttpHeaderStat;
-
 typedef struct _domain_ping domain_ping;
 
 typedef struct _domain_type domain_type;
@@ -83,14 +81,8 @@ typedef struct _refresh_t refresh_t;
 
 typedef struct _CommWriteStateData CommWriteStateData;
 
-typedef struct _StatCounters StatCounters;
-
 typedef struct _storeSwapLogData storeSwapLogData;
 
-typedef struct _StatHist StatHist;
-
-typedef struct _cd_guess_stats cd_guess_stats;
-
 typedef struct _CacheDigest CacheDigest;
 
 typedef struct _Version Version;
@@ -147,9 +139,6 @@ typedef void HLPSONEQ(void *);
 typedef void HLPCMDOPTS(int *argc, char **argv);
 typedef void IDNSCB(void *, rfc1035_rr *, int, const char *);
 
-typedef double hbase_f(double);
-typedef void StatHistBinDumper(StoreEntry *, int idx, double val, double size, int count);
-
 /* MD5 cache keys */
 typedef unsigned char cache_key;
 
index c71f0befcbfa91d253770e6f888884cfaee43d96..23c7074a1aef48ab2f2e2d8df737abbd85682345 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "squid-old.h"
 #include "SquidTime.h"
+#include "StatCounters.h"
 #include "SwapDir.h"
 #include "fde.h"
 #include "xusleep.h"
@@ -131,13 +132,13 @@ unlinkdUnlink(const char *path)
         return;
     }
 
-    statCounter.unlink.requests++;
+    ++statCounter.unlink.requests;
     /*
     * Increment this syscalls counter here, even though the syscall
     * is executed by the helper process.  We try to be consistent
     * in counting unlink operations.
     */
-    statCounter.syscalls.disk.unlinks++;
+    ++statCounter.syscalls.disk.unlinks;
     queuelen++;
 }
 
index 6ee7cc9d81c52d643fcfc8309edc1f3bccfb33b5..b2c74b43509344a15d9edddb73f13ad4c81f0088 100644 (file)
@@ -42,6 +42,7 @@
 #include "comm.h"
 #include "HttpRequest.h"
 #include "forward.h"
+#include "StatCounters.h"
 
 #define WHOIS_PORT 43
 
@@ -169,8 +170,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);
+        kb_incr(&(statCounter.server.all.kbytes_in), aBufferLength);
+        kb_incr(&(statCounter.server.http.kbytes_in), aBufferLength);
 
         /* No range support, we always grab it all */
         dataWritten = true;