From: claudio Date: Wed, 14 Dec 2022 10:34:49 +0000 (+0000) Subject: Switch to struct timespec for collecting stats. This allows to use X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=65c1cececaece7a50a38d6d0af8dbb6074cfa203;p=openbsd Switch to struct timespec for collecting stats. This allows to use clock_gettime(CLOCK_MONOTONIC) for runtime calculation. OK tb@ --- diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index d946f8b8b20..9143c457766 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.162 2022/11/29 10:33:09 claudio Exp $ */ +/* $OpenBSD: extern.h,v 1.163 2022/12/14 10:34:49 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -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; diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 105c1ed6cba..c78655b6fcb 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.227 2022/11/30 08:16:10 job Exp $ */ +/* $OpenBSD: main.c,v 1.228 2022/12/14 10:34:49 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -18,28 +18,31 @@ #include #include -#include #include +#include #include +#include #include #include #include +#include #include #include -#include #include #include +#include #include #include +#include #include #include #include -#include #include -#include #include +#include #include + #include #include "extern.h" @@ -881,9 +884,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 +1325,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, &now_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 */