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.", " Shows breakdown of memory.",
"MALLOC-STATS", "MALLOC-STATS",
" Show global malloc stats as provided by allocator libraries", " 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.", " 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.", " 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>", "USAGE <key>",
" Show memory usage of a key.", " Show memory usage of a key.",
"DECOMMIT", "DECOMMIT",
@ -321,20 +324,32 @@ void MemoryCmd::MallocStats() {
void MemoryCmd::ArenaStats(CmdArgList args) { void MemoryCmd::ArenaStats(CmdArgList args) {
uint32_t tid = 0; uint32_t tid = 0;
bool backing = false; bool backing = false;
bool show_arenas = false;
if (args.size() >= 2) { if (args.size() >= 2) {
ToUpper(&args[1]); ToUpper(&args[1]);
unsigned tid_indx = 1; if (ArgS(args, 1) == "SHOW") {
if (ArgS(args, tid_indx) == "BACKING") { if (args.size() != 2)
++tid_indx; return cntx_->SendError(kSyntaxErr, kSyntaxErrType);
backing = true; show_arenas = true;
} } else {
unsigned tid_indx = 1;
if (args.size() > tid_indx && !absl::SimpleAtoi(ArgS(args, tid_indx), &tid)) { if (ArgS(args, tid_indx) == "BACKING") {
return cntx_->SendError(kInvalidIntErr); ++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()) { if (backing && tid >= shard_set->pool()->size()) {
return cntx_->SendError( return cntx_->SendError(
absl::StrCat("Thread id must be less than ", shard_set->pool()->size())); 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) { void Transaction::BuildShardIndex(const KeyIndex& key_index, std::vector<PerShardCache>* out) {
auto& shard_index = *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; auto& slices = shard_index[sid].slices;
if (!slices.empty() && slices.back().second == b) { if (!slices.empty() && slices.back().second == b) {
slices.back().second = e; slices.back().second = e;