From: Jeff Muizelaar Date: Wed, 29 Feb 2012 14:58:32 +0000 (-0500) Subject: Implement getTime for OS X X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=43ac1bff7374a572d3bb0a8341ab3d167e3ac07d;p=apitrace Implement getTime for OS X mach_absolute_time lowest level timing function on OS X Signed-off-by: Jose Fonseca --- diff --git a/common/os_posix.cpp b/common/os_posix.cpp index 261fe88..3eebbd8 100644 --- a/common/os_posix.cpp +++ b/common/os_posix.cpp @@ -158,6 +158,10 @@ log(const char *format, ...) logging = false; } +#if defined(__APPLE__) +long long timeFrequency = 0LL; +#endif + void abort(void) { diff --git a/common/os_time.hpp b/common/os_time.hpp index a4f5209..75175d8 100644 --- a/common/os_time.hpp +++ b/common/os_time.hpp @@ -35,6 +35,8 @@ #include #elif defined(__linux__) #include +#elif defined(__APPLE__) +#include #else #include #endif @@ -43,15 +45,15 @@ namespace os { // OS dependent time frequency -#if defined(_WIN32) - // runtime variable on Windows +#if defined(_WIN32) || defined(__APPLE__) + // runtime variable on Windows and MacOSX extern long long timeFrequency; #elif defined(__linux__) - // nanoseconds - static const long long timeFrequency = 1000000000; + // nanoseconds on Linux + static const long long timeFrequency = 1000000000LL; #else - // microseconds on - static const long long timeFrequency = 1000000; + // microseconds on Unices + static const long long timeFrequency = 1000000LL; #endif // Time from an unknown base in a unit determined by timeFrequency @@ -72,6 +74,13 @@ namespace os { return 0; } return tp.tv_sec * 1000000000LL + tp.tv_nsec; +#elif defined(__APPLE__) + if (!timeFrequency) { + mach_timebase_info_data_t timebaseInfo; + mach_timebase_info(&timebaseInfo); + timeFrequency = 1000000000LL * timebaseInfo.denom / timebaseInfo.numer; + } + return mach_absolute_time(); #else struct timeval tv; gettimeofday(&tv, NULL);