From d9a062452979a34cd8d5f882c9b5acca5478cc13 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Mon, 2 Nov 2020 00:24:24 +0300 Subject: [PATCH 1/3] Print current values of stat counters as well. For some reasons unknown to me the current values of stat counters are never printed. This makes is quite hard to use printing during the debugging in the middle of program run. --- src/stats.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stats.c b/src/stats.c index b04822cc..b083b26a 100644 --- a/src/stats.c +++ b/src/stats.c @@ -167,6 +167,7 @@ static void mi_print_count(int64_t n, int64_t unit, mi_output_fun* out, void* ar static void mi_stat_print(const mi_stat_count_t* stat, const char* msg, int64_t unit, mi_output_fun* out, void* arg ) { _mi_fprintf(out, arg,"%10s:", msg); if (unit>0) { + mi_print_amount(stat->current, unit, out, arg); mi_print_amount(stat->peak, unit, out, arg); mi_print_amount(stat->allocated, unit, out, arg); mi_print_amount(stat->freed, unit, out, arg); @@ -178,6 +179,7 @@ static void mi_stat_print(const mi_stat_count_t* stat, const char* msg, int64_t _mi_fprintf(out, arg, " ok\n"); } else if (unit<0) { + mi_print_amount(stat->current, -1, out, arg); mi_print_amount(stat->peak, -1, out, arg); mi_print_amount(stat->allocated, -1, out, arg); mi_print_amount(stat->freed, -1, out, arg); @@ -194,6 +196,7 @@ static void mi_stat_print(const mi_stat_count_t* stat, const char* msg, int64_t _mi_fprintf(out, arg, " ok\n"); } else { + mi_print_amount(stat->current, 1, out, arg); mi_print_amount(stat->peak, 1, out, arg); mi_print_amount(stat->allocated, 1, out, arg); _mi_fprintf(out, arg, "\n"); @@ -215,7 +218,7 @@ static void mi_stat_counter_print_avg(const mi_stat_counter_t* stat, const char* static void mi_print_header(mi_output_fun* out, void* arg ) { - _mi_fprintf(out, arg, "%10s: %10s %10s %10s %10s %10s\n", "heap stats", "peak ", "total ", "freed ", "unit ", "count "); + _mi_fprintf(out, arg, "%10s: %10s %10s %10s %10s %10s %10s\n", "heap stats", "current ", "peak ", "total ", "freed ", "unit ", "count "); } #if MI_STAT>1 From f68c1a74da7279f32550fe0b1eeb334079bf2687 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 29 Jan 2021 14:33:49 -0800 Subject: [PATCH 2/3] fix assertion comparison (#353) --- src/heap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/heap.c b/src/heap.c index db1b773e..54562d10 100644 --- a/src/heap.c +++ b/src/heap.c @@ -359,7 +359,7 @@ static void mi_heap_absorb(mi_heap_t* heap, mi_heap_t* from) { // turns out to be ok as `_mi_heap_delayed_free` only visits the list and calls a // the regular `_mi_free_delayed_block` which is safe. _mi_heap_delayed_free(from); - mi_assert_internal(from->thread_delayed_free == NULL); + mi_assert_internal(mi_atomic_load_ptr_relaxed(mi_block_t,&from->thread_delayed_free) == NULL); // and reset the `from` heap mi_heap_reset_pages(from); From a6fa7b083eaaf9787901105338d1fdafe46c3882 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 29 Jan 2021 14:45:16 -0800 Subject: [PATCH 3/3] make current stat the third column instead of first --- src/stats.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/stats.c b/src/stats.c index fc457d05..091ad173 100644 --- a/src/stats.c +++ b/src/stats.c @@ -151,7 +151,7 @@ static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void* const int64_t tens = (n / (divider/10)); const long whole = (long)(tens/10); const long frac1 = (long)(tens%10); - snprintf(buf, len, "%ld.%ld %s%s", whole, frac1, magnitude, suffix); + snprintf(buf, len, "%ld.%ld %s%s", whole, (frac1 < 0 ? -frac1 : frac1), magnitude, suffix); } _mi_fprintf(out, arg, (fmt==NULL ? "%11s" : fmt), buf); } @@ -169,10 +169,10 @@ static void mi_print_count(int64_t n, int64_t unit, mi_output_fun* out, void* ar static void mi_stat_print(const mi_stat_count_t* stat, const char* msg, int64_t unit, mi_output_fun* out, void* arg ) { _mi_fprintf(out, arg,"%10s:", msg); if (unit>0) { - mi_print_amount(stat->current, unit, out, arg); mi_print_amount(stat->peak, unit, out, arg); mi_print_amount(stat->allocated, unit, out, arg); mi_print_amount(stat->freed, unit, out, arg); + mi_print_amount(stat->current, unit, out, arg); mi_print_amount(unit, 1, out, arg); mi_print_count(stat->allocated, unit, out, arg); if (stat->allocated > stat->freed) @@ -181,10 +181,10 @@ static void mi_stat_print(const mi_stat_count_t* stat, const char* msg, int64_t _mi_fprintf(out, arg, " ok\n"); } else if (unit<0) { - mi_print_amount(stat->current, -1, out, arg); mi_print_amount(stat->peak, -1, out, arg); mi_print_amount(stat->allocated, -1, out, arg); mi_print_amount(stat->freed, -1, out, arg); + mi_print_amount(stat->current, -1, out, arg); if (unit==-1) { _mi_fprintf(out, arg, "%22s", ""); } @@ -198,9 +198,10 @@ static void mi_stat_print(const mi_stat_count_t* stat, const char* msg, int64_t _mi_fprintf(out, arg, " ok\n"); } else { - mi_print_amount(stat->current, 1, out, arg); mi_print_amount(stat->peak, 1, out, arg); mi_print_amount(stat->allocated, 1, out, arg); + _mi_fprintf(out, arg, "%11s", " "); // no freed + mi_print_amount(stat->current, 1, out, arg); _mi_fprintf(out, arg, "\n"); } } @@ -220,7 +221,7 @@ static void mi_stat_counter_print_avg(const mi_stat_counter_t* stat, const char* static void mi_print_header(mi_output_fun* out, void* arg ) { - _mi_fprintf(out, arg, "%10s: %10s %10s %10s %10s %10s %10s\n", "heap stats", "current ", "peak ", "total ", "freed ", "unit ", "count "); + _mi_fprintf(out, arg, "%10s: %10s %10s %10s %10s %10s %10s\n", "heap stats", "peak ", "total ", "freed ", "current ", "unit ", "count "); } #if MI_STAT>1