From 8c9842d413b00205243457a22f6f7d0fdca0d70e Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Sat, 3 Mar 2012 16:19:03 -0700 Subject: [PATCH] Bug 3381: 32-bit overflow assertion in StatHist - 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 --- src/CacheDigest.cc | 33 +-- src/DiskIO/DiskDaemon/DiskdFile.cc | 11 +- src/DiskIO/DiskDaemon/DiskdIOStrategy.cc | 3 +- src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc | 11 +- .../DiskThreads/DiskThreadsIOStrategy.cc | 3 +- src/DiskIO/IpcIo/IpcIoFile.cc | 5 +- src/HttpHdrCc.cc | 6 +- src/HttpHdrSc.cc | 1 + src/HttpHdrScTarget.cc | 3 +- src/HttpHeader.cc | 22 +- src/HttpHeaderStat.h | 33 +++ src/Makefile.am | 121 +++++++--- src/PeerDigest.h | 5 +- src/Server.cc | 3 +- src/StatCounters.cc | 35 +++ src/StatCounters.h | 188 +++++++++++++++ src/StatHist.cc | 216 ++++++------------ src/StatHist.h | 159 +++++++++++++ src/client_db.cc | 5 +- src/client_side.cc | 25 +- src/comm.cc | 1 + src/comm/ModDevPoll.cc | 7 +- src/comm/ModEpoll.cc | 6 +- src/comm/ModPoll.cc | 16 +- src/comm/ModSelect.cc | 17 +- src/comm/ModSelectWin32.cc | 17 +- src/comm/TcpAcceptor.cc | 3 +- src/comm/Write.cc | 3 +- src/disk.cc | 3 +- src/fqdncache.cc | 3 +- src/fs/ufs/store_dir_ufs.cc | 3 +- src/ftp.cc | 15 +- src/globals.h | 3 +- src/gopher.cc | 9 +- src/htcp.cc | 1 + src/http.cc | 9 +- src/icp_v2.cc | 5 +- src/ipcache.cc | 3 +- src/main.cc | 1 + src/protos.h | 120 +++++----- src/snmp_agent.cc | 28 +-- src/stat.cc | 159 ++++++------- src/store.cc | 1 + src/store_client.cc | 1 + src/store_rebuild.cc | 1 + src/store_swapin.cc | 3 +- src/store_swapout.cc | 3 +- src/structs.h | 180 --------------- src/tests/stub_StatHist.cc | 45 ++-- src/tests/stub_mem.cc | 69 ++++++ src/tests/stub_stmem.cc | 51 +---- src/tests/testStatHist.cc | 78 +++++++ src/tests/testStatHist.h | 27 +++ src/tunnel.cc | 13 +- src/typedefs.h | 11 - src/unlinkd.cc | 5 +- src/whois.cc | 5 +- 57 files changed, 1107 insertions(+), 706 deletions(-) create mode 100644 src/HttpHeaderStat.h create mode 100644 src/StatCounters.cc create mode 100644 src/StatCounters.h create mode 100644 src/StatHist.h create mode 100644 src/tests/stub_mem.cc create mode 100644 src/tests/testStatHist.cc create mode 100644 src/tests/testStatHist.h diff --git a/src/CacheDigest.cc b/src/CacheDigest.cc index 8a96066560..b2f2cdb971 100644 --- a/src/CacheDigest.cc +++ b/src/CacheDigest.cc @@ -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 diff --git a/src/DiskIO/DiskDaemon/DiskdFile.cc b/src/DiskIO/DiskDaemon/DiskdFile.cc index 4a6f955d8a..af376dcb8c 100644 --- a/src/DiskIO/DiskDaemon/DiskdFile.cc +++ b/src/DiskIO/DiskDaemon/DiskdFile.cc @@ -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(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(M->requestor); diff --git a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc index ee2f3d706b..1c0b937e5b 100644 --- a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc +++ b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc @@ -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++; diff --git a/src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc b/src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc index a6badd437f..19cfc6222c 100644 --- a/src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc +++ b/src/DiskIO/DiskThreads/DiskThreadsDiskFile.cc @@ -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 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 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 diff --git a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc index 7e2e16e206..e490f392c9 100644 --- a/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc +++ b/src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc @@ -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); } diff --git a/src/DiskIO/IpcIo/IpcIoFile.cc b/src/DiskIO/IpcIo/IpcIoFile.cc index a648f1fa0f..30f9c585f7 100644 --- a/src/DiskIO/IpcIo/IpcIoFile.cc +++ b/src/DiskIO/IpcIo/IpcIoFile.cc @@ -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) { diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index 6d543d7b02..4d86e7e461 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -32,9 +32,11 @@ #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 @@ -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 diff --git a/src/HttpHdrSc.cc b/src/HttpHdrSc.cc index 938c79cdeb..1b554518bd 100644 --- a/src/HttpHdrSc.cc +++ b/src/HttpHdrSc.cc @@ -39,6 +39,7 @@ #include "squid-old.h" #include "Store.h" #include "HttpHeader.h" +#include "HttpHeaderStat.h" #include "HttpHdrSc.h" #if HAVE_MAP diff --git a/src/HttpHdrScTarget.cc b/src/HttpHdrScTarget.cc index 5a78eb901a..cc9571ad6c 100644 --- a/src/HttpHdrScTarget.cc +++ b/src/HttpHdrScTarget.cc @@ -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); } diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 12cb2c4a22..cf398e7f23 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -39,9 +39,11 @@ #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 index 0000000000..7fcff9d045 --- /dev/null +++ b/src/HttpHeaderStat.h @@ -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_ */ diff --git a/src/Makefile.am b/src/Makefile.am index f4bb1e2398..639882be33 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/PeerDigest.h b/src/PeerDigest.h index 7a7af382da..696dc8f377 100644 --- a/src/PeerDigest.h +++ b/src/PeerDigest.h @@ -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 { diff --git a/src/Server.cc b/src/Server.cc index 945af7e482..beffab6a46 100644 --- a/src/Server.cc +++ b/src/Server.cc @@ -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 index 0000000000..34379fa250 --- /dev/null +++ b/src/StatCounters.cc @@ -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 index 0000000000..cfedcadc90 --- /dev/null +++ b/src/StatCounters.h @@ -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_ */ diff --git a/src/StatHist.cc b/src/StatHist.cc index 6b82e9bfd5..9e5d0ddcc1 100644 --- a/src/StatHist.cc +++ b/src/StatHist.cc @@ -1,7 +1,5 @@ /* - * $Id$ - * * DEBUG: section 62 Generic Histogram * AUTHOR: Duane Wessels * @@ -33,25 +31,10 @@ * */ -/* - * 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(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; ibins); - - if (Dest->capacity == Orig->capacity) - statHistCopy(Dest, Orig); + if (src.bins!=NULL) { + bins = static_cast(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 (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(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 index 0000000000..576525d21a --- /dev/null +++ b/src/StatHist.h @@ -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(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_ */ diff --git a/src/client_db.cc b/src/client_db.cc index c549f41169..0df881542e 100644 --- a/src/client_db.cc +++ b/src/client_db.cc @@ -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++; } diff --git a/src/client_side.cc b/src/client_side.cc index 5870dfa8ed..2b9d35adbf 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -117,6 +117,8 @@ #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)) diff --git a/src/comm.cc b/src/comm.cc index 0fde2694bb..e39f66b1a8 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -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 diff --git a/src/comm/ModDevPoll.cc b/src/comm/ModDevPoll.cc index 9fb29d62d5..525587f719 100644 --- a/src/comm/ModDevPoll.cc +++ b/src/comm/ModDevPoll.cc @@ -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 */ diff --git a/src/comm/ModEpoll.cc b/src/comm/ModEpoll.cc index 22f134db94..9a8f986905 100644 --- a/src/comm/ModEpoll.cc +++ b/src/comm/ModEpoll.cc @@ -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.. */ diff --git a/src/comm/ModPoll.cc b/src/comm/ModPoll.cc index 95f585390c..2ee0ab388f 100644 --- a/src/comm/ModPoll.cc +++ b/src/comm/ModPoll.cc @@ -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 */ diff --git a/src/comm/ModSelect.cc b/src/comm/ModSelect.cc index bcc62cb132..c882569be7 100644 --- a/src/comm/ModSelect.cc +++ b/src/comm/ModSelect.cc @@ -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 diff --git a/src/comm/ModSelectWin32.cc b/src/comm/ModSelectWin32.cc index 27e80a9708..5eb36a2af4 100644 --- a/src/comm/ModSelectWin32.cc +++ b/src/comm/ModSelectWin32.cc @@ -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 diff --git a/src/comm/TcpAcceptor.cc b/src/comm/TcpAcceptor.cc index e6791fbb19..f8ceeedb69 100644 --- a/src/comm/TcpAcceptor.cc +++ b/src/comm/TcpAcceptor.cc @@ -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); diff --git a/src/comm/Write.cc b/src/comm/Write.cc index ec656fb7c0..641e7bda8f 100644 --- a/src/comm/Write.cc +++ b/src/comm/Write.cc @@ -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; diff --git a/src/disk.cc b/src/disk.cc index 9dad9c5778..92724c54a6 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -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; } diff --git a/src/fqdncache.cc b/src/fqdncache.cc index 22c02fb322..ad1a5f60b7 100644 --- a/src/fqdncache.cc +++ b/src/fqdncache.cc @@ -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(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); diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 0341b4bbbb..4e950a9407 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -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); diff --git a/src/ftp.cc b/src/ftp.cc index e92ebd631e..8dd4d6c114 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -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); } diff --git a/src/globals.h b/src/globals.h index c20e713b5e..4165e0090c 100644 --- a/src/globals.h +++ b/src/globals.h @@ -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 */ diff --git a/src/gopher.cc b/src/gopher.cc index 3e83bb010f..e560f04e68 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -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) { diff --git a/src/htcp.cc b/src/htcp.cc index 87861f887e..b243ee55e5 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -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" diff --git a/src/http.cc b/src/http.cc index 95b7fed354..63f78bac35 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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) diff --git a/src/icp_v2.cc b/src/icp_v2.cc index e0aa6b8091..436f36df84 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -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) diff --git a/src/ipcache.cc b/src/ipcache.cc index 727b2b4b06..19b0f31a4e 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -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(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); diff --git a/src/main.cc b/src/main.cc index 6b12880f4e..8c9a850b97 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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" diff --git a/src/protos.h b/src/protos.h index 23af5517b4..f8227bbb5f 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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 */ diff --git a/src/snmp_agent.cc b/src/snmp_agent.cc index 1c36cc50ec..e220c7871f 100644 --- a/src/snmp_agent.cc +++ b/src/snmp_agent.cc @@ -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: diff --git a/src/stat.cc b/src/stat.cc index 447b09a36b..22750b465d 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -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: diff --git a/src/store.cc b/src/store.cc index 5969835ead..1c9a9e18a0 100644 --- a/src/store.cc +++ b/src/store.cc @@ -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" diff --git a/src/store_client.cc b/src/store_client.cc index 9789620666..8e022d8093 100644 --- a/src/store_client.cc +++ b/src/store_client.cc @@ -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 diff --git a/src/store_rebuild.cc b/src/store_rebuild.cc index 87b334b96c..521cf26b68 100644 --- a/src/store_rebuild.cc +++ b/src/store_rebuild.cc @@ -35,6 +35,7 @@ #include "squid-old.h" #include "event.h" +#include "StatCounters.h" #include "Store.h" #include "SwapDir.h" #include "StoreSearch.h" diff --git a/src/store_swapin.cc b/src/store_swapin.cc index 050c682840..d7b81875a2 100644 --- a/src/store_swapin.cc +++ b/src/store_swapin.cc @@ -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 diff --git a/src/store_swapout.cc b/src/store_swapout.cc index 2781426334..832a543d36 100644 --- a/src/store_swapout.cc +++ b/src/store_swapout.cc @@ -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__); diff --git a/src/structs.h b/src/structs.h index 07716eae47..4351027fce 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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 */ diff --git a/src/tests/stub_StatHist.cc b/src/tests/stub_StatHist.cc index 9bcc5857f1..cf0cfdfd4e 100644 --- a/src/tests/stub_StatHist.cc +++ b/src/tests/stub_StatHist.cc @@ -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 index 0000000000..53cc877b1f --- /dev/null +++ b/src/tests/stub_mem.cc @@ -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 diff --git a/src/tests/stub_stmem.cc b/src/tests/stub_stmem.cc index 951fbf209a..27046c3a75 100644 --- a/src/tests/stub_stmem.cc +++ b/src/tests/stub_stmem.cc @@ -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 index 0000000000..8e03768661 --- /dev/null +++ b/src/tests/testStatHist.cc @@ -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 index 0000000000..8a3af1a032 --- /dev/null +++ b/src/tests/testStatHist.h @@ -0,0 +1,27 @@ +/* + * StatHist unit test + */ + +#ifndef TESTSTATHIST_H_ +#define TESTSTATHIST_H_ + +#include + + +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_ */ diff --git a/src/tunnel.cc b/src/tunnel.cc index 7fa9f4993b..739ae2a59b 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -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 */ diff --git a/src/typedefs.h b/src/typedefs.h index 5b37728abc..85db563982 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -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; diff --git a/src/unlinkd.cc b/src/unlinkd.cc index c71f0befcb..23c7074a1a 100644 --- a/src/unlinkd.cc +++ b/src/unlinkd.cc @@ -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++; } diff --git a/src/whois.cc b/src/whois.cc index 6ee7cc9d81..b2c74b4350 100644 --- a/src/whois.cc +++ b/src/whois.cc @@ -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; -- 2.47.2