From 0e070e93d85fe78be7ef0f23f246bcb42bea5d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20G=C3=B3mez?= Date: Mon, 1 Dec 2025 17:23:46 -0500 Subject: [PATCH] util: add helper to get time in nanoseconds. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergio Gómez --- include/util/time.h | 5 +++++ util/time.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/include/util/time.h b/include/util/time.h index dd164bf2f..fd2bf9626 100644 --- a/include/util/time.h +++ b/include/util/time.h @@ -6,6 +6,11 @@ static const long NSEC_PER_SEC = 1000000000; +/** + * Get the current time, in nanoseconds. + */ +int64_t get_current_time_nsec(void); + /** * Get the current time, in milliseconds. */ diff --git a/util/time.c b/util/time.c index 1a8f32969..7db0893b4 100644 --- a/util/time.c +++ b/util/time.c @@ -22,6 +22,12 @@ int64_t get_current_time_msec(void) { return timespec_to_msec(&now); } +int64_t get_current_time_nsec(void) { + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return timespec_to_nsec(&now); +} + void timespec_sub(struct timespec *r, const struct timespec *a, const struct timespec *b) { r->tv_sec = a->tv_sec - b->tv_sec;