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 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 String join(const Container& container, char joiner, bool esc_joiner = true) {