Added Util::bootSecs() for reliable time since boot measurements.
This commit is contained in:
parent
cb31d8bb48
commit
5973e7ebe1
2 changed files with 8 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
#include <sys/time.h>//for gettimeofday
|
#include <sys/time.h>//for gettimeofday
|
||||||
#include <time.h>//for time and nanosleep
|
#include <time.h>//for time and nanosleep
|
||||||
|
#include <sys/sysinfo.h> //forsysinfo
|
||||||
|
|
||||||
//emulate clock_gettime() for OSX compatibility
|
//emulate clock_gettime() for OSX compatibility
|
||||||
#if defined(__APPLE__) || defined(__MACH__)
|
#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;
|
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.
|
/// Gets the current time in microseconds.
|
||||||
long long unsigned int Util::getMicros(){
|
long long unsigned int Util::getMicros(){
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
namespace Util {
|
namespace Util {
|
||||||
void sleep(int ms); ///< Sleeps for the indicated amount of milliseconds or longer.
|
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 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();///<Gets the current time in microseconds.
|
||||||
long long unsigned int getMicros(long long unsigned int previous);///<Gets the time difference in microseconds.
|
long long unsigned int getMicros(long long unsigned int previous);///<Gets the time difference in microseconds.
|
||||||
long long int getNTP();
|
long long int getNTP();
|
||||||
|
|
Loading…
Add table
Reference in a new issue