diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index fad73521..cfeb6387 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -237,6 +237,7 @@ bool _mi_heap_area_visit_blocks(const mi_heap_area_t* area, mi_page_t* void _mi_heap_page_reclaim(mi_heap_t* heap, mi_page_t* page); // "stats.c" +void _mi_stats_init(void); void _mi_stats_done(mi_stats_t* stats); void _mi_stats_merge_thread(mi_tld_t* tld); void _mi_stats_merge_from(mi_stats_t* to, mi_stats_t* from); diff --git a/src/init.c b/src/init.c index 3ba67c8c..8336fdb9 100644 --- a/src/init.c +++ b/src/init.c @@ -709,6 +709,7 @@ void mi_process_init(void) mi_attr_noexcept { _mi_verbose_message("process init: 0x%zx\n", _mi_thread_id()); mi_detect_cpu_features(); + _mi_stats_init(); _mi_os_init(); _mi_page_map_init(); mi_heap_main_init(); diff --git a/src/stats.c b/src/stats.c index b1a7779d..6e4e8f74 100644 --- a/src/stats.c +++ b/src/stats.c @@ -386,6 +386,12 @@ static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0) static mi_msecs_t mi_process_start; // = 0 +// called on process init +void _mi_stats_init(void) { + if (mi_process_start == 0) { mi_process_start = _mi_clock_start(); }; +} + + // return thread local stats static mi_stats_t* mi_get_tld_stats(void) { return &_mi_thread_tld()->stats; @@ -396,9 +402,10 @@ void mi_stats_reset(void) mi_attr_noexcept { mi_subproc_t* subproc = _mi_subproc(); if (stats != &subproc->stats) { _mi_memzero(stats, sizeof(mi_stats_t)); } _mi_memzero(&subproc->stats, sizeof(mi_stats_t)); - if (mi_process_start == 0) { mi_process_start = _mi_clock_start(); }; + _mi_stats_init(); } + void _mi_stats_merge_from(mi_stats_t* to, mi_stats_t* from) { mi_assert_internal(to != NULL && from != NULL); if (to != from) {