diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-21 19:34:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-21 19:34:08 +0000 |
commit | 6d2e027eb728c8294fdd7c3692e9853b3ca2603b (patch) | |
tree | 3e190253238075ac8590b2f214852d2256fdad53 /libnetdata/clocks/clocks.c | |
parent | Opting out by default from sending anonymous statistics (phone home). (diff) | |
download | netdata-6d2e027eb728c8294fdd7c3692e9853b3ca2603b.tar.xz netdata-6d2e027eb728c8294fdd7c3692e9853b3ca2603b.zip |
Merging upstream version 1.12.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/clocks/clocks.c')
-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) { |