]> arthur.barton.de Git - netdata.git/blobdiff - src/clocks.h
introduce heartbeat API using monotonic clock
[netdata.git] / src / clocks.h
index c1b8e70179ec93acda3025e0afa0e3163e03d290..39c0436f8327b4a86df06339e04b53a3fcddec2e 100644 (file)
@@ -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 */