diff options
author | Kenneth Heafield <github@kheafield.com> | 2013-05-29 13:30:39 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2013-05-29 13:30:39 +0400 |
commit | 59bd7deb4b6b9c4f7b3b7dbb055783528fbc31ca (patch) | |
tree | 97b0b605cb49b7f53f568e929675b6d8802a732e /util | |
parent | b5bb5007738f731a55178dde5ab085b53422f22d (diff) |
Tetsuo's two patches
Diffstat (limited to 'util')
-rw-r--r-- | util/usage.cc | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/util/usage.cc b/util/usage.cc index 6c5f69c07..8db375e14 100644 --- a/util/usage.cc +++ b/util/usage.cc @@ -21,6 +21,21 @@ namespace util { #if !defined(_WIN32) && !defined(_WIN64) namespace { + +// On Mac OS X, clock_gettime is not implemented. +// CLOCK_MONOTONIC is not defined either. +#ifdef __MACH__ +#define CLOCK_MONOTONIC 0 + +int clock_gettime(int clk_id, struct timespec *tp) { + struct timeval tv; + gettimeofday(&tv, NULL); + tp->tv_sec = tv.tv_sec; + tp->tv_nsec = tv.tv_usec * 1000; + return 0; +} +#endif // __MACH__ + float FloatSec(const struct timeval &tv) { return static_cast<float>(tv.tv_sec) + (static_cast<float>(tv.tv_usec) / 1000000.0); } @@ -36,9 +51,7 @@ const char *SkipSpaces(const char *at) { class RecordStart { public: RecordStart() { -#ifdef CLOCK_MONOTONIC clock_gettime(CLOCK_MONOTONIC, &started_); -#endif } const struct timespec &Started() const { @@ -79,9 +92,7 @@ void PrintUsage(std::ostream &out) { out << "CPU:" << (FloatSec(usage.ru_utime) + FloatSec(usage.ru_stime)); struct timespec current; -#ifdef CLOCK_MONOTONIC clock_gettime(CLOCK_MONOTONIC, ¤t); -#endif out << "\treal:" << (FloatSec(current) - FloatSec(kRecordStart.Started())) << '\n'; #endif } |