Skip to content

Commit d51e33b

Browse files
committed
add _mi_stats_init to initialize the process start time
1 parent 4bf6ae6 commit d51e33b

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

include/mimalloc/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ bool _mi_heap_area_visit_blocks(const mi_heap_area_t* area, mi_page_t*
237237
void _mi_heap_page_reclaim(mi_heap_t* heap, mi_page_t* page);
238238

239239
// "stats.c"
240+
void _mi_stats_init(void);
240241
void _mi_stats_done(mi_stats_t* stats);
241242
void _mi_stats_merge_thread(mi_tld_t* tld);
242243
void _mi_stats_merge_from(mi_stats_t* to, mi_stats_t* from);

src/init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ void mi_process_init(void) mi_attr_noexcept {
709709
_mi_verbose_message("process init: 0x%zx\n", _mi_thread_id());
710710

711711
mi_detect_cpu_features();
712+
_mi_stats_init();
712713
_mi_os_init();
713714
_mi_page_map_init();
714715
mi_heap_main_init();

src/stats.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0)
386386

387387
static mi_msecs_t mi_process_start; // = 0
388388

389+
// called on process init
390+
void _mi_stats_init(void) {
391+
if (mi_process_start == 0) { mi_process_start = _mi_clock_start(); };
392+
}
393+
394+
389395
// return thread local stats
390396
static mi_stats_t* mi_get_tld_stats(void) {
391397
return &_mi_thread_tld()->stats;
@@ -396,9 +402,10 @@ void mi_stats_reset(void) mi_attr_noexcept {
396402
mi_subproc_t* subproc = _mi_subproc();
397403
if (stats != &subproc->stats) { _mi_memzero(stats, sizeof(mi_stats_t)); }
398404
_mi_memzero(&subproc->stats, sizeof(mi_stats_t));
399-
if (mi_process_start == 0) { mi_process_start = _mi_clock_start(); };
405+
_mi_stats_init();
400406
}
401407

408+
402409
void _mi_stats_merge_from(mi_stats_t* to, mi_stats_t* from) {
403410
mi_assert_internal(to != NULL && from != NULL);
404411
if (to != from) {

0 commit comments

Comments
 (0)