diff --git a/src/commands.cc b/src/commands.cc index 5f65ac85..3336e38f 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1254,9 +1254,14 @@ const CommandDesc debug_cmd = { write_to_debug_buffer("Memory usage:"); for (int domain = 0; domain < (int)MemoryDomain::Count; ++domain) { - size_t count = domain_allocated_bytes[domain]; - total += count; - write_to_debug_buffer(format(" {}: {}", domain_name((MemoryDomain)domain), count)); + 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(" Total: {}", total)); #if defined(__GLIBC__) || defined(__CYGWIN__) diff --git a/src/memory.cc b/src/memory.cc index e2928412..38da3f60 100644 --- a/src/memory.cc +++ b/src/memory.cc @@ -3,6 +3,6 @@ namespace Kakoune { -size_t domain_allocated_bytes[(size_t)MemoryDomain::Count] = {}; +MemoryStats memory_stats[(size_t)MemoryDomain::Count] = {}; } diff --git a/src/memory.hh b/src/memory.hh index 0d0460bc..eae9826e 100644 --- a/src/memory.hh +++ b/src/memory.hh @@ -76,17 +76,29 @@ inline const char* domain_name(MemoryDomain domain) return ""; } -extern size_t domain_allocated_bytes[(size_t)MemoryDomain::Count]; +struct MemoryStats +{ + size_t allocated_bytes; + size_t allocation_count; + size_t total_allocation_count; +}; + +extern MemoryStats memory_stats[(size_t)MemoryDomain::Count]; inline void on_alloc(MemoryDomain domain, size_t size) { - domain_allocated_bytes[(int)domain] += size; + auto& stats = memory_stats[(int)domain]; + stats.allocated_bytes += size; + ++stats.allocation_count; + ++stats.total_allocation_count; } inline void on_dealloc(MemoryDomain domain, size_t size) { - kak_assert(domain_allocated_bytes[(int)domain] >= size); - domain_allocated_bytes[(int)domain] -= size; + auto& stats = memory_stats[(int)domain]; + kak_assert(stats.allocated_bytes >= size); + stats.allocated_bytes -= size; + --stats.allocation_count; } template