diff options
Diffstat (limited to '')
-rw-r--r-- | src/system/Clock.cxx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/system/Clock.cxx b/src/system/Clock.cxx index 347997a44..4d89b9b89 100644 --- a/src/system/Clock.cxx +++ b/src/system/Clock.cxx @@ -31,6 +31,28 @@ #endif unsigned +MonotonicClockS(void) +{ +#ifdef WIN32 + return GetTickCount() / 1000; +#elif defined(__APPLE__) /* OS X does not define CLOCK_MONOTONIC */ + static mach_timebase_info_data_t base; + if (base.denom == 0) + (void)mach_timebase_info(&base); + + return (unsigned)((mach_absolute_time() * base.numer / 1000) + / (1000000 * base.denom)); +#elif defined(CLOCK_MONOTONIC) + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec; +#else + /* we have no monotonic clock, fall back to time() */ + return time(nullptr); +#endif +} + +unsigned MonotonicClockMS(void) { #ifdef WIN32 @@ -96,3 +118,29 @@ MonotonicClockUS(void) #endif } +#ifdef WIN32 + +gcc_const +static unsigned +DeltaFileTimeS(FILETIME a, FILETIME b) +{ + ULARGE_INTEGER a2, b2; + b2.LowPart = b.dwLowDateTime; + b2.HighPart = b.dwHighDateTime; + a2.LowPart = a.dwLowDateTime; + a2.HighPart = a.dwHighDateTime; + return (a2.QuadPart - b2.QuadPart) / 10000000; +} + +unsigned +GetProcessUptimeS() +{ + FILETIME creation_time, exit_time, kernel_time, user_time, now; + GetProcessTimes(GetCurrentProcess(), &creation_time, + &exit_time, &kernel_time, &user_time); + GetSystemTimeAsFileTime(&now); + + return DeltaFileTimeS(now, creation_time); +} + +#endif |