Track more memory statistics
This commit is contained in:
parent
56611604b2
commit
31d67f51dd
|
@ -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__)
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
size_t domain_allocated_bytes[(size_t)MemoryDomain::Count] = {};
|
||||
MemoryStats memory_stats[(size_t)MemoryDomain::Count] = {};
|
||||
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user