From 925ff2b9e4387aecdf8e8c148dfe3cfe6f1c4b41 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 5 Jan 2023 18:45:48 +0100 Subject: [PATCH] Add clock_cpu() --- src/lib/utils.c | 7 +++++++ src/lib/utils.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/lib/utils.c b/src/lib/utils.c index 1d383ad..7a53c61 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -210,3 +210,10 @@ long clock_micros(void) { clock_gettime(CLOCK_MONOTONIC, &time); return time.tv_sec * 1000000 + time.tv_nsec / 1000; } + + +long clock_cpu(void) { + struct timespec time; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time); + return time.tv_sec * 1000000000 + time.tv_nsec; +} diff --git a/src/lib/utils.h b/src/lib/utils.h index 504682d..56aeb05 100644 --- a/src/lib/utils.h +++ b/src/lib/utils.h @@ -39,4 +39,6 @@ int base64_encode(void *data, unsigned long data_len, char *output, unsigned lon long clock_micros(void); +long clock_cpu(void); + #endif //SESIMOS_UTILS_H