1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-30 23:37:17 +03:00

Track more memory statistics

This commit is contained in:
Maxime Coste 2019-03-21 20:35:22 +11:00
parent 56611604b2
commit 31d67f51dd
3 changed files with 25 additions and 8 deletions

View File

@ -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__)

View File

@ -3,6 +3,6 @@
namespace Kakoune
{
size_t domain_allocated_bytes[(size_t)MemoryDomain::Count] = {};
MemoryStats memory_stats[(size_t)MemoryDomain::Count] = {};
}

View File

@ -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<typename T, MemoryDomain domain>