From: Ian Lynagh Date: Wed, 27 Sep 2006 23:46:30 +0000 (+0000) Subject: Handle clock_gettime failing X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=b214419d68962f9979fb3ddd22150a8a25960be5 Handle clock_gettime failing --- diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c index 0e591ef..a2d9a31 100644 --- a/rts/posix/GetTime.c +++ b/rts/posix/GetTime.c @@ -44,7 +44,7 @@ Ticks getProcessCPUTime(void) { struct rusage t; getrusage(RUSAGE_SELF, &t); - return ((Ticks)t.ru_utime.tv_sec * TICKS_PER_SECOND + + return ((Ticks)t.ru_utime.tv_sec * TICKS_PER_SECOND + ((Ticks)t.ru_utime.tv_usec * TICKS_PER_SECOND)/1000000); } @@ -119,12 +119,14 @@ Ticks getThreadCPUTime(void) // clock_gettime() gives us per-thread CPU time. It isn't // reliable on Linux, but it's the best we have. struct timespec ts; - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); - return ((Ticks)ts.tv_sec * TICKS_PER_SECOND + - ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000); -#else - return getProcessCPUTime(); + int res; + res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + if (res == 0) { + return ((Ticks)ts.tv_sec * TICKS_PER_SECOND + + ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000); + } #endif + return getProcessCPUTime(); } nat