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;