]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: separate SBufStats from SBuf.h
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 28 Feb 2016 07:49:02 +0000 (20:49 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 28 Feb 2016 07:49:02 +0000 (20:49 +1300)
src/sbuf/Makefile.am
src/sbuf/SBuf.cc
src/sbuf/SBuf.h
src/sbuf/Stats.cc [new file with mode: 0644]
src/sbuf/Stats.h [new file with mode: 0644]

index 062bda48314a0293059c965a84e9bc281fe40928..e42c1e29b7f1e60e5526e2efb41c49410c4437cf 100644 (file)
@@ -24,4 +24,6 @@ libsbuf_la_SOURCES = \
        SBufExceptions.h \
        SBufList.cc \
        SBufList.h \
-       SBufStream.h
+       SBufStream.h \
+       Stats.cc \
+       Stats.h
index 1e75cc883168f01775e748b667d0400d7852a00f..1d2ea44c9ad67caa0f7c0c55b6998d7ca57cc7f1 100644 (file)
@@ -36,44 +36,6 @@ SBufStats SBuf::stats;
 const SBuf::size_type SBuf::npos;
 const SBuf::size_type SBuf::maxSize;
 
-SBufStats::SBufStats()
-    : alloc(0), allocCopy(0), allocFromCString(0),
-      assignFast(0), clear(0), append(0), moves(0), toStream(0), setChar(0),
-      getChar(0), compareSlow(0), compareFast(0), copyOut(0),
-      rawAccess(0), nulTerminate(0), chop(0), trim(0), find(0), scanf(0),
-      caseChange(0), cowFast(0), cowSlow(0), live(0)
-{}
-
-SBufStats&
-SBufStats::operator +=(const SBufStats& ss)
-{
-    alloc += ss.alloc;
-    allocCopy += ss.allocCopy;
-    allocFromCString += ss.allocFromCString;
-    assignFast += ss.assignFast;
-    clear += ss.clear;
-    append += ss.append;
-    moves += ss.moves;
-    toStream += ss.toStream;
-    setChar += ss.setChar;
-    getChar += ss.getChar;
-    compareSlow += ss.compareSlow;
-    compareFast += ss.compareFast;
-    copyOut += ss.copyOut;
-    rawAccess += ss.rawAccess;
-    nulTerminate += ss.nulTerminate;
-    chop += ss.chop;
-    trim += ss.trim;
-    find += ss.find;
-    scanf += ss.scanf;
-    caseChange += ss.caseChange;
-    cowFast += ss.cowFast;
-    cowSlow += ss.cowSlow;
-    live += ss.live;
-
-    return *this;
-}
-
 SBuf::SBuf()
     : store_(GetStorePrototype()), off_(0), len_(0)
 {
@@ -863,40 +825,6 @@ SBuf::scanf(const char *format, ...)
     return rv;
 }
 
-std::ostream &
-SBufStats::dump(std::ostream& os) const
-{
-    MemBlobStats ststats = MemBlob::GetStats();
-    os <<
-       "SBuf stats:\nnumber of allocations: " << alloc <<
-       "\ncopy-allocations: " << allocCopy <<
-       "\ncopy-allocations from C String: " << allocFromCString <<
-       "\nlive references: " << live <<
-       "\nno-copy assignments: " << assignFast <<
-       "\nclearing operations: " << clear <<
-       "\nappend operations: " << append <<
-       "\nmove operations: " << moves <<
-       "\ndump-to-ostream: " << toStream <<
-       "\nset-char: " << setChar <<
-       "\nget-char: " << getChar <<
-       "\ncomparisons with data-scan: " << compareSlow <<
-       "\ncomparisons not requiring data-scan: " << compareFast <<
-       "\ncopy-out ops: " << copyOut <<
-       "\nraw access to memory: " << rawAccess <<
-       "\nNULL terminate C string: " << nulTerminate <<
-       "\nchop operations: " << chop <<
-       "\ntrim operations: " << trim <<
-       "\nfind: " << find <<
-       "\nscanf: " << scanf <<
-       "\ncase-change ops: " << caseChange <<
-       "\nCOW not actually requiring a copy: " << cowFast <<
-       "\nCOW: " << cowSlow <<
-       "\naverage store share factor: " <<
-       (ststats.live != 0 ? static_cast<float>(live)/ststats.live : 0) <<
-       std::endl;
-    return os;
-}
-
 void
 SBuf::toLower()
 {
index f275fc7894105e3ed1bb5e848262c8b493eea3de..0780eb528ab80213eb5a3104e7b2fa2a2ab6ae99 100644 (file)
@@ -16,6 +16,7 @@
 #include "globals.h"
 #include "sbuf/MemBlob.h"
 #include "SBufExceptions.h"
+#include "sbuf/Stats.h"
 
 #include <climits>
 #include <cstdarg>
@@ -37,47 +38,6 @@ typedef enum {
     caseInsensitive
 } SBufCaseSensitive;
 
-/**
- * Container for various SBuf class-wide statistics.
- *
- * The stats are not completely accurate; they're mostly meant to
- * understand whether Squid is leaking resources
- * and whether SBuf is paying off the expected gains.
- */
-class SBufStats
-{
-public:
-    uint64_t alloc; ///<number of calls to SBuf constructors
-    uint64_t allocCopy; ///<number of calls to SBuf copy-constructor
-    uint64_t allocFromCString; ///<number of copy-allocations from c-strings
-    uint64_t assignFast; ///<number of no-copy assignment operations
-    uint64_t clear; ///<number of clear operations
-    uint64_t append; ///<number of append operations
-    uint64_t moves; ///<number of move constructions/assignments
-    uint64_t toStream;  ///<number of write operations to ostreams
-    uint64_t setChar; ///<number of calls to setAt
-    uint64_t getChar; ///<number of calls to at() and operator[]
-    uint64_t compareSlow; ///<number of comparison operations requiring data scan
-    uint64_t compareFast; ///<number of comparison operations not requiring data scan
-    uint64_t copyOut; ///<number of data-copies to other forms of buffers
-    uint64_t rawAccess; ///<number of accesses to raw contents
-    uint64_t nulTerminate; ///<number of c_str() terminations
-    uint64_t chop;  ///<number of chop operations
-    uint64_t trim;  ///<number of trim operations
-    uint64_t find;  ///<number of find operations
-    uint64_t scanf;  ///<number of scanf operations
-    uint64_t caseChange; ///<number of toUpper and toLower operations
-    uint64_t cowFast; ///<number of cow operations not actually requiring a copy
-    uint64_t cowSlow; ///<number of cow operations requiring a copy
-    uint64_t live;  ///<number of currently-allocated SBuf
-
-    ///Dump statistics to an ostream.
-    std::ostream& dump(std::ostream &os) const;
-    SBufStats();
-
-    SBufStats& operator +=(const SBufStats&);
-};
-
 class CharacterSet;
 class SBuf;
 
diff --git a/src/sbuf/Stats.cc b/src/sbuf/Stats.cc
new file mode 100644 (file)
index 0000000..67f7fac
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "sbuf/MemBlob.h"
+#include "sbuf/SBuf.h"
+#include "sbuf/Stats.h"
+
+#include <iostream>
+
+SBufStats::SBufStats()
+    : alloc(0), allocCopy(0), allocFromCString(0),
+      assignFast(0), clear(0), append(0), moves(0), toStream(0), setChar(0),
+      getChar(0), compareSlow(0), compareFast(0), copyOut(0),
+      rawAccess(0), nulTerminate(0), chop(0), trim(0), find(0), scanf(0),
+      caseChange(0), cowFast(0), cowSlow(0), live(0)
+{}
+
+SBufStats&
+SBufStats::operator +=(const SBufStats& ss)
+{
+    alloc += ss.alloc;
+    allocCopy += ss.allocCopy;
+    allocFromCString += ss.allocFromCString;
+    assignFast += ss.assignFast;
+    clear += ss.clear;
+    append += ss.append;
+    moves += ss.moves;
+    toStream += ss.toStream;
+    setChar += ss.setChar;
+    getChar += ss.getChar;
+    compareSlow += ss.compareSlow;
+    compareFast += ss.compareFast;
+    copyOut += ss.copyOut;
+    rawAccess += ss.rawAccess;
+    nulTerminate += ss.nulTerminate;
+    chop += ss.chop;
+    trim += ss.trim;
+    find += ss.find;
+    scanf += ss.scanf;
+    caseChange += ss.caseChange;
+    cowFast += ss.cowFast;
+    cowSlow += ss.cowSlow;
+    live += ss.live;
+
+    return *this;
+}
+
+std::ostream &
+SBufStats::dump(std::ostream& os) const
+{
+    MemBlobStats ststats = MemBlob::GetStats();
+    os <<
+       "SBuf stats:\nnumber of allocations: " << alloc <<
+       "\ncopy-allocations: " << allocCopy <<
+       "\ncopy-allocations from C String: " << allocFromCString <<
+       "\nlive references: " << live <<
+       "\nno-copy assignments: " << assignFast <<
+       "\nclearing operations: " << clear <<
+       "\nappend operations: " << append <<
+       "\nmove operations: " << moves <<
+       "\ndump-to-ostream: " << toStream <<
+       "\nset-char: " << setChar <<
+       "\nget-char: " << getChar <<
+       "\ncomparisons with data-scan: " << compareSlow <<
+       "\ncomparisons not requiring data-scan: " << compareFast <<
+       "\ncopy-out ops: " << copyOut <<
+       "\nraw access to memory: " << rawAccess <<
+       "\nNULL terminate C string: " << nulTerminate <<
+       "\nchop operations: " << chop <<
+       "\ntrim operations: " << trim <<
+       "\nfind: " << find <<
+       "\nscanf: " << scanf <<
+       "\ncase-change ops: " << caseChange <<
+       "\nCOW not actually requiring a copy: " << cowFast <<
+       "\nCOW: " << cowSlow <<
+       "\naverage store share factor: " <<
+       (ststats.live != 0 ? static_cast<float>(live)/ststats.live : 0) <<
+       std::endl;
+    return os;
+}
+
diff --git a/src/sbuf/Stats.h b/src/sbuf/Stats.h
new file mode 100644 (file)
index 0000000..34c37a0
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SBUF_STATS_H
+#define SQUID_SBUF_STATS_H
+
+#include <iosfwd>
+
+/**
+ * Container for various SBuf class-wide statistics.
+ *
+ * The stats are not completely accurate; they're mostly meant to
+ * understand whether Squid is leaking resources
+ * and whether SBuf is paying off the expected gains.
+ */
+class SBufStats
+{
+public:
+    uint64_t alloc; ///<number of calls to SBuf constructors
+    uint64_t allocCopy; ///<number of calls to SBuf copy-constructor
+    uint64_t allocFromCString; ///<number of copy-allocations from c-strings
+    uint64_t assignFast; ///<number of no-copy assignment operations
+    uint64_t clear; ///<number of clear operations
+    uint64_t append; ///<number of append operations
+    uint64_t moves; ///<number of move constructions/assignments
+    uint64_t toStream;  ///<number of write operations to ostreams
+    uint64_t setChar; ///<number of calls to setAt
+    uint64_t getChar; ///<number of calls to at() and operator[]
+    uint64_t compareSlow; ///<number of comparison operations requiring data scan
+    uint64_t compareFast; ///<number of comparison operations not requiring data scan
+    uint64_t copyOut; ///<number of data-copies to other forms of buffers
+    uint64_t rawAccess; ///<number of accesses to raw contents
+    uint64_t nulTerminate; ///<number of c_str() terminations
+    uint64_t chop;  ///<number of chop operations
+    uint64_t trim;  ///<number of trim operations
+    uint64_t find;  ///<number of find operations
+    uint64_t scanf;  ///<number of scanf operations
+    uint64_t caseChange; ///<number of toUpper and toLower operations
+    uint64_t cowFast; ///<number of cow operations not actually requiring a copy
+    uint64_t cowSlow; ///<number of cow operations requiring a copy
+    uint64_t live;  ///<number of currently-allocated SBuf
+
+    ///Dump statistics to an ostream.
+    std::ostream& dump(std::ostream &os) const;
+    SBufStats();
+
+    SBufStats& operator +=(const SBufStats&);
+};
+
+#endif /* SQUID_SBUF_STATS_H */