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;
|
auto total = 0;
|
||||||
write_to_debug_buffer("Memory usage:");
|
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)
|
for (int domain = 0; domain < (int)MemoryDomain::Count; ++domain)
|
||||||
{
|
{
|
||||||
auto& stats = memory_stats[domain];
|
auto& stats = memory_stats[domain];
|
||||||
total += stats.allocated_bytes;
|
total += stats.allocated_bytes;
|
||||||
write_to_debug_buffer(
|
write_to_debug_buffer(format("{} │{} │{} │{} ",
|
||||||
format(" {}: {} bytes, {} alloc active, {} alloc total",
|
left_pad(domain_name((MemoryDomain)domain), column_size),
|
||||||
domain_name((MemoryDomain)domain),
|
left_pad(to_string(stats.allocated_bytes), column_size),
|
||||||
stats.allocated_bytes,
|
left_pad(to_string(stats.allocation_count), column_size),
|
||||||
stats.allocation_count,
|
left_pad(to_string(stats.total_allocation_count), column_size)));
|
||||||
stats.total_allocation_count));
|
|
||||||
}
|
}
|
||||||
|
write_to_debug_buffer({});
|
||||||
write_to_debug_buffer(format(" Total: {}", total));
|
write_to_debug_buffer(format(" Total: {}", total));
|
||||||
#if defined(__GLIBC__) || defined(__CYGWIN__)
|
#if defined(__GLIBC__) || defined(__CYGWIN__)
|
||||||
write_to_debug_buffer(format(" Malloced: {}", mallinfo().uordblks));
|
write_to_debug_buffer(format(" Malloced: {}", mallinfo().uordblks));
|
||||||
|
|
|
@ -111,6 +111,16 @@ String replace(StringView str, StringView substr, StringView replacement)
|
||||||
return res;
|
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)
|
Optional<int> str_to_int_ifp(StringView str)
|
||||||
{
|
{
|
||||||
bool negative = not str.empty() and str[0] == '-';
|
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 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>
|
template<typename Container>
|
||||||
String join(const Container& container, char joiner, bool esc_joiner = true)
|
String join(const Container& container, char joiner, bool esc_joiner = true)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user