diff options
| author | Volker Lendecke <vl@samba.org> | 2013-11-20 12:00:17 +0100 |
|---|---|---|
| committer | Jeremy Allison <jra@samba.org> | 2013-12-12 12:50:21 -0800 |
| commit | b2dfd57669ba5835feb024b4ce1b3208a797d568 (patch) | |
| tree | a913eaf92e65a677e67e32ae7bb823e48d41d253 /lib | |
| parent | 11f744581813dcfe8bd036ab2a7fa40cb9209f6b (diff) | |
| download | samba-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')
| -rw-r--r-- | lib/util/time.c | 18 | ||||
| -rw-r--r-- | lib/util/time.h | 10 |
2 files changed, 28 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 diff --git a/lib/util/time.h b/lib/util/time.h index 69ba783774..b5302f84c2 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -247,6 +247,16 @@ double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2); double timeval_elapsed(const struct timeval *tv); /** + return the number of seconds elapsed between two times +*/ +double timespec_elapsed2(const struct timespec *ts1, + const struct timespec *ts2); +/** + return the number of seconds elapsed since a given time +*/ +double timespec_elapsed(const struct timespec *ts); + +/** return the lesser of two timevals */ struct timeval timeval_min(const struct timeval *tv1, |
