Skip to content

Commit

Permalink
Feat[MQB]: pass allocator stats to json
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeny Malygin <[email protected]>
  • Loading branch information
678098 committed Nov 13, 2024
1 parent 613c5ba commit b39399b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/groups/mqb/mqbstat/mqbstat_jsonprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
// MQB
#include <mqbstat_queuestats.h>

// BMQ
#include <bmqst_statutil.h>
#include <bmqu_memoutstream.h>

// BDE
Expand Down Expand Up @@ -169,6 +171,54 @@ struct ConversionUtils {
*domainIt);
}
}

inline static void
populateAllAllocatorsStats(bdljsn::JsonObject* parent,
const bmqst::StatContext& ctx)
{
// PRECONDITIONS
BSLS_ASSERT_SAFE(parent);

if (ctx.numValues() == 1) {
// BSLS_ASSERT_SAFE(ctx.valueName(0) == "Memory");

const bmqst::StatValue::SnapshotLocation latestSnapshot(0, 0);
const bmqst::StatValue& memory =
ctx.value(bmqst::StatContext::ValueType::e_TOTAL_VALUE, 0);

bslstl::StringRef nodeName = ctx.hasName() ? ctx.name()
: "UNDEFINED";
bdljsn::JsonObject& node = (*parent)[nodeName].makeObject();

node["numAllocated"].makeNumber() =
bmqst::StatUtil::value(memory, latestSnapshot);
node["maxAllocated"].makeNumber() = bmqst::StatUtil::absoluteMax(
memory);
node["numAllocations"].makeNumber() =
bmqst::StatUtil::increments(memory, latestSnapshot);
node["numDeallocations"].makeNumber() =
bmqst::StatUtil::decrements(memory, latestSnapshot);

if (ctx.numSubcontexts() > 0) {
bdljsn::JsonObject& childAllocators =
node["allocators"].makeObject();

for (bmqst::StatContextIterator allocIt =
ctx.subcontextIterator();
allocIt;
++allocIt) {
populateAllAllocatorsStats(&childAllocators, *allocIt);
}
}
}
else {
for (bmqst::StatContextIterator allocIt = ctx.subcontextIterator();
allocIt;
++allocIt) {
populateAllAllocatorsStats(parent, *allocIt);
}
}
}
};

} // close unnamed namespace
Expand Down Expand Up @@ -263,6 +313,16 @@ inline int JsonPrinter::JsonPrinterImpl::printStats(bsl::string* out,
ConversionUtils::populateAllDomainsStats(&domainQueuesObj, ctx);
}

{
bdljsn::JsonObject& allocatorsObj = obj["allocators"].makeObject();

StatContextsMap::const_iterator it = d_contexts.find("allocators");
if (it != d_contexts.end()) {
ConversionUtils::populateAllAllocatorsStats(&allocatorsObj,
*it->second);
}
}

const bdljsn::WriteOptions& ops = compact ? d_opsCompact : d_opsPretty;

bmqu::MemOutStream os;
Expand Down
14 changes: 14 additions & 0 deletions src/python/blazingmq/dev/it/process/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,17 @@ def stop(self) -> None:
if self._channel is not None:
self._channel.close()
self._channel = None


if __name__ == "__main__":
client = AdminClient()
client.connect("localhost", 30114)

while True:
cmd = input("Enter admin command:")
if len(cmd) == 0:
break
res = client.send_admin(cmd)
print(res)

client.stop()

0 comments on commit b39399b

Please sign in to comment.