Added Util::bootSecs() for reliable time since boot measurements.

This commit is contained in:
Thulinma 2014-05-16 19:45:02 +02:00
parent cb31d8bb48
commit 5973e7ebe1
2 changed files with 8 additions and 0 deletions

View file

@ -4,6 +4,7 @@
#include "timing.h"
#include <sys/time.h>//for gettimeofday
#include <time.h>//for time and nanosleep
#include <sys/sysinfo.h> //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;

View file

@ -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();///<Gets the current time in microseconds.
long long unsigned int getMicros(long long unsigned int previous);///<Gets the time difference in microseconds.
long long int getNTP();