From 5973e7ebe16d4c35078ddac1a5c8150f56cb6463 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 16 May 2014 19:45:02 +0200 Subject: [PATCH] Added Util::bootSecs() for reliable time since boot measurements. --- lib/timing.cpp | 7 +++++++ lib/timing.h | 1 + 2 files changed, 8 insertions(+) diff --git a/lib/timing.cpp b/lib/timing.cpp index b1cc7ca8..b253f194 100644 --- a/lib/timing.cpp +++ b/lib/timing.cpp @@ -4,6 +4,7 @@ #include "timing.h" #include //for gettimeofday #include //for time and nanosleep +#include //forsysinfo //emulate clock_gettime() for OSX compatibility #if defined(__APPLE__) || defined(__MACH__) @@ -48,6 +49,12 @@ long long int Util::getMS(){ return ((long long int)t.tv_sec) * 1000 + t.tv_nsec / 1000000; } +long long int Util::bootSecs(){ + struct sysinfo sinfo; + sysinfo(&sinfo); + return sinfo.uptime; +} + /// Gets the current time in microseconds. long long unsigned int Util::getMicros(){ struct timespec t; diff --git a/lib/timing.h b/lib/timing.h index 4e141e50..e2a4313b 100644 --- a/lib/timing.h +++ b/lib/timing.h @@ -6,6 +6,7 @@ namespace Util { void sleep(int ms); ///< Sleeps for the indicated amount of milliseconds or longer. long long int getMS(); ///< Gets the current time in milliseconds. + long long int bootSecs(); ///< Gets the current system uptime in seconds. long long unsigned int getMicros();///