core: add nm_utils_get_monotonic_timestamp_us() function

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-02-11 11:17:40 +01:00
parent 3e70fb20d4
commit a0e734764f
2 changed files with 25 additions and 0 deletions

View File

@@ -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: * nm_utils_get_monotonic_timestamp_ms:
* *

View File

@@ -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); 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) #define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
gint64 nm_utils_get_monotonic_timestamp_us (void);
gint64 nm_utils_get_monotonic_timestamp_ms (void); gint64 nm_utils_get_monotonic_timestamp_ms (void);
gint32 nm_utils_get_monotonic_timestamp_s (void); gint32 nm_utils_get_monotonic_timestamp_s (void);