diff options
author | Ernie Rael <errael@raelity.com> | 2023-03-16 21:43:15 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-03-16 21:43:15 +0000 |
commit | 076de79ad832558267b3ff903c048df2f4c1a5d6 (patch) | |
tree | e0412a99ca8e44db8702b98a6a1cec93a0c561b9 /src/time.c | |
parent | 16110ccf11de7a41cb0db0ae1ecb829e5a1b98fc (diff) |
patch 9.0.1411: accuracy of profiling is not optimalv9.0.1411
Problem: Accuracy of profiling is not optimal.
Solution: Use CLOCK_MONOTONIC if possible. (Ernie Rael, closes #12129)
Diffstat (limited to 'src/time.c')
-rw-r--r-- | src/time.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/time.c b/src/time.c index c82a79aaff..bcc7eef139 100644 --- a/src/time.c +++ b/src/time.c @@ -163,7 +163,7 @@ list2proftime(typval_T *arg, proftime_T *tm) tm->LowPart = n2; # else tm->tv_sec = n1; - tm->tv_usec = n2; + tm->tv_fsec = n2; # endif return error ? FAIL : OK; } @@ -222,7 +222,7 @@ f_reltime(typval_T *argvars UNUSED, typval_T *rettv UNUSED) n2 = res.LowPart; # else n1 = res.tv_sec; - n2 = res.tv_usec; + n2 = res.tv_fsec; # endif list_append_number(rettv->vval.v_list, (varnumber_T)n1); list_append_number(rettv->vval.v_list, (varnumber_T)n2); @@ -258,6 +258,7 @@ f_reltimefloat(typval_T *argvars UNUSED, typval_T *rettv) void f_reltimestr(typval_T *argvars UNUSED, typval_T *rettv) { + static char buf[50]; # ifdef FEAT_RELTIME proftime_T tm; # endif @@ -269,7 +270,15 @@ f_reltimestr(typval_T *argvars UNUSED, typval_T *rettv) return; if (list2proftime(&argvars[0], &tm) == OK) + { +# ifdef MSWIN rettv->vval.v_string = vim_strsave((char_u *)profile_msg(&tm)); +# else + long usec = tm.tv_fsec / (TV_FSEC_SEC / 1000000); + sprintf(buf, "%3ld.%06ld", (long)tm.tv_sec, usec); + rettv->vval.v_string = vim_strsave((char_u *)buf); +# endif + } else if (in_vim9script()) emsg(_(e_invalid_argument)); # endif @@ -392,7 +401,7 @@ static timer_T *first_timer = NULL; static long last_timer_id = 0; /* - * Return time left until "due". Negative if past "due". + * Return time left, in "msec", until "due". Negative if past "due". */ long proftime_time_left(proftime_T *due, proftime_T *now) @@ -409,7 +418,7 @@ proftime_time_left(proftime_T *due, proftime_T *now) if (now->tv_sec > due->tv_sec) return 0; return (due->tv_sec - now->tv_sec) * 1000 - + (due->tv_usec - now->tv_usec) / 1000; + + (due->tv_fsec - now->tv_fsec) / (TV_FSEC_SEC / 1000); # endif } |