aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/alsa/time_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/alsa/time_utils.c')
-rw-r--r--plugins/alsa/time_utils.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/plugins/alsa/time_utils.c b/plugins/alsa/time_utils.c
new file mode 100644
index 0000000..6f22e9d
--- /dev/null
+++ b/plugins/alsa/time_utils.c
@@ -0,0 +1,17 @@
+#include "time_utils.h"
+#include "time.h"
+
+__thread uint64_t last = 0;
+
+uint64_t now_monotonic_usec() {
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ return now.tv_sec*1000000+now.tv_nsec/1000;
+}
+
+uint64_t ts() {
+ uint64_t now = now_monotonic_usec();
+ uint64_t elapsed = now-last;
+ last = now;
+ return elapsed;
+}