From 527cd05fecd9749cb9d12dd2d5a8060a137cb2c0 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Sat, 1 Mar 2025 14:29:23 -0800 Subject: [PATCH 1/6] add git hash to compile defines --- CMakeLists.txt | 14 ++++++++++++++ src/init.c | 8 -------- src/options.c | 33 ++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb0dad9f..52647130 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,18 @@ else() set(mi_defines "") endif() +# pass git revision as a define +if(EXISTS "${CMAKE_SOURCE_DIR}/.git/index") + find_package(Git) + if(GIT_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} "describe" OUTPUT_VARIABLE mi_git_describe RESULT_VARIABLE mi_git_res ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if(mi_git_res EQUAL "0") + list(APPEND mi_defines "MI_GIT_DESCRIBE=${mi_git_describe}") + list(APPEND CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/index") # add to dependencies so we rebuild if the git rev changes + endif() + endif() +endif() + # ----------------------------------------------------------------------------- # Convenience: set default build type and compiler depending on the build directory # ----------------------------------------------------------------------------- @@ -492,6 +504,7 @@ else() endif() endif() + # ----------------------------------------------------------------------------- # Install and output names # ----------------------------------------------------------------------------- @@ -522,6 +535,7 @@ if(MI_TRACK_ASAN) set(mi_libname "${mi_libname}-asan") endif() string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC) +list(APPEND mi_defines "MI_CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE_LC}") #todo: multi-config project needs $ ? if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$")) set(mi_libname "${mi_libname}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version endif() diff --git a/src/init.c b/src/init.c index 03201707..dd3666fb 100644 --- a/src/init.c +++ b/src/init.c @@ -625,14 +625,6 @@ void mi_process_init(void) mi_attr_noexcept { mi_detect_cpu_features(); _mi_os_init(); mi_heap_main_init(); - #if MI_DEBUG - _mi_verbose_message("debug level : %d\n", MI_DEBUG); - #endif - _mi_verbose_message("secure level: %d\n", MI_SECURE); - _mi_verbose_message("mem tracking: %s\n", MI_TRACK_TOOL); - #if MI_TSAN - _mi_verbose_message("thread santizer enabled\n"); - #endif mi_thread_init(); #if defined(_WIN32) diff --git a/src/options.c b/src/options.c index 69247367..33e2bbce 100644 --- a/src/options.c +++ b/src/options.c @@ -175,7 +175,7 @@ void _mi_options_init(void) { mi_add_stderr_output(); // now it safe to use stderr for output for(int i = 0; i < _mi_option_last; i++ ) { mi_option_t option = (mi_option_t)i; - mi_option_get(option); // initialize + long l = mi_option_get(option); MI_UNUSED(l); // initialize } mi_max_error_count = mi_option_get(mi_option_max_errors); mi_max_warning_count = mi_option_get(mi_option_max_warnings); @@ -190,24 +190,47 @@ void _mi_options_init(void) { mi_options_print(); } -void mi_options_print(void) mi_attr_noexcept +#define mi_stringifyx(str) #str // and stringify +#define mi_stringify(str) mi_stringifyx(str) // expand + +void mi_options_print(void) mi_attr_noexcept { // show version const int vermajor = MI_MALLOC_VERSION/100; const int verminor = (MI_MALLOC_VERSION%100)/10; const int verpatch = (MI_MALLOC_VERSION%10); - _mi_verbose_message("v%i.%i.%i (built on %s, %s)\n", vermajor, verminor, verpatch, __DATE__, __TIME__); + _mi_verbose_message("v%i.%i.%i%s%s (built on %s, %s)\n", vermajor, verminor, verpatch, + #if defined(MI_CMAKE_BUILD_TYPE) + ", " mi_stringify(MI_CMAKE_BUILD_TYPE) + #else + "" + #endif + , + #if defined(MI_GIT_DESCRIBE) + ", git " mi_stringify(MI_GIT_DESCRIBE) + #else + "" + #endif + , __DATE__, __TIME__); // show options for (int i = 0; i < _mi_option_last; i++) { mi_option_t option = (mi_option_t)i; - mi_option_get(option); + long l = mi_option_get(option); MI_UNUSED(l); // possibly initialize mi_option_desc_t* desc = &options[option]; _mi_verbose_message("option '%s': %ld %s\n", desc->name, desc->value, (mi_option_has_size_in_kib(option) ? "KiB" : "")); - } + } + + // show build configuration + _mi_verbose_message("debug level : %d\n", MI_DEBUG ); + _mi_verbose_message("secure level: %d\n", MI_SECURE ); + _mi_verbose_message("mem tracking: %s\n", MI_TRACK_TOOL); #if MI_GUARDED _mi_verbose_message("guarded build: %s\n", mi_option_get(mi_option_guarded_sample_rate) != 0 ? "enabled" : "disabled"); #endif + #if MI_TSAN + _mi_verbose_message("thread santizer enabled\n"); + #endif } long _mi_option_get_fast(mi_option_t option) { From c2ae1c3539067d6e1d9d683fb0c93abec19c18a1 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Sat, 1 Mar 2025 14:31:24 -0800 Subject: [PATCH 2/6] fix git rev dependency in cmake configure --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52647130..2cf10569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,7 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git/index") execute_process(COMMAND ${GIT_EXECUTABLE} "describe" OUTPUT_VARIABLE mi_git_describe RESULT_VARIABLE mi_git_res ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if(mi_git_res EQUAL "0") list(APPEND mi_defines "MI_GIT_DESCRIBE=${mi_git_describe}") - list(APPEND CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/index") # add to dependencies so we rebuild if the git rev changes + set_property(GLOBAL APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/index") # add to dependencies so we rebuild if the git rev changes endif() endif() endif() From b0b9d9c22bf0070083933c4a9217309be9e5577c Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Sat, 1 Mar 2025 14:51:27 -0800 Subject: [PATCH 3/6] add note that git rev dependency doesnt work --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cf10569..900241b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,8 +84,11 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git/index") if(GIT_FOUND) execute_process(COMMAND ${GIT_EXECUTABLE} "describe" OUTPUT_VARIABLE mi_git_describe RESULT_VARIABLE mi_git_res ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if(mi_git_res EQUAL "0") + message(STATUS, "git describe: ${mi_git_describe}") list(APPEND mi_defines "MI_GIT_DESCRIBE=${mi_git_describe}") - set_property(GLOBAL APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/index") # add to dependencies so we rebuild if the git rev changes + # add to dependencies so we rebuild if the git head commit changes + # todo: this doesn't seem to work? + set_property(GLOBAL APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/index") endif() endif() endif() From 113800d1f052f3c0fa09b38d5e435730ed292fc3 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Sat, 1 Mar 2025 14:52:37 -0800 Subject: [PATCH 4/6] remove status message --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 900241b5..dbd400c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,10 +84,8 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git/index") if(GIT_FOUND) execute_process(COMMAND ${GIT_EXECUTABLE} "describe" OUTPUT_VARIABLE mi_git_describe RESULT_VARIABLE mi_git_res ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if(mi_git_res EQUAL "0") - message(STATUS, "git describe: ${mi_git_describe}") list(APPEND mi_defines "MI_GIT_DESCRIBE=${mi_git_describe}") # add to dependencies so we rebuild if the git head commit changes - # todo: this doesn't seem to work? set_property(GLOBAL APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/index") endif() endif() From bdaeb1d469f9ee42774b72138eca3f3cc380bebb Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Sat, 1 Mar 2025 16:29:28 -0800 Subject: [PATCH 5/6] remove stat_adjust --- include/mimalloc/types.h | 7 ------- src/stats.c | 27 --------------------------- 2 files changed, 34 deletions(-) diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index c8c10a2a..fdadcb35 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -612,9 +612,6 @@ typedef struct mi_stats_s { // add to stat keeping track of the peak void _mi_stat_increase(mi_stat_count_t* stat, size_t amount); void _mi_stat_decrease(mi_stat_count_t* stat, size_t amount); -// adjust stat in special cases to compensate for double counting -void _mi_stat_adjust_increase(mi_stat_count_t* stat, size_t amount); -void _mi_stat_adjust_decrease(mi_stat_count_t* stat, size_t amount); // counters can just be increased void _mi_stat_counter_increase(mi_stat_counter_t* stat, size_t amount); @@ -622,14 +619,10 @@ void _mi_stat_counter_increase(mi_stat_counter_t* stat, size_t amount); #define mi_stat_increase(stat,amount) _mi_stat_increase( &(stat), amount) #define mi_stat_decrease(stat,amount) _mi_stat_decrease( &(stat), amount) #define mi_stat_counter_increase(stat,amount) _mi_stat_counter_increase( &(stat), amount) -#define mi_stat_adjust_increase(stat,amount) _mi_stat_adjust_increase( &(stat), amount) -#define mi_stat_adjust_decrease(stat,amount) _mi_stat_adjust_decrease( &(stat), amount) #else #define mi_stat_increase(stat,amount) ((void)0) #define mi_stat_decrease(stat,amount) ((void)0) #define mi_stat_counter_increase(stat,amount) ((void)0) -#define mi_stat_adjuct_increase(stat,amount) ((void)0) -#define mi_stat_adjust_decrease(stat,amount) ((void)0) #endif #define mi_heap_stat_counter_increase(heap,stat,amount) mi_stat_counter_increase( (heap)->tld->stats.stat, amount) diff --git a/src/stats.c b/src/stats.c index 8566e8f2..e652c65f 100644 --- a/src/stats.c +++ b/src/stats.c @@ -51,27 +51,6 @@ static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) { } } -// Adjust stats to compensate; for example before committing a range, -// first adjust downwards with parts that were already committed so -// we avoid double counting. -static void mi_stat_adjust(mi_stat_count_t* stat, int64_t amount) { - if (amount == 0) return; - if mi_unlikely(mi_is_in_main(stat)) - { - // adjust atomically - mi_atomic_addi64_relaxed(&stat->current, amount); - mi_atomic_addi64_relaxed(&stat->allocated, amount); - mi_atomic_addi64_relaxed(&stat->freed, amount); - } - else { - // don't affect the peak - stat->current += amount; - // add to both - stat->allocated += amount; - stat->freed += amount; - } -} - void _mi_stat_counter_increase(mi_stat_counter_t* stat, size_t amount) { if (mi_is_in_main(stat)) { mi_atomic_addi64_relaxed( &stat->count, 1 ); @@ -91,13 +70,7 @@ void _mi_stat_decrease(mi_stat_count_t* stat, size_t amount) { mi_stat_update(stat, -((int64_t)amount)); } -void _mi_stat_adjust_increase(mi_stat_count_t* stat, size_t amount) { - mi_stat_adjust(stat, (int64_t)amount); -} -void _mi_stat_adjust_decrease(mi_stat_count_t* stat, size_t amount) { - mi_stat_adjust(stat, -((int64_t)amount)); -} // must be thread safe as it is called from stats_merge static void mi_stat_add(mi_stat_count_t* stat, const mi_stat_count_t* src, int64_t unit) { From 56aba086eaea3893e411f51bc9615663763592c7 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Sat, 1 Mar 2025 16:52:48 -0800 Subject: [PATCH 6/6] remove superfluous stat fields (count and freed) --- include/mimalloc/types.h | 4 +- src/init.c | 10 ++-- src/stats.c | 116 ++++++++++++++++++--------------------- 3 files changed, 59 insertions(+), 71 deletions(-) diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index fdadcb35..64ebb160 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -563,15 +563,13 @@ void _mi_assert_fail(const char* assertion, const char* fname, unsigned int line #endif typedef struct mi_stat_count_s { - int64_t allocated; - int64_t freed; + int64_t total; int64_t peak; int64_t current; } mi_stat_count_t; typedef struct mi_stat_counter_s { int64_t total; - int64_t count; } mi_stat_counter_t; typedef struct mi_stats_s { diff --git a/src/init.c b/src/init.c index dd3666fb..c25e7516 100644 --- a/src/init.c +++ b/src/init.c @@ -66,7 +66,7 @@ const mi_page_t _mi_page_empty = { QNULL(MI_LARGE_OBJ_WSIZE_MAX + 1 /* 655360, Huge queue */), \ QNULL(MI_LARGE_OBJ_WSIZE_MAX + 2) /* Full queue */ } -#define MI_STAT_COUNT_NULL() {0,0,0,0} +#define MI_STAT_COUNT_NULL() {0,0,0} // Empty statistics #if MI_STAT>1 @@ -84,10 +84,10 @@ const mi_page_t _mi_page_empty = { MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), \ MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), \ MI_STAT_COUNT_NULL(), \ - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ - { 0, 0 } \ + { 0 }, { 0 }, { 0 }, { 0 }, \ + { 0 }, { 0 }, { 0 }, { 0 }, \ + { 0 }, { 0 }, { 0 }, { 0 }, \ + { 0 } \ MI_STAT_COUNT_END_NULL() // -------------------------------------------------------- diff --git a/src/stats.c b/src/stats.c index e652c65f..1f3b928c 100644 --- a/src/stats.c +++ b/src/stats.c @@ -32,10 +32,7 @@ static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) { int64_t current = mi_atomic_addi64_relaxed(&stat->current, amount); mi_atomic_maxi64_relaxed(&stat->peak, current + amount); if (amount > 0) { - mi_atomic_addi64_relaxed(&stat->allocated,amount); - } - else { - mi_atomic_addi64_relaxed(&stat->freed, -amount); + mi_atomic_addi64_relaxed(&stat->total,amount); } } else { @@ -43,21 +40,16 @@ static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) { stat->current += amount; if (stat->current > stat->peak) stat->peak = stat->current; if (amount > 0) { - stat->allocated += amount; - } - else { - stat->freed += -amount; + stat->total += amount; } } } void _mi_stat_counter_increase(mi_stat_counter_t* stat, size_t amount) { if (mi_is_in_main(stat)) { - mi_atomic_addi64_relaxed( &stat->count, 1 ); mi_atomic_addi64_relaxed( &stat->total, (int64_t)amount ); } else { - stat->count++; stat->total += amount; } } @@ -73,58 +65,56 @@ void _mi_stat_decrease(mi_stat_count_t* stat, size_t amount) { // must be thread safe as it is called from stats_merge -static void mi_stat_add(mi_stat_count_t* stat, const mi_stat_count_t* src, int64_t unit) { +static void mi_stat_add(mi_stat_count_t* stat, const mi_stat_count_t* src) { if (stat==src) return; - if (src->allocated==0 && src->freed==0) return; - mi_atomic_addi64_relaxed( &stat->allocated, src->allocated * unit); - mi_atomic_addi64_relaxed( &stat->current, src->current * unit); - mi_atomic_addi64_relaxed( &stat->freed, src->freed * unit); - // peak scores do not work across threads.. - mi_atomic_addi64_relaxed( &stat->peak, src->peak * unit); + if (src->total==0) return; + mi_atomic_addi64_relaxed( &stat->total, src->total); + mi_atomic_addi64_relaxed( &stat->current, src->current); + // peak scores do really not work across threads ... we use conservative max + mi_atomic_maxi64_relaxed( &stat->peak, src->peak); // or: mi_atomic_addi64_relaxed( &stat->peak, src->peak); } -static void mi_stat_counter_add(mi_stat_counter_t* stat, const mi_stat_counter_t* src, int64_t unit) { +static void mi_stat_counter_add(mi_stat_counter_t* stat, const mi_stat_counter_t* src) { if (stat==src) return; - mi_atomic_addi64_relaxed( &stat->total, src->total * unit); - mi_atomic_addi64_relaxed( &stat->count, src->count * unit); + mi_atomic_addi64_relaxed( &stat->total, src->total); } // must be thread safe as it is called from stats_merge static void mi_stats_add(mi_stats_t* stats, const mi_stats_t* src) { if (stats==src) return; - mi_stat_add(&stats->segments, &src->segments,1); - mi_stat_add(&stats->pages, &src->pages,1); - mi_stat_add(&stats->reserved, &src->reserved, 1); - mi_stat_add(&stats->committed, &src->committed, 1); - mi_stat_add(&stats->reset, &src->reset, 1); - mi_stat_add(&stats->purged, &src->purged, 1); - mi_stat_add(&stats->page_committed, &src->page_committed, 1); + mi_stat_add(&stats->segments, &src->segments); + mi_stat_add(&stats->pages, &src->pages); + mi_stat_add(&stats->reserved, &src->reserved); + mi_stat_add(&stats->committed, &src->committed); + mi_stat_add(&stats->reset, &src->reset); + mi_stat_add(&stats->purged, &src->purged); + mi_stat_add(&stats->page_committed, &src->page_committed); - mi_stat_add(&stats->pages_abandoned, &src->pages_abandoned, 1); - mi_stat_add(&stats->segments_abandoned, &src->segments_abandoned, 1); - mi_stat_add(&stats->threads, &src->threads, 1); + mi_stat_add(&stats->pages_abandoned, &src->pages_abandoned); + mi_stat_add(&stats->segments_abandoned, &src->segments_abandoned); + mi_stat_add(&stats->threads, &src->threads); - mi_stat_add(&stats->malloc, &src->malloc, 1); - mi_stat_add(&stats->segments_cache, &src->segments_cache, 1); - mi_stat_add(&stats->normal, &src->normal, 1); - mi_stat_add(&stats->huge, &src->huge, 1); - mi_stat_add(&stats->giant, &src->giant, 1); + mi_stat_add(&stats->malloc, &src->malloc); + mi_stat_add(&stats->segments_cache, &src->segments_cache); + mi_stat_add(&stats->normal, &src->normal); + mi_stat_add(&stats->huge, &src->huge); + mi_stat_add(&stats->giant, &src->giant); - mi_stat_counter_add(&stats->pages_extended, &src->pages_extended, 1); - mi_stat_counter_add(&stats->mmap_calls, &src->mmap_calls, 1); - mi_stat_counter_add(&stats->commit_calls, &src->commit_calls, 1); - mi_stat_counter_add(&stats->reset_calls, &src->reset_calls, 1); - mi_stat_counter_add(&stats->purge_calls, &src->purge_calls, 1); + mi_stat_counter_add(&stats->pages_extended, &src->pages_extended); + mi_stat_counter_add(&stats->mmap_calls, &src->mmap_calls); + mi_stat_counter_add(&stats->commit_calls, &src->commit_calls); + mi_stat_counter_add(&stats->reset_calls, &src->reset_calls); + mi_stat_counter_add(&stats->purge_calls, &src->purge_calls); - mi_stat_counter_add(&stats->page_no_retire, &src->page_no_retire, 1); - mi_stat_counter_add(&stats->searches, &src->searches, 1); - mi_stat_counter_add(&stats->normal_count, &src->normal_count, 1); - mi_stat_counter_add(&stats->huge_count, &src->huge_count, 1); - mi_stat_counter_add(&stats->guarded_alloc_count, &src->guarded_alloc_count, 1); + mi_stat_counter_add(&stats->page_no_retire, &src->page_no_retire); + mi_stat_counter_add(&stats->searches, &src->searches); + mi_stat_counter_add(&stats->normal_count, &src->normal_count); + mi_stat_counter_add(&stats->huge_count, &src->huge_count); + mi_stat_counter_add(&stats->guarded_alloc_count, &src->guarded_alloc_count); #if MI_STAT>1 for (size_t i = 0; i <= MI_BIN_HUGE; i++) { - if (src->normal_bins[i].allocated > 0 || src->normal_bins[i].freed > 0) { - mi_stat_add(&stats->normal_bins[i], &src->normal_bins[i], 1); + if (src->normal_bins[i].total > 0) { + mi_stat_add(&stats->normal_bins[i], &src->normal_bins[i]); } } #endif @@ -180,26 +170,26 @@ static void mi_stat_print_ex(const mi_stat_count_t* stat, const char* msg, int64 if (unit != 0) { if (unit > 0) { 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->total, 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); + mi_print_count(stat->total, unit, out, arg); } else { 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->total, -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, "%24s", ""); } else { mi_print_amount(-unit, 1, out, arg); - mi_print_count((stat->allocated / -unit), 0, out, arg); + mi_print_count((stat->total / -unit), 0, out, arg); } } - if (stat->allocated > stat->freed) { + if (stat->current != 0) { _mi_fprintf(out, arg, " "); _mi_fprintf(out, arg, (notok == NULL ? "not all freed" : notok)); _mi_fprintf(out, arg, "\n"); @@ -210,7 +200,7 @@ static void mi_stat_print_ex(const mi_stat_count_t* stat, const char* msg, int64 } else { mi_print_amount(stat->peak, 1, out, arg); - mi_print_amount(stat->allocated, 1, out, arg); + mi_print_amount(stat->total, 1, out, arg); _mi_fprintf(out, arg, "%11s", " "); // no freed mi_print_amount(stat->current, 1, out, arg); _mi_fprintf(out, arg, "\n"); @@ -235,7 +225,7 @@ static void mi_stat_counter_print(const mi_stat_counter_t* stat, const char* msg static void mi_stat_counter_print_avg(const mi_stat_counter_t* stat, const char* msg, mi_output_fun* out, void* arg) { - const int64_t avg_tens = (stat->count == 0 ? 0 : (stat->total*10 / stat->count)); + const int64_t avg_tens = (stat->total == 0 ? 0 : (stat->total*10 / stat->total)); const long avg_whole = (long)(avg_tens/10); const long avg_frac1 = (long)(avg_tens%10); _mi_fprintf(out, arg, "%10s: %5ld.%ld avg\n", msg, avg_whole, avg_frac1); @@ -243,7 +233,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: %11s %11s %11s %11s %11s %11s\n", "heap stats", "peak ", "total ", "freed ", "current ", "unit ", "count "); + _mi_fprintf(out, arg, "%10s: %11s %11s %11s %11s %11s\n", "heap stats", "peak ", "total ", "current ", "unit ", "total# "); } #if MI_STAT>1 @@ -251,7 +241,7 @@ static void mi_stats_print_bins(const mi_stat_count_t* bins, size_t max, const c bool found = false; char buf[64]; for (size_t i = 0; i <= max; i++) { - if (bins[i].allocated > 0) { + if (bins[i].total > 0) { found = true; int64_t unit = _mi_bin_size((uint8_t)i); _mi_snprintf(buf, 64, "%s %3lu", fmt, (long)i); @@ -315,11 +305,11 @@ static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0) mi_stats_print_bins(stats->normal_bins, MI_BIN_HUGE, "normal",out,arg); #endif #if MI_STAT - mi_stat_print(&stats->normal, "normal", (stats->normal_count.count == 0 ? 1 : -(stats->normal.allocated / stats->normal_count.count)), out, arg); - mi_stat_print(&stats->huge, "huge", (stats->huge_count.count == 0 ? 1 : -(stats->huge.allocated / stats->huge_count.count)), out, arg); - mi_stat_count_t total = { 0,0,0,0 }; - mi_stat_add(&total, &stats->normal, 1); - mi_stat_add(&total, &stats->huge, 1); + mi_stat_print(&stats->normal, "normal", (stats->normal_count.total == 0 ? 1 : -1), out, arg); + mi_stat_print(&stats->huge, "huge", (stats->huge_count.total == 0 ? 1 : -1), out, arg); + mi_stat_count_t total = { 0,0,0 }; + mi_stat_add(&total, &stats->normal); + mi_stat_add(&total, &stats->huge); mi_stat_print(&total, "total", 1, out, arg); #endif #if MI_STAT>1