update mi_process_info to not use doubles

This commit is contained in:
daan 2020-09-06 13:53:02 -07:00
parent ee286919d9
commit 46ee8952eb
3 changed files with 13 additions and 9 deletions

View File

@ -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_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_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 // Aligned allocation

View File

@ -543,7 +543,7 @@ static void mi_stat_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* c
#endif #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 utime = 0;
mi_msecs_t stime = 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 peak_commit0 = 0;
size_t page_faults0 = 0; size_t page_faults0 = 0;
mi_stat_process_info(&utime, &stime, &current_rss0, &peak_rss0, &current_commit0, &peak_commit0, &page_faults0); mi_stat_process_info(&utime, &stime, &current_rss0, &peak_rss0, &current_commit0, &peak_commit0, &page_faults0);
if (user_time!=NULL) *user_time = ((double)(utime/1000)) + (((double)(utime%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_time!=NULL) *system_time = ((double)(stime/1000)) + (((double)(stime%1000))*1e-3); 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 (current_rss!=NULL) *current_rss = current_rss0;
if (peak_rss!=NULL) *peak_rss = peak_rss0; if (peak_rss!=NULL) *peak_rss = peak_rss0;
if (current_commit!=NULL) *current_commit = current_commit0; if (current_commit!=NULL) *current_commit = current_commit0;

View File

@ -134,13 +134,17 @@ static void test_aslr(void) {
} }
static void test_process_info(void) { static void test_process_info(void) {
double utime = 0; size_t user_msecs = 0;
double stime = 0; size_t system_msecs = 0;
size_t current_rss = 0; size_t current_rss = 0;
size_t peak_rss = 0; size_t peak_rss = 0;
size_t current_commit = 0; size_t current_commit = 0;
size_t peak_commit = 0; size_t peak_commit = 0;
size_t page_faults = 0; size_t page_faults = 0;
mi_process_info(&utime, &stime, &current_rss, &peak_rss, &current_commit, &peak_commit, &page_faults); for (int i = 0; i < 100000; i++) {
printf("process info: user: %.3f s, rss: %zd b, commit: %zd b\n\n", utime, peak_rss, peak_commit); void* p = calloc(100,10);
free(p);
}
mi_process_info(&user_msecs, &system_msecs, &current_rss, &peak_rss, &current_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);
} }