From c738d9685aaa11d2a9cd756071524e92a3deec5e Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Thu, 25 Apr 2024 17:19:27 +0100 Subject: [PATCH 1/2] Format mgr:sbuf report as YAML --- src/SBufStatsAction.cc | 16 +++++------ src/sbuf/MemBlob.cc | 21 ++++++++------- src/sbuf/MemBlob.h | 2 +- src/sbuf/Stats.cc | 61 +++++++++++++++++++++--------------------- src/sbuf/Stats.h | 2 +- src/tests/stub_SBuf.cc | 2 +- 6 files changed, 50 insertions(+), 54 deletions(-) diff --git a/src/SBufStatsAction.cc b/src/SBufStatsAction.cc index c970e9d88e9..c7cb0e9a04f 100644 --- a/src/SBufStatsAction.cc +++ b/src/SBufStatsAction.cc @@ -85,22 +85,18 @@ statHistSBufDumper(StoreEntry * sentry, int, double val, double size, int count) { if (count == 0) return; - storeAppendPrintf(sentry, "\t%d-%d\t%d\n", static_cast(val), static_cast(val+size), count); + storeAppendPrintf(sentry, " %d-%d: %d\n", static_cast(val), static_cast(val+size), count); } void SBufStatsAction::dump(StoreEntry* entry) { - PackableStream ses(*entry); - ses << "\n\n\nThese statistics are experimental; their format and contents " - "should not be relied upon, they are bound to change as " - "the SBuf feature is evolved\n"; - sbdata.dump(ses); - mbdata.dump(ses); - ses << "\n"; - ses << "SBuf size distribution at destruct time:\n"; + PackableStream yaml(*entry); + sbdata.dump(yaml); + mbdata.dump(yaml); + yaml << "SBuf size distribution at destruct time:\n"; sbsizesatdestruct.dump(entry,statHistSBufDumper); - ses << "MemBlob capacity distribution at destruct time:\n"; + yaml << "MemBlob capacity distribution at destruct time:\n"; mbsizesatdestruct.dump(entry,statHistSBufDumper); } diff --git a/src/sbuf/MemBlob.cc b/src/sbuf/MemBlob.cc index 3bb1af36b7b..e4c00632f36 100644 --- a/src/sbuf/MemBlob.cc +++ b/src/sbuf/MemBlob.cc @@ -29,17 +29,18 @@ MemBlobStats::operator += (const MemBlobStats& s) return *this; } -std::ostream& -MemBlobStats::dump(std::ostream &os) const +void +MemBlobStats::dump(std::ostream &yaml) const { - os << - "MemBlob created: " << alloc << - "\nMemBlob alive: " << live << - "\nMemBlob append calls: " << append << - "\nMemBlob currently allocated size: " << liveBytes << - "\nlive MemBlob mean current allocation size: " << - (static_cast(liveBytes)/(live?live:1)) << std::endl; - return os; + std::string indent(" "); + yaml << + "MemBlob stats: " << '\n' << + indent << "allocations: " << alloc << '\n' << + indent << "live instances: " << live << '\n' << + indent << "append calls: " << append << '\n' << + indent << "cumulative size bytes: " << liveBytes << '\n' << + indent << "mean size: " << std::fixed << std::setprecision(1) << + (static_cast(liveBytes)/(live?live:1)) << '\n'; } static auto & diff --git a/src/sbuf/MemBlob.h b/src/sbuf/MemBlob.h index e9304b9b5b9..af1cca3257d 100644 --- a/src/sbuf/MemBlob.h +++ b/src/sbuf/MemBlob.h @@ -20,7 +20,7 @@ class MemBlobStats { public: /// dumps class-wide statistics - std::ostream& dump(std::ostream& os) const; + void dump(std::ostream& os) const; MemBlobStats& operator += (const MemBlobStats&); diff --git a/src/sbuf/Stats.cc b/src/sbuf/Stats.cc index 869cbdb91a7..12aeb27a9e1 100644 --- a/src/sbuf/Stats.cc +++ b/src/sbuf/Stats.cc @@ -61,38 +61,37 @@ SBufStats::operator +=(const SBufStats& ss) return *this; } -std::ostream & -SBufStats::dump(std::ostream& os) const +void +SBufStats::dump(std::ostream& yaml) 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 << - "\ncase-change ops: " << caseChange << - "\nCOW completely avoided: " << cowAvoided << - "\nCOW replaced with memmove(3): " << cowShift << - "\nCOW requiring an empty buffer allocation: " << cowJustAlloc << - "\nCOW requiring allocation and copying: " << cowAllocCopy << - "\naverage store share factor: " << - (ststats.live != 0 ? static_cast(live)/ststats.live : 0) << - std::endl; - return os; + const std::string indent(" "); + yaml << "SBuf stats:\n" << + indent << "allocations: " << alloc << '\n' << + indent << "copy-allocations: " << allocCopy << '\n' << + indent << "copy-allocations from cstring: " << allocFromCString << '\n' << + indent << "live references: " << live << '\n' << + indent << "no-copy assignments: " << assignFast << '\n' << + indent << "clearing operations: " << clear << '\n' << + indent << "append operations: " << append << '\n' << + indent << "move operations: " << moves << '\n' << + indent << "dump-to-ostream: " << toStream << '\n' << + indent << "set-char: " << setChar << '\n' << + indent << "get-char: " << getChar << '\n' << + indent << "comparisons with data-scan: " << compareSlow << '\n' << + indent << "comparisons not requiring data-scan: " << compareFast << '\n' << + indent << "copy-out ops: " << copyOut << '\n' << + indent << "raw access to memory: " << rawAccess << '\n' << + indent << "NULL terminate cstring: " << nulTerminate << '\n' << + indent << "chop operations: " << chop << '\n' << + indent << "trim operations: " << trim << '\n' << + indent << "find: " << find << '\n' << + indent << "case-change ops: " << caseChange << '\n' << + indent << "COW completely avoided: " << cowAvoided << '\n' << + indent << "COW replaced with memmove: " << cowShift << '\n' << + indent << "COW requiring an empty buffer allocation: " << cowJustAlloc << '\n' << + indent << "COW requiring allocation and copying: " << cowAllocCopy << '\n' << + indent << "average store share factor: " << std::fixed << std::setprecision(3) << + (ststats.live != 0 ? static_cast(live)/ststats.live : 0) << '\n'; } diff --git a/src/sbuf/Stats.h b/src/sbuf/Stats.h index e0169714038..d9ac944e5e1 100644 --- a/src/sbuf/Stats.h +++ b/src/sbuf/Stats.h @@ -22,7 +22,7 @@ class SBufStats { public: ///Dump statistics to an ostream. - std::ostream& dump(std::ostream &os) const; + void dump(std::ostream &) const; SBufStats& operator +=(const SBufStats&); diff --git a/src/tests/stub_SBuf.cc b/src/tests/stub_SBuf.cc index 9d0aec565b2..ceeb346280a 100644 --- a/src/tests/stub_SBuf.cc +++ b/src/tests/stub_SBuf.cc @@ -21,7 +21,7 @@ const SBuf::size_type SBuf::maxSize; SBufStats::SizeRecorder SBufStats::SBufSizeAtDestructRecorder = nullptr; SBufStats::SizeRecorder SBufStats::MemBlobSizeAtDestructRecorder = nullptr; -std::ostream& SBufStats::dump(std::ostream &os) const STUB_RETVAL(os) +void SBufStats::dump(std::ostream &) const STUB SBufStats& SBufStats::operator +=(const SBufStats&) STUB_RETVAL(*this) SBuf::SBuf() {} From 51133b24277709c614bc766579d064cb68cbd96e Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Fri, 26 Apr 2024 00:13:30 +0100 Subject: [PATCH 2/2] Source maintenance --- src/sbuf/MemBlob.cc | 14 ++++++------ src/sbuf/Stats.cc | 52 ++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/sbuf/MemBlob.cc b/src/sbuf/MemBlob.cc index e4c00632f36..2e8129a2510 100644 --- a/src/sbuf/MemBlob.cc +++ b/src/sbuf/MemBlob.cc @@ -34,13 +34,13 @@ MemBlobStats::dump(std::ostream &yaml) const { std::string indent(" "); yaml << - "MemBlob stats: " << '\n' << - indent << "allocations: " << alloc << '\n' << - indent << "live instances: " << live << '\n' << - indent << "append calls: " << append << '\n' << - indent << "cumulative size bytes: " << liveBytes << '\n' << - indent << "mean size: " << std::fixed << std::setprecision(1) << - (static_cast(liveBytes)/(live?live:1)) << '\n'; + "MemBlob stats: " << '\n' << + indent << "allocations: " << alloc << '\n' << + indent << "live instances: " << live << '\n' << + indent << "append calls: " << append << '\n' << + indent << "cumulative size bytes: " << liveBytes << '\n' << + indent << "mean size: " << std::fixed << std::setprecision(1) << + (static_cast(liveBytes)/(live?live:1)) << '\n'; } static auto & diff --git a/src/sbuf/Stats.cc b/src/sbuf/Stats.cc index 12aeb27a9e1..f7dd2e73d24 100644 --- a/src/sbuf/Stats.cc +++ b/src/sbuf/Stats.cc @@ -67,31 +67,31 @@ SBufStats::dump(std::ostream& yaml) const MemBlobStats ststats = MemBlob::GetStats(); const std::string indent(" "); yaml << "SBuf stats:\n" << - indent << "allocations: " << alloc << '\n' << - indent << "copy-allocations: " << allocCopy << '\n' << - indent << "copy-allocations from cstring: " << allocFromCString << '\n' << - indent << "live references: " << live << '\n' << - indent << "no-copy assignments: " << assignFast << '\n' << - indent << "clearing operations: " << clear << '\n' << - indent << "append operations: " << append << '\n' << - indent << "move operations: " << moves << '\n' << - indent << "dump-to-ostream: " << toStream << '\n' << - indent << "set-char: " << setChar << '\n' << - indent << "get-char: " << getChar << '\n' << - indent << "comparisons with data-scan: " << compareSlow << '\n' << - indent << "comparisons not requiring data-scan: " << compareFast << '\n' << - indent << "copy-out ops: " << copyOut << '\n' << - indent << "raw access to memory: " << rawAccess << '\n' << - indent << "NULL terminate cstring: " << nulTerminate << '\n' << - indent << "chop operations: " << chop << '\n' << - indent << "trim operations: " << trim << '\n' << - indent << "find: " << find << '\n' << - indent << "case-change ops: " << caseChange << '\n' << - indent << "COW completely avoided: " << cowAvoided << '\n' << - indent << "COW replaced with memmove: " << cowShift << '\n' << - indent << "COW requiring an empty buffer allocation: " << cowJustAlloc << '\n' << - indent << "COW requiring allocation and copying: " << cowAllocCopy << '\n' << - indent << "average store share factor: " << std::fixed << std::setprecision(3) << - (ststats.live != 0 ? static_cast(live)/ststats.live : 0) << '\n'; + indent << "allocations: " << alloc << '\n' << + indent << "copy-allocations: " << allocCopy << '\n' << + indent << "copy-allocations from cstring: " << allocFromCString << '\n' << + indent << "live references: " << live << '\n' << + indent << "no-copy assignments: " << assignFast << '\n' << + indent << "clearing operations: " << clear << '\n' << + indent << "append operations: " << append << '\n' << + indent << "move operations: " << moves << '\n' << + indent << "dump-to-ostream: " << toStream << '\n' << + indent << "set-char: " << setChar << '\n' << + indent << "get-char: " << getChar << '\n' << + indent << "comparisons with data-scan: " << compareSlow << '\n' << + indent << "comparisons not requiring data-scan: " << compareFast << '\n' << + indent << "copy-out ops: " << copyOut << '\n' << + indent << "raw access to memory: " << rawAccess << '\n' << + indent << "NULL terminate cstring: " << nulTerminate << '\n' << + indent << "chop operations: " << chop << '\n' << + indent << "trim operations: " << trim << '\n' << + indent << "find: " << find << '\n' << + indent << "case-change ops: " << caseChange << '\n' << + indent << "COW completely avoided: " << cowAvoided << '\n' << + indent << "COW replaced with memmove: " << cowShift << '\n' << + indent << "COW requiring an empty buffer allocation: " << cowJustAlloc << '\n' << + indent << "COW requiring allocation and copying: " << cowAllocCopy << '\n' << + indent << "average store share factor: " << std::fixed << std::setprecision(3) << + (ststats.live != 0 ? static_cast(live)/ststats.live : 0) << '\n'; }