From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Thu, 18 Apr 2024 23:54:15 +0000 (+0000) Subject: Format mgr:pconn as YAML (#1780) X-Git-Tag: SQUID_7_0_1~138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a580c1301ad90b3fe41b518d42c10025a51793e;p=thirdparty%2Fsquid.git Format mgr:pconn as YAML (#1780) Also rework to rely on PackableStream --- diff --git a/src/pconn.cc b/src/pconn.cc index 2dfcda1609..3c1e951116 100644 --- a/src/pconn.cc +++ b/src/pconn.cc @@ -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(walker->key) << "\": " << + static_cast(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 &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); } diff --git a/src/pconn.h b/src/pconn.h index 7cd052b9c9..cd206b12d4 100644 --- a/src/pconn.h +++ b/src/pconn.h @@ -14,6 +14,7 @@ #include "mgr/forward.h" #include +#include /** \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 Pools; ///< unordered PconnPool collection diff --git a/src/tests/stub_pconn.cc b/src/tests/stub_pconn.cc index 291959db10..171ccf5526 100644 --- a/src/tests/stub_pconn.cc +++ b/src/tests/stub_pconn.cc @@ -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