diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-21 19:34:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-21 19:34:01 +0000 |
commit | 66564c2324abc58b24327b763e1113ff781156a2 (patch) | |
tree | 2480212cd47149a3fda5225b57689d0126546e23 /libnetdata/clocks/clocks.c | |
parent | Adding upstream version 1.12.0. (diff) | |
download | netdata-66564c2324abc58b24327b763e1113ff781156a2.tar.xz netdata-66564c2324abc58b24327b763e1113ff781156a2.zip |
Adding upstream version 1.12.1.upstream/1.12.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | libnetdata/clocks/clocks.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libnetdata/clocks/clocks.c b/libnetdata/clocks/clocks.c index f303ccddc..f7d217178 100644 --- a/libnetdata/clocks/clocks.c +++ b/libnetdata/clocks/clocks.c @@ -2,6 +2,8 @@ #include "../libnetdata.h" +static int clock_boottime_valid = 1; + #ifndef HAVE_CLOCK_GETTIME inline int clock_gettime(clockid_t clk_id, struct timespec *ts) { struct timeval tv; @@ -15,6 +17,12 @@ inline int clock_gettime(clockid_t clk_id, struct timespec *ts) { } #endif +void test_clock_boottime(void) { + struct timespec ts; + if(clock_gettime(CLOCK_BOOTTIME, &ts) == -1 && errno == EINVAL) + clock_boottime_valid = 0; +} + static inline time_t now_sec(clockid_t clk_id) { struct timespec ts; if(unlikely(clock_gettime(clk_id, &ts) == -1)) { @@ -73,15 +81,15 @@ inline int now_monotonic_timeval(struct timeval *tv) { } inline time_t now_boottime_sec(void) { - return now_sec(CLOCK_BOOTTIME); + return now_sec(likely(clock_boottime_valid) ? CLOCK_BOOTTIME : CLOCK_MONOTONIC); } inline usec_t now_boottime_usec(void) { - return now_usec(CLOCK_BOOTTIME); + return now_usec(likely(clock_boottime_valid) ? CLOCK_BOOTTIME : CLOCK_MONOTONIC); } inline int now_boottime_timeval(struct timeval *tv) { - return now_timeval(CLOCK_BOOTTIME, tv); + return now_timeval(likely(clock_boottime_valid) ? CLOCK_BOOTTIME : CLOCK_MONOTONIC, tv); } inline usec_t timeval_usec(struct timeval *tv) { |