chore: Add 'memory arena show' command (#3298)

* chore: Add 'memory arena show' command

Its output goes to stdout.
---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-07-10 10:20:17 +03:00 committed by GitHub
parent 5d4b969bee
commit b61c722f84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 9 deletions

View File

@ -100,9 +100,12 @@ void MemoryCmd::Run(CmdArgList args) {
" Shows breakdown of memory.",
"MALLOC-STATS",
" Show global malloc stats as provided by allocator libraries",
"ARENA [BACKING] [thread-id]",
"ARENA BACKING] [thread-id]",
" Show mimalloc arena stats for a heap residing in specified thread-id. 0 by default.",
" If BACKING is specified, show stats for the backing heap.",
"ARENA SHOW",
" Prints the arena summary report for the entire process.",
" Requires MIMALLOC_VERBOSE=1 environment to be set. The output goes to stdout",
"USAGE <key>",
" Show memory usage of a key.",
"DECOMMIT",
@ -321,20 +324,32 @@ void MemoryCmd::MallocStats() {
void MemoryCmd::ArenaStats(CmdArgList args) {
uint32_t tid = 0;
bool backing = false;
bool show_arenas = false;
if (args.size() >= 2) {
ToUpper(&args[1]);
unsigned tid_indx = 1;
if (ArgS(args, tid_indx) == "BACKING") {
++tid_indx;
backing = true;
}
if (ArgS(args, 1) == "SHOW") {
if (args.size() != 2)
return cntx_->SendError(kSyntaxErr, kSyntaxErrType);
show_arenas = true;
} else {
unsigned tid_indx = 1;
if (args.size() > tid_indx && !absl::SimpleAtoi(ArgS(args, tid_indx), &tid)) {
return cntx_->SendError(kInvalidIntErr);
if (ArgS(args, tid_indx) == "BACKING") {
++tid_indx;
backing = true;
}
if (args.size() > tid_indx && !absl::SimpleAtoi(ArgS(args, tid_indx), &tid)) {
return cntx_->SendError(kInvalidIntErr);
}
}
}
if (show_arenas) {
mi_debug_show_arenas(true, true, true);
return cntx_->reply_builder()->SendOk();
}
if (backing && tid >= shard_set->pool()->size()) {
return cntx_->SendError(
absl::StrCat("Thread id must be less than ", shard_set->pool()->size()));

View File

@ -181,7 +181,7 @@ void Transaction::InitGlobal() {
void Transaction::BuildShardIndex(const KeyIndex& key_index, std::vector<PerShardCache>* out) {
auto& shard_index = *out;
auto add = [this, &shard_index](uint32_t sid, uint32_t b, uint32_t e) {
auto add = [&shard_index](uint32_t sid, uint32_t b, uint32_t e) {
auto& slices = shard_index[sid].slices;
if (!slices.empty() && slices.back().second == b) {
slices.back().second = e;