Skip to content

Commit c82afdd

Browse files
committed
Improve stats
1 parent e78e2e8 commit c82afdd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/snmalloc/mem/globalalloc.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,17 @@ namespace snmalloc
153153
template<SNMALLOC_CONCEPT(IsConfig) Config>
154154
inline static void print_alloc_stats()
155155
{
156+
static std::atomic<size_t> dump{0};
157+
158+
auto l_dump = dump++;
159+
if (l_dump == 0)
160+
{
161+
message<1024>("snmalloc_allocs,dumpid,sizeclass,size,allocated,deallocated,in_use,bytes");
162+
message<1024>("snmalloc_totals,dumpid,backend bytes,peak backend bytes,requested");
163+
}
164+
156165
auto stats = snmalloc::get_stats<Config>();
166+
size_t total_live{0};
157167
for (size_t i = 0; i < snmalloc::SIZECLASS_REP_SIZE; i++)
158168
{
159169
auto sc = snmalloc::sizeclass_t::from_raw(i);
@@ -164,7 +174,10 @@ namespace snmalloc
164174
auto size =
165175
snmalloc::sizeclass_full_to_size(snmalloc::sizeclass_t::from_raw(i));
166176
auto in_use = allocated - deallocated;
167-
snmalloc::message<1024>("SNMALLOCallocs,{},{},{},{},{}", i, size, allocated, deallocated, in_use);
177+
auto amount = in_use * size;
178+
total_live += amount;
179+
snmalloc::message<1024>("snmalloc_allocs,{},{},{},{},{},{},{}", l_dump, i, size, allocated, deallocated, in_use,amount);
168180
}
181+
snmalloc::message<1024>("snmalloc_totals,{},{},{},{}", l_dump, Config::Backend::get_current_usage(), Config::Backend::get_peak_usage(), total_live);
169182
}
170183
} // namespace snmalloc

0 commit comments

Comments
 (0)