add _mi_stats_init to initialize the process start time

This commit is contained in:
daanx 2025-05-21 19:11:47 -07:00
parent 4bf6ae693a
commit d51e33b18e
3 changed files with 10 additions and 1 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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) {