diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 241d2ddf4..f7f2b986f 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -798,6 +798,30 @@ monotonic_timestamp_get (struct timespec *tp) } } +/** + * nm_utils_get_monotonic_timestamp_us: + * + * Returns: a monotonically increasing time stamp in microseconds, + * starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME. + * + * The returned value will start counting at an undefined point + * in the past and will always be positive. + **/ +gint64 +nm_utils_get_monotonic_timestamp_us (void) +{ + struct timespec tp; + + monotonic_timestamp_get (&tp); + + /* Although the result will always be positive, we return a signed + * integer, which makes it easier to calculate time differences (when + * you want to subtract signed values). + **/ + return (((gint64) tp.tv_sec) + monotonic_timestamp_offset_sec) * ((gint64) G_USEC_PER_SEC) + + (tp.tv_nsec / (NM_UTILS_NS_PER_SECOND/G_USEC_PER_SEC)); +} + /** * nm_utils_get_monotonic_timestamp_ms: * diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index cae7944e0..d33ceda50 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -97,6 +97,7 @@ NMConnection *nm_utils_match_connection (GSList *connections, gint64 nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback); #define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000) +gint64 nm_utils_get_monotonic_timestamp_us (void); gint64 nm_utils_get_monotonic_timestamp_ms (void); gint32 nm_utils_get_monotonic_timestamp_s (void);