/* 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"
}
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):
}
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);
}
#include "mgr/forward.h"
#include <set>
+#include <iosfwd>
/**
\defgroup PConnAPI Persistent Connection API
*/
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
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;
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
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