summaryrefslogtreecommitdiffstats
path: root/lib/util/time.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2013-11-20 12:00:17 +0100
committerJeremy Allison <jra@samba.org>2013-12-12 12:50:21 -0800
commitb2dfd57669ba5835feb024b4ce1b3208a797d568 (patch)
treea913eaf92e65a677e67e32ae7bb823e48d41d253 /lib/util/time.c
parent11f744581813dcfe8bd036ab2a7fa40cb9209f6b (diff)
downloadsamba-b2dfd57669ba5835feb024b4ce1b3208a797d568.tar.gz
samba-b2dfd57669ba5835feb024b4ce1b3208a797d568.tar.xz
samba-b2dfd57669ba5835feb024b4ce1b3208a797d568.zip
lib-util: add functions to get elapsed from given timespec structs
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/util/time.c')
-rw-r--r--lib/util/time.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/util/time.c b/lib/util/time.c
index 05251dd3b5..a09490a198 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -652,6 +652,24 @@ _PUBLIC_ double timeval_elapsed(const struct timeval *tv)
struct timeval tv2 = timeval_current();
return timeval_elapsed2(tv, &tv2);
}
+/**
+ * return the number of seconds elapsed between two times
+ **/
+_PUBLIC_ double timespec_elapsed2(const struct timespec *ts1,
+ const struct timespec *ts2)
+{
+ return (ts2->tv_sec - ts1->tv_sec) +
+ (ts2->tv_nsec - ts1->tv_nsec)*1.0e-9;
+}
+
+/**
+ * return the number of seconds elapsed since a given time
+ */
+_PUBLIC_ double timespec_elapsed(const struct timespec *ts)
+{
+ struct timespec ts2 = timespec_current();
+ return timespec_elapsed2(ts, &ts2);
+}
/**
return the lesser of two timevals