Compare commits

...

1 Commits
main ... Pr1

Author SHA1 Message Date
Roman Gershman 06794e4719
chore(server): Improve malloc-stats output
Now it will print deduplicated lines, shortening the table
dramatically. Also it's now easier to import it into excel.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-10-08 17:27:53 +03:00
2 changed files with 23 additions and 10 deletions

View File

@ -8,6 +8,7 @@
#include <mimalloc.h>
#include "facade/error.h"
#include "server/engine_shard_set.h"
#include "server/server_state.h"
using namespace std;
@ -22,13 +23,15 @@ void MiStatsCallback(const char* msg, void* arg) {
absl::StrAppend(str, msg);
}
// blocksize, reserved, commited, used.
using BlockKey = std::tuple<size_t, size_t, size_t, size_t>;
using BlockMap = absl::flat_hash_map<BlockKey, uint64_t>;
bool MiArenaVisit(const mi_heap_t* heap, const mi_heap_area_t* area, void* block, size_t block_size,
void* arg) {
string* str = (string*)arg;
absl::StrAppend(str, "block_size ", block_size, ", reserved ",
area->reserved, ", comitted ", area->committed,
", used: ", area->used * block_size, "\n");
BlockMap* bmap = (BlockMap*)arg;
BlockKey bkey{block_size, area->reserved, area->committed, area->used * block_size};
(*bmap)[bkey]++;
return true;
};
@ -44,25 +47,35 @@ void MemoryCmd::Run(CmdArgList args) {
// dummy output, in practice not implemented yet.
return (*cntx_)->SendLong(1);
} else if (sub_cmd == "MALLOC-STATS") {
return MallocStats();
string res = shard_set->pool()->at(0)->AwaitBrief([this] { return MallocStats(); });
return (*cntx_)->SendBulkString(res);
}
string err = UnknownSubCmd(sub_cmd, "MEMORY");
return (*cntx_)->SendError(err, kSyntaxErrType);
}
void MemoryCmd::MallocStats() {
string MemoryCmd::MallocStats() {
string str;
absl::StrAppend(&str, "___ Begin mimalloc statistics ___\n");
mi_stats_print_out(MiStatsCallback, &str);
absl::StrAppend(&str, "\nArena statistics from a single thread:\n");
absl::StrAppend(&str, "Count BlockSize Reserved Committed Used\n");
mi_heap_t* data_heap = ServerState::tlocal()->data_heap();
mi_heap_visit_blocks(data_heap, false /* visit all blocks*/, MiArenaVisit, &str);
BlockMap block_map;
mi_heap_visit_blocks(data_heap, false /* visit all blocks*/, MiArenaVisit, &block_map);
for (const auto& k_v : block_map) {
absl::StrAppend(&str, k_v.second, " ", get<0>(k_v.first), " ", get<1>(k_v.first), " ",
get<2>(k_v.first), " ", get<3>(k_v.first), "\n");
}
absl::StrAppend(&str, "--- End mimalloc statistics ---\n");
return (*cntx_)->SendBulkString(str);
return str;
}
} // namespace dfly

View File

@ -17,7 +17,7 @@ class MemoryCmd {
void Run(CmdArgList args);
private:
void MallocStats();
std::string MallocStats();
ServerFamily& sf_;
ConnectionContext* cntx_;