diff --git a/include/mimalloc.h b/include/mimalloc.h index d58e15fd..5b3d13ed 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -153,7 +153,7 @@ mi_decl_export void mi_thread_init(void) mi_attr_noexcept; mi_decl_export void mi_thread_done(void) mi_attr_noexcept; mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept; -mi_decl_export void mi_process_info(double* user_time, double* system_time, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept; +mi_decl_export void mi_process_info(size_t* user_msecs, size_t* system_msecs, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept; // ------------------------------------------------------------------------------------- // Aligned allocation diff --git a/src/stats.c b/src/stats.c index b8e0ba77..842e2009 100644 --- a/src/stats.c +++ b/src/stats.c @@ -543,7 +543,7 @@ static void mi_stat_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* c #endif -mi_decl_export void mi_process_info(double* user_time, double* system_time, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept +mi_decl_export void mi_process_info(size_t* user_msecs, size_t* system_msecs, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept { mi_msecs_t utime = 0; mi_msecs_t stime = 0; @@ -553,8 +553,8 @@ mi_decl_export void mi_process_info(double* user_time, double* system_time, size size_t peak_commit0 = 0; size_t page_faults0 = 0; mi_stat_process_info(&utime, &stime, ¤t_rss0, &peak_rss0, ¤t_commit0, &peak_commit0, &page_faults0); - if (user_time!=NULL) *user_time = ((double)(utime/1000)) + (((double)(utime%1000))*1e-3); - if (system_time!=NULL) *system_time = ((double)(stime/1000)) + (((double)(stime%1000))*1e-3); + if (user_msecs!=NULL) *user_msecs = (utime < 0 ? 0 : (utime < (mi_msecs_t)SIZE_MAX ? (size_t)utime : SIZE_MAX)); + if (system_msecs!=NULL) *system_msecs = (stime < 0 ? 0 : (stime < (mi_msecs_t)SIZE_MAX ? (size_t)stime : SIZE_MAX)); if (current_rss!=NULL) *current_rss = current_rss0; if (peak_rss!=NULL) *peak_rss = peak_rss0; if (current_commit!=NULL) *current_commit = current_commit0; diff --git a/test/main-override-static.c b/test/main-override-static.c index 992a822e..0b73bb61 100644 --- a/test/main-override-static.c +++ b/test/main-override-static.c @@ -134,13 +134,17 @@ static void test_aslr(void) { } static void test_process_info(void) { - double utime = 0; - double stime = 0; + size_t user_msecs = 0; + size_t system_msecs = 0; size_t current_rss = 0; size_t peak_rss = 0; size_t current_commit = 0; size_t peak_commit = 0; - size_t page_faults = 0; - mi_process_info(&utime, &stime, ¤t_rss, &peak_rss, ¤t_commit, &peak_commit, &page_faults); - printf("process info: user: %.3f s, rss: %zd b, commit: %zd b\n\n", utime, peak_rss, peak_commit); + size_t page_faults = 0; + for (int i = 0; i < 100000; i++) { + void* p = calloc(100,10); + free(p); + } + mi_process_info(&user_msecs, &system_msecs, ¤t_rss, &peak_rss, ¤t_commit, &peak_commit, &page_faults); + printf("\n\n*** process info: user: %3zd.%03zd s, rss: %zd b, commit: %zd b\n\n", user_msecs/1000, user_msecs%1000, peak_rss, peak_commit); } \ No newline at end of file