@@ -111,6 +111,11 @@ namespace snmalloc
111111 */
112112 Ticker<typename Config::Pal> ticker;
113113
114+ /* *
115+ * Tracks this allocators memory usage
116+ */
117+ AllocStats stats;
118+
114119 /* *
115120 * The message queue needs to be accessible from other threads
116121 *
@@ -672,13 +677,14 @@ namespace snmalloc
672677 // pointers
673678 auto & entry =
674679 Config::Backend::template get_metaentry (snmalloc::address_cast (p));
675- if (SNMALLOC_LIKELY (dealloc_local_object_fast (entry, p, entropy)))
680+ if (SNMALLOC_LIKELY (dealloc_local_object_fast< false > (entry, p, entropy)))
676681 return ;
677682
678683 dealloc_local_object_slow (p, entry);
679684 }
680685
681- SNMALLOC_FAST_PATH static bool dealloc_local_object_fast (
686+ template <bool Statistics = true >
687+ SNMALLOC_FAST_PATH bool dealloc_local_object_fast (
682688 const PagemapEntry& entry,
683689 CapPtr<void , capptr::bounds::Alloc> p,
684690 LocalEntropy& entropy)
@@ -699,6 +705,10 @@ namespace snmalloc
699705 // Update the head and the next pointer in the free list.
700706 meta->free_queue .add (cp, key, entropy);
701707
708+ if constexpr (Statistics)
709+ {
710+ stats[entry.get_sizeclass ()].objects_deallocated ++;
711+ }
702712 return SNMALLOC_LIKELY (!meta->return_object ());
703713 }
704714
@@ -745,6 +755,7 @@ namespace snmalloc
745755 }
746756
747757 auto r = finish_alloc<zero_mem, Config>(p, sizeclass);
758+ stats[sizeclass].objects_allocated ++;
748759 return ticker.check_tick (r);
749760 }
750761 return small_alloc_slow<zero_mem>(sizeclass, fast_free_list);
@@ -817,6 +828,8 @@ namespace snmalloc
817828 }
818829
819830 auto r = finish_alloc<zero_mem, Config>(p, sizeclass);
831+
832+ stats[sizeclass].objects_allocated ++;
820833 return ticker.check_tick (r);
821834 }
822835
@@ -992,6 +1005,11 @@ namespace snmalloc
9921005
9931006 return debug_is_empty_impl (result);
9941007 }
1008+
1009+ const AllocStats& get_stats ()
1010+ {
1011+ return stats;
1012+ }
9951013 };
9961014
9971015 /* *
0 commit comments