summaryrefslogtreecommitdiffstats
path: root/src/clocks.h
diff options
context:
space:
mode:
authorRémi Lefèvre <remi.lefevre@parrot.com>2016-12-13 16:12:23 +0100
committerRémi Lefèvre <remi.lefevre@parrot.com>2017-01-23 17:17:25 +0100
commitc032b7be6773ba76c0560bfed83d2b0b86b267d6 (patch)
tree18f9394f703137542eb5455246564909b78073fb /src/clocks.h
parentecff88e2704c654d3df8d18f29820b359fe239be (diff)
introduce heartbeat API using monotonic clock
Signed-off-by: Rémi Lefèvre <remi.lefevre@parrot.com>
Diffstat (limited to 'src/clocks.h')
-rw-r--r--src/clocks.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/clocks.h b/src/clocks.h
index c1b8e70179..39c0436f83 100644
--- a/src/clocks.h
+++ b/src/clocks.h
@@ -12,6 +12,10 @@ struct timespec {
typedef int clockid_t;
#endif
+typedef unsigned long long usec_t;
+
+typedef usec_t heartbeat_t;
+
#ifndef HAVE_CLOCK_GETTIME
int clock_gettime(clockid_t clk_id, struct timespec *ts);
#endif
@@ -35,8 +39,6 @@ int clock_gettime(clockid_t clk_id, struct timespec *ts);
#endif
#endif
-typedef unsigned long long usec_t;
-
#define NSEC_PER_SEC 1000000000ULL
#define NSEC_PER_MSEC 1000000ULL
#define NSEC_PER_USEC 1000ULL
@@ -89,4 +91,14 @@ extern usec_t now_boottime_usec(void);
extern usec_t timeval_usec(struct timeval *ts);
extern usec_t dt_usec(struct timeval *now, struct timeval *old);
+extern void heartbeat_init(heartbeat_t *hb);
+
+/* Sleeps until next multiple of tick using monotonic clock.
+ * Returns elapsed time in microseconds since previous heartbeat
+ */
+extern usec_t heartbeat_next(heartbeat_t *hb, usec_t tick);
+
+/* Returns elapsed time in microseconds since last heartbeat */
+extern usec_t heartbeat_dt_usec(heartbeat_t *hb);
+
#endif /* NETDATA_CLOCKS_H */