Skip to content

Commit

Permalink
chore: Add 'memory arena show' command (#3298)
Browse files Browse the repository at this point in the history
* chore: Add 'memory arena show' command

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

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Jul 10, 2024
1 parent 5d4b969 commit b61c722
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 23 additions & 8 deletions src/server/memory_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion src/server/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b61c722

Please sign in to comment.