Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format mgr:sbuf report as YAML #1795

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/SBufStatsAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(val), static_cast<int>(val+size), count);
storeAppendPrintf(sentry, " %d-%d: %d\n", static_cast<int>(val), static_cast<int>(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);
}

Expand Down
21 changes: 11 additions & 10 deletions src/sbuf/MemBlob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(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<double>(liveBytes)/(live?live:1)) << '\n';
}

static auto &
Expand Down
2 changes: 1 addition & 1 deletion src/sbuf/MemBlob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);

Expand Down
61 changes: 30 additions & 31 deletions src/sbuf/Stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(live)/ststats.live : 0) <<
std::endl;
return os;
const std::string indent(" ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use std::string in primary Squid code. In most cases (probably including this one), using SBuf is best. I am aware that this code reports SBuf stats.

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<float>(live)/ststats.live : 0) << '\n';
}

2 changes: 1 addition & 1 deletion src/sbuf/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);

Expand Down
2 changes: 1 addition & 1 deletion src/tests/stub_SBuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Loading