summaryrefslogtreecommitdiff
path: root/rts/posix
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2006-09-27 23:46:30 +0000
committerIan Lynagh <igloo@earth.li>2006-09-27 23:46:30 +0000
commitb214419d68962f9979fb3ddd22150a8a25960be5 (patch)
tree9c5a664d0c51ce24163f69119fc01b38b87d721f /rts/posix
parentcf570a334cdcaa03729c4a8b3e71c54eb37daf75 (diff)
downloadhaskell-b214419d68962f9979fb3ddd22150a8a25960be5.tar.gz
Handle clock_gettime failing
Diffstat (limited to 'rts/posix')
-rw-r--r--rts/posix/GetTime.c14
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