diff options
-rw-r--r-- | rts/posix/GetTime.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c index 0e591ef551..a2d9a31060 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 |