mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-27 02:23:26 +03:00
Output debug memory stats in a nice table
This commit is contained in:
parent
5933ab1e78
commit
af175d2e7e
@ -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));
|
||||
|
@ -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] == '-';
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user