@@ -62,6 +62,25 @@ void _mi_stat_decrease(mi_stat_count_t* stat, size_t amount) {
6262}
6363
6464
65+ static void mi_stat_adjust (mi_stat_count_t * stat , int64_t amount ) {
66+ if (amount == 0 ) return ;
67+ if mi_unlikely (mi_is_in_main (stat ))
68+ {
69+ // adjust atomically
70+ mi_atomic_addi64_relaxed (& stat -> current , amount );
71+ mi_atomic_addi64_relaxed (& stat -> total ,amount );
72+ }
73+ else {
74+ // adjust local
75+ stat -> current += amount ;
76+ stat -> total += amount ;
77+ }
78+ }
79+
80+ void _mi_stat_adjust_decrease (mi_stat_count_t * stat , size_t amount ) {
81+ mi_stat_adjust (stat , - ((int64_t )amount ));
82+ }
83+
6584
6685// must be thread safe as it is called from stats_merge
6786static void mi_stat_count_add_mt (mi_stat_count_t * stat , const mi_stat_count_t * src ) {
@@ -199,6 +218,13 @@ static void mi_stat_peak_print(const mi_stat_count_t* stat, const char* msg, int
199218 _mi_fprintf (out , arg , "\n" );
200219}
201220
221+ static void mi_stat_total_print (const mi_stat_count_t * stat , const char * msg , int64_t unit , mi_output_fun * out , void * arg ) {
222+ _mi_fprintf (out , arg , "%10s:" , msg );
223+ _mi_fprintf (out , arg , "%12s" , " " ); // no peak
224+ mi_print_amount (stat -> total , unit , out , arg );
225+ _mi_fprintf (out , arg , "\n" );
226+ }
227+
202228static void mi_stat_counter_print (const mi_stat_counter_t * stat , const char * msg , mi_output_fun * out , void * arg ) {
203229 _mi_fprintf (out , arg , "%10s:" , msg );
204230 mi_print_amount (stat -> total , -1 , out , arg );
@@ -295,7 +321,7 @@ static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0)
295321 mi_stat_print_ex (& total , "total" , 1 , out , arg , "" );
296322 #endif
297323 #if MI_STAT > 1
298- mi_stat_peak_print (& stats -> malloc_requested , "malloc req" , 1 , out , arg );
324+ mi_stat_total_print (& stats -> malloc_requested , "malloc req" , 1 , out , arg );
299325 _mi_fprintf (out , arg , "\n" );
300326 #endif
301327 mi_stat_print_ex (& stats -> reserved , "reserved" , 1 , out , arg , "" );
0 commit comments