diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2017-11-24 13:48:13 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2017-11-24 13:48:13 +0000 |
commit | f444ae41531827763ea40797240788c841a6ed59 (patch) | |
tree | 6edf85306d9046e746ceb9eacc0c543b88026ccf /usr.bin | |
parent | 34f8ee06ad27b530db073e6e0ca3693e74271901 (diff) |
Use clock_gettime and getrusage to compute real and user time.
Better handling of clock jumps, from Scott Cheloa.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/openssl/apps_posix.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/usr.bin/openssl/apps_posix.c b/usr.bin/openssl/apps_posix.c index 67cd465088e..94c6d35f714 100644 --- a/usr.bin/openssl/apps_posix.c +++ b/usr.bin/openssl/apps_posix.c @@ -116,31 +116,48 @@ * Functions that need to be overridden by non-POSIX operating systems. */ -#include <sys/times.h> +#include <sys/resource.h> +#include <sys/time.h> -#include <unistd.h> +#include <time.h> #include "apps.h" -double -app_tminterval(int stop, int usertime) +static double +real_interval(int stop) { - double ret = 0; - struct tms rus; - clock_t now = times(&rus); - static clock_t tmstart; + static struct timespec start; + struct timespec elapsed, now; + + clock_gettime(CLOCK_MONOTONIC, &now); + if (stop) { + timespecsub(&now, &start, &elapsed); + return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0; + } + start = now; + return 0.0; +} - if (usertime) - now = rus.tms_utime; +static double +user_interval(int stop) +{ + static struct timeval start; + struct timeval elapsed; + struct rusage now; - if (stop == TM_START) - tmstart = now; - else { - long int tck = sysconf(_SC_CLK_TCK); - ret = (now - tmstart) / (double) tck; + getrusage(RUSAGE_SELF, &now); + if (stop) { + timersub(&now.ru_utime, &start, &elapsed); + return elapsed.tv_sec + elapsed.tv_usec / 1000000.0; } + start = now.ru_utime; + return 0.0; +} - return (ret); +double +app_tminterval(int stop, int usertime) +{ + return (usertime) ? user_interval(stop) : real_interval(stop); } int |