diff options
author | jca <> | 2017-11-24 13:48:12 +0000 |
---|---|---|
committer | jca <> | 2017-11-24 13:48:12 +0000 |
commit | 39d54f53c5193a75023fc870449caf64192e3183 (patch) | |
tree | 16008c1ded290153806f50af80da5c0592234809 | |
parent | 6298fe5f892c4094450148524c15044171a975a0 (diff) | |
download | openbsd-39d54f53c5193a75023fc870449caf64192e3183.tar.gz openbsd-39d54f53c5193a75023fc870449caf64192e3183.tar.bz2 openbsd-39d54f53c5193a75023fc870449caf64192e3183.zip |
Use clock_gettime and getrusage to compute real and user time.
Better handling of clock jumps, from Scott Cheloa.
-rw-r--r-- | src/usr.bin/openssl/apps_posix.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/usr.bin/openssl/apps_posix.c b/src/usr.bin/openssl/apps_posix.c index 67cd465088..94c6d35f71 100644 --- a/src/usr.bin/openssl/apps_posix.c +++ b/src/usr.bin/openssl/apps_posix.c | |||
@@ -116,31 +116,48 @@ | |||
116 | * Functions that need to be overridden by non-POSIX operating systems. | 116 | * Functions that need to be overridden by non-POSIX operating systems. |
117 | */ | 117 | */ |
118 | 118 | ||
119 | #include <sys/times.h> | 119 | #include <sys/resource.h> |
120 | #include <sys/time.h> | ||
120 | 121 | ||
121 | #include <unistd.h> | 122 | #include <time.h> |
122 | 123 | ||
123 | #include "apps.h" | 124 | #include "apps.h" |
124 | 125 | ||
125 | double | 126 | static double |
126 | app_tminterval(int stop, int usertime) | 127 | real_interval(int stop) |
127 | { | 128 | { |
128 | double ret = 0; | 129 | static struct timespec start; |
129 | struct tms rus; | 130 | struct timespec elapsed, now; |
130 | clock_t now = times(&rus); | 131 | |
131 | static clock_t tmstart; | 132 | clock_gettime(CLOCK_MONOTONIC, &now); |
133 | if (stop) { | ||
134 | timespecsub(&now, &start, &elapsed); | ||
135 | return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0; | ||
136 | } | ||
137 | start = now; | ||
138 | return 0.0; | ||
139 | } | ||
132 | 140 | ||
133 | if (usertime) | 141 | static double |
134 | now = rus.tms_utime; | 142 | user_interval(int stop) |
143 | { | ||
144 | static struct timeval start; | ||
145 | struct timeval elapsed; | ||
146 | struct rusage now; | ||
135 | 147 | ||
136 | if (stop == TM_START) | 148 | getrusage(RUSAGE_SELF, &now); |
137 | tmstart = now; | 149 | if (stop) { |
138 | else { | 150 | timersub(&now.ru_utime, &start, &elapsed); |
139 | long int tck = sysconf(_SC_CLK_TCK); | 151 | return elapsed.tv_sec + elapsed.tv_usec / 1000000.0; |
140 | ret = (now - tmstart) / (double) tck; | ||
141 | } | 152 | } |
153 | start = now.ru_utime; | ||
154 | return 0.0; | ||
155 | } | ||
142 | 156 | ||
143 | return (ret); | 157 | double |
158 | app_tminterval(int stop, int usertime) | ||
159 | { | ||
160 | return (usertime) ? user_interval(stop) : real_interval(stop); | ||
144 | } | 161 | } |
145 | 162 | ||
146 | int | 163 | int |