]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Format mgr:pconn as YAML (#1780) auto master
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Thu, 18 Apr 2024 23:54:15 +0000 (23:54 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 19 Apr 2024 02:07:50 +0000 (02:07 +0000)
Also rework to rely on PackableStream

src/pconn.cc
src/pconn.h
src/tests/stub_pconn.cc

index 2dfcda160971be1cc108a48771f92063bade84cd..3c1e95111696884d15b78538a86f49abb891d102 100644 (file)
@@ -9,6 +9,8 @@
 /* DEBUG: section 48    Persistent Connections */
 
 #include "squid.h"
+#include "base/IoManip.h"
+#include "base/PackableStream.h"
 #include "CachePeer.h"
 #include "comm.h"
 #include "comm/Connection.h"
@@ -348,36 +350,43 @@ PconnPool::key(const Comm::ConnectionPointer &destLink, const char *domain)
 }
 
 void
-PconnPool::dumpHist(StoreEntry * e) const
+PconnPool::dumpHist(std::ostream &yaml) const
 {
-    storeAppendPrintf(e,
-                      "%s persistent connection counts:\n"
-                      "\n"
-                      "\t Requests\t Connection Count\n"
-                      "\t --------\t ----------------\n",
-                      descr);
+    AtMostOnce heading(
+        "  connection use histogram:\n"
+        "    # requests per connection: closed connections that carried that many requests\n");
 
     for (int i = 0; i < PCONN_HIST_SZ; ++i) {
         if (hist[i] == 0)
             continue;
 
-        storeAppendPrintf(e, "\t%d\t%d\n", i, hist[i]);
+        yaml << heading <<
+             "    " << i << ": " << hist[i] << "\n";
     }
 }
 
 void
-PconnPool::dumpHash(StoreEntry *e) const
+PconnPool::dumpHash(std::ostream &yaml) const
 {
-    hash_table *hid = table;
+    const auto hid = table;
     hash_first(hid);
-
-    int i = 0;
-    for (hash_link *walker = hash_next(hid); walker; walker = hash_next(hid)) {
-        storeAppendPrintf(e, "\t item %d:\t%s\n", i, (char *)(walker->key));
-        ++i;
+    AtMostOnce title("  open connections list:\n");
+    for (auto *walker = hash_next(hid); walker; walker = hash_next(hid)) {
+        yaml << title <<
+             "    \"" << static_cast<char *>(walker->key) << "\": " <<
+             static_cast<IdleConnList *>(walker)->count() <<
+             "\n";
     }
 }
 
+void
+PconnPool::dump(std::ostream &yaml) const
+{
+    yaml << "pool " << descr << ":\n";
+    dumpHist(yaml);
+    dumpHash(yaml);
+}
+
 /* ========== PconnPool PUBLIC FUNCTIONS ============================================ */
 
 PconnPool::PconnPool(const char *aDescr, const CbcPointer<PeerPoolMgr> &aMgr):
@@ -582,22 +591,16 @@ PconnModule::remove(PconnPool *aPool)
 }
 
 void
-PconnModule::dump(StoreEntry *e)
-{
-    typedef Pools::const_iterator PCI;
-    int i = 0; // TODO: Why number pools if they all have names?
-    for (PCI p = pools.begin(); p != pools.end(); ++p, ++i) {
-        // TODO: Let each pool dump itself the way it wants to.
-        storeAppendPrintf(e, "\n Pool %d Stats\n", i);
-        (*p)->dumpHist(e);
-        storeAppendPrintf(e, "\n Pool %d Hash Table\n",i);
-        (*p)->dumpHash(e);
-    }
+PconnModule::dump(std::ostream &yaml)
+{
+    for (const auto &p: pools)
+        p->dump(yaml);
 }
 
 void
 PconnModule::DumpWrapper(StoreEntry *e)
 {
-    PconnModule::GetInstance()->dump(e);
+    PackableStream yaml(*e);
+    PconnModule::GetInstance()->dump(yaml);
 }
 
index 7cd052b9c95d076604f00f0a3757dda4d1bf69b5..cd206b12d48979caaa84e76d460cdf3248422634 100644 (file)
@@ -14,6 +14,7 @@
 #include "mgr/forward.h"
 
 #include <set>
+#include <iosfwd>
 
 /**
  \defgroup PConnAPI Persistent Connection API
@@ -133,8 +134,7 @@ public:
      */
     Comm::ConnectionPointer pop(const Comm::ConnectionPointer &dest, const char *domain, bool keepOpen);
     void count(int uses);
-    void dumpHist(StoreEntry *e) const;
-    void dumpHash(StoreEntry *e) const;
+    void dump(std::ostream &) const;
     void unlinkList(IdleConnList *list);
     void noteUses(int uses);
     /// closes any n connections, regardless of their destination
@@ -151,6 +151,8 @@ private:
     static const char *key(const Comm::ConnectionPointer &destLink, const char *domain);
 
     Comm::ConnectionPointer popStored(const Comm::ConnectionPointer &dest, const char *domain, const bool keepOpen);
+    void dumpHist(std::ostream &) const;
+    void dumpHash(std::ostream &) const;
 
     int hist[PCONN_HIST_SZ];
     hash_table *table;
@@ -182,7 +184,7 @@ public:
     void add(PconnPool *);
     void remove(PconnPool *); ///< unregister and forget about this pool object
 
-    OBJH dump;
+    void dump(std::ostream &yaml);
 
 private:
     typedef std::set<PconnPool*> Pools; ///< unordered PconnPool collection
index 291959db10810f8a6a4c682cf20688e8281e01af..171ccf55269b068c619904b53fce99108105bee2 100644 (file)
@@ -29,13 +29,12 @@ void PconnPool::push(const Comm::ConnectionPointer &, const char *) STUB
 Comm::ConnectionPointer PconnPool::pop(const Comm::ConnectionPointer &, const char *, bool) STUB_RETVAL(Comm::ConnectionPointer())
 void PconnPool::count(int) STUB
 void PconnPool::noteUses(int) STUB
-void PconnPool::dumpHist(StoreEntry *) const STUB
-void PconnPool::dumpHash(StoreEntry *) const STUB
+void PconnPool::dump(std::ostream&) const STUB
 void PconnPool::unlinkList(IdleConnList *) STUB
 PconnModule * PconnModule::GetInstance() STUB_RETVAL(nullptr)
 void PconnModule::DumpWrapper(StoreEntry *) STUB
 PconnModule::PconnModule() STUB
 void PconnModule::registerWithCacheManager(void) STUB
 void PconnModule::add(PconnPool *) STUB
-void PconnModule::dump(StoreEntry *) STUB
+void PconnModule::dump(std::ostream &) STUB