summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2020-05-19 17:16:37 +1000
committerMaxime Coste <mawww@kakoune.org>2020-05-19 17:16:37 +1000
commitaf175d2e7e8b32f5519aac6992ba337aaaff6361 (patch)
treea362cb5465914915b786edf0c7550f2a0b508b09 /src
parent5933ab1e780f8f2a51f6580e6fad249beea31698 (diff)
Output debug memory stats in a nice table
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc20
-rw-r--r--src/string_utils.cc10
-rw-r--r--src/string_utils.hh3
3 files changed, 27 insertions, 6 deletions
diff --git a/src/commands.cc b/src/commands.cc
index d6feb501..c5cd5fdb 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -1397,17 +1397,25 @@ const CommandDesc debug_cmd = {
{
auto total = 0;
write_to_debug_buffer("Memory usage:");
+ const ColumnCount column_size = 13;
+ write_to_debug_buffer(format("{} │{} │{} │{} ",
+ left_pad("domain", column_size),
+ left_pad("bytes", column_size),
+ left_pad("active allocs", column_size),
+ left_pad("total allocs", column_size)));
+ write_to_debug_buffer(format("{0}┼{0}┼{0}┼{0}", String(Codepoint{0x2500}, column_size + 1)));
+
for (int domain = 0; domain < (int)MemoryDomain::Count; ++domain)
{
auto& stats = memory_stats[domain];
total += stats.allocated_bytes;
- write_to_debug_buffer(
- format(" {}: {} bytes, {} alloc active, {} alloc total",
- domain_name((MemoryDomain)domain),
- stats.allocated_bytes,
- stats.allocation_count,
- stats.total_allocation_count));
+ write_to_debug_buffer(format("{} │{} │{} │{} ",
+ left_pad(domain_name((MemoryDomain)domain), column_size),
+ left_pad(to_string(stats.allocated_bytes), column_size),
+ left_pad(to_string(stats.allocation_count), column_size),
+ left_pad(to_string(stats.total_allocation_count), column_size)));
}
+ write_to_debug_buffer({});
write_to_debug_buffer(format(" Total: {}", total));
#if defined(__GLIBC__) || defined(__CYGWIN__)
write_to_debug_buffer(format(" Malloced: {}", mallinfo().uordblks));
diff --git a/src/string_utils.cc b/src/string_utils.cc
index 3ce98940..2ae8ea6f 100644
--- a/src/string_utils.cc
+++ b/src/string_utils.cc
@@ -111,6 +111,16 @@ String replace(StringView str, StringView substr, StringView replacement)
return res;
}
+String left_pad(StringView str, ColumnCount size, Codepoint c)
+{
+ return String(c, std::max(0_col, size - str.column_length())) + str.substr(0, size);
+}
+
+String right_pad(StringView str, ColumnCount size, Codepoint c)
+{
+ return str.substr(0, size) + String(c, std::max(0_col, size - str.column_length()));
+}
+
Optional<int> str_to_int_ifp(StringView str)
{
bool negative = not str.empty() and str[0] == '-';
diff --git a/src/string_utils.hh b/src/string_utils.hh
index 6f78b674..4da7ddc3 100644
--- a/src/string_utils.hh
+++ b/src/string_utils.hh
@@ -26,6 +26,9 @@ String indent(StringView str, StringView indent = " ");
String replace(StringView str, StringView substr, StringView replacement);
+String left_pad(StringView str, ColumnCount size, Codepoint c = ' ');
+String right_pad(StringView str, ColumnCount size, Codepoint c = ' ');
+
template<typename Container>
String join(const Container& container, char joiner, bool esc_joiner = true)
{