Commit 960c61cd authored by Simon Marlow's avatar Simon Marlow
Browse files

Fix getThreadCPUTime()

ever since the patch "Check with sysconf _POSIX_THREAD_CPUTIME", it
has been returning incorrect results, because the sysconf variable to
check should have been _SC_THREAD_CPUTIME, not _POSIX_THREAD_CPUTIME.
parent 4a82c60e
...@@ -156,8 +156,16 @@ Ticks getThreadCPUTime(void) ...@@ -156,8 +156,16 @@ Ticks getThreadCPUTime(void)
} }
return ((usec * TICKS_PER_SECOND) / 1000000); return ((usec * TICKS_PER_SECOND) / 1000000);
#elif !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_POSIX_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_SYSCONF) #elif !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_SC_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_SYSCONF)
if (sysconf(_POSIX_THREAD_CPUTIME) != -1) { {
static int checked_sysconf = 0;
static int sysconf_result = 0;
if (!checked_sysconf) {
sysconf_result = sysconf(_SC_THREAD_CPUTIME);
checked_sysconf = 1;
}
if (sysconf_result != -1) {
// clock_gettime() gives us per-thread CPU time. It isn't // clock_gettime() gives us per-thread CPU time. It isn't
// reliable on Linux, but it's the best we have. // reliable on Linux, but it's the best we have.
struct timespec ts; struct timespec ts;
...@@ -168,6 +176,7 @@ Ticks getThreadCPUTime(void) ...@@ -168,6 +176,7 @@ Ticks getThreadCPUTime(void)
((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000); ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000);
} }
} }
}
#endif #endif
return getProcessCPUTime(); return getProcessCPUTime();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment