Use clock_gettime(CLOCK_MONOTONIC) to calculate the runtime of
rpki-client. While there switch all timevals in the stats struct to
timespecs in preparation for openmetric support.
I also resorted the headers and added the missing time headers.
--
:wq Claudio
Index: extern.h
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/extern.h,v
retrieving revision 1.162
diff -u -p -r1.162 extern.h
--- extern.h 29 Nov 2022 10:33:09 -0000 1.162
+++ extern.h 8 Dec 2022 11:06:18 -0000
@@ -533,9 +533,9 @@ struct stats {
size_t del_dirs; /* number of directories removed in cleanup */
size_t brks; /* number of BGPsec Router Key (BRK) certificates */
size_t skiplistentries; /* number of skiplist entries */
- struct timeval elapsed_time;
- struct timeval user_time;
- struct timeval system_time;
+ struct timespec elapsed_time;
+ struct timespec user_time;
+ struct timespec system_time;
};
struct ibuf;
Index: main.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v
retrieving revision 1.227
diff -u -p -r1.227 main.c
--- main.c 30 Nov 2022 08:16:10 -0000 1.227
+++ main.c 8 Dec 2022 11:12:06 -0000
@@ -18,30 +18,32 @@
#include <sys/types.h>
#include <sys/queue.h>
-#include <sys/socket.h>
#include <sys/resource.h>
+#include <sys/socket.h>
#include <sys/statvfs.h>
+#include <sys/time.h>
#include <sys/tree.h>
#include <sys/wait.h>
#include <assert.h>
+#include <dirent.h>
#include <err.h>
#include <errno.h>
-#include <dirent.h>
#include <fcntl.h>
#include <fnmatch.h>
+#include <limits.h>
#include <poll.h>
#include <pwd.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <signal.h>
#include <string.h>
-#include <limits.h>
#include <syslog.h>
+#include <time.h>
#include <unistd.h>
-#include <imsg.h>
+#include <imsg.h>
#include "extern.h"
#include "version.h"
@@ -881,9 +883,9 @@ main(int argc, char *argv[])
struct brk_tree brks = RB_INITIALIZER(&brks);
struct vap_tree vaps = RB_INITIALIZER(&vaps);
struct rusage ru;
- struct timeval start_time, now_time;
+ struct timespec start_time, now_time;
- gettimeofday(&start_time, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &start_time);
/* If started as root, priv-drop to _rpki-client */
if (getuid() == 0) {
@@ -1322,15 +1324,19 @@ main(int argc, char *argv[])
if (!noop)
repo_cleanup(&fpt, cachefd);
- gettimeofday(&now_time, NULL);
- timersub(&now_time, &start_time, &stats.elapsed_time);
+ clock_gettime(CLOCK_MONOTONIC, &start_time);
+ timespecsub(&now_time, &start_time, &stats.elapsed_time);
if (getrusage(RUSAGE_SELF, &ru) == 0) {
- stats.user_time = ru.ru_utime;
- stats.system_time = ru.ru_stime;
+ TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &stats.user_time);
+ TIMEVAL_TO_TIMESPEC(&ru.ru_stime, &stats.system_time);
}
if (getrusage(RUSAGE_CHILDREN, &ru) == 0) {
- timeradd(&stats.user_time, &ru.ru_utime, &stats.user_time);
- timeradd(&stats.system_time, &ru.ru_stime, &stats.system_time);
+ struct timespec ts;
+
+ TIMEVAL_TO_TIMESPEC(&ru.ru_utime, &ts);
+ timespecadd(&stats.user_time, &ts, &stats.user_time);
+ TIMEVAL_TO_TIMESPEC(&ru.ru_stime, &ts);
+ timespecadd(&stats.system_time, &ts, &stats.system_time);
}
/* change working directory to the output directory */