lib/util: add nsec_time_diff to calulate diffs from timespecs
authorBjörn Jacke <bj@sernet.de>
Mon, 30 Aug 2010 15:56:37 +0000 (17:56 +0200)
committerBjörn Jacke <bj@sernet.de>
Tue, 31 Aug 2010 08:26:23 +0000 (10:26 +0200)
lib/util/time.c
lib/util/time.h

index 5557346b9b035f5544974a6c4255dd2267efe75f..5ecf93cb77caba269514ebe5b30d28571f140062 100644 (file)
@@ -409,6 +409,15 @@ _PUBLIC_ int64_t usec_time_diff(const struct timeval *tv1, const struct timeval
        return (sec_diff * 1000000) + (int64_t)(tv1->tv_usec - tv2->tv_usec);
 }
 
+/**
+  return (tp1 - tp2) in microseconds
+*/
+_PUBLIC_ int64_t nsec_time_diff(const struct timespec *tp1, const struct timespec *tp2)
+{
+       int64_t sec_diff = tp1->tv_sec - tp2->tv_sec;
+       return (sec_diff * 1000000000) + (int64_t)(tp1->tv_nsec - tp2->tv_nsec);
+}
+
 
 /**
   return a zero timeval
index 90890cdbc81f7f3ef51461b1cb3ff7da9e240a92..720a262b2927d8b15a7cd848f8a62cec5aefbf88 100644 (file)
@@ -148,6 +148,11 @@ _PUBLIC_ NTTIME nttime_from_string(const char *s);
 */
 _PUBLIC_ int64_t usec_time_diff(const struct timeval *tv1, const struct timeval *tv2);
 
+/**
+  return (tp1 - tp2) in nanoseconds
+*/
+_PUBLIC_ int64_t nsec_time_diff(const struct timespec *tp1, const struct timespec *tp2);
+
 /**
   return a zero timeval
 */