X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fposix%2FGetTime.c;h=939eef177e0c26956843a1a7ccd70073ccc041d2;hb=95a3e5532edfbf62cafa59067021d89d7e1c6852;hp=a2d9a3106060a6d387a1b3b59ead078d93b216f0;hpb=b214419d68962f9979fb3ddd22150a8a25960be5;p=ghc-hetmet.git diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c index a2d9a31..939eef1 100644 --- a/rts/posix/GetTime.c +++ b/rts/posix/GetTime.c @@ -32,6 +32,10 @@ # include #endif +#ifdef USE_PAPI +# include +#endif + #if ! ((defined(HAVE_GETRUSAGE) && !irix_HOST_OS) || defined(HAVE_TIMES)) #error No implementation for getProcessCPUTime() available. #endif @@ -68,9 +72,17 @@ void getProcessTimes(Ticks *user, Ticks *elapsed) Ticks getProcessCPUTime(void) { +#if !defined(THREADED_RTS) && USE_PAPI + long long usec; + if ((usec = PAPI_get_virt_usec()) < 0) { + barf("PAPI_get_virt_usec: %lld", usec); + } + return ((usec * TICKS_PER_SECOND) / 1000000); +#else Ticks user, elapsed; getProcessTimes(&user,&elapsed); return user; +#endif } Ticks getProcessElapsedTime(void) @@ -115,15 +127,24 @@ void getProcessTimes(Ticks *user, Ticks *elapsed) Ticks getThreadCPUTime(void) { -#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_THREAD_CPUTIME_ID) - // clock_gettime() gives us per-thread CPU time. It isn't - // reliable on Linux, but it's the best we have. - struct timespec ts; - 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); +#if USE_PAPI + long long usec; + if ((usec = PAPI_get_virt_usec()) < 0) { + barf("PAPI_get_virt_usec: %lld", usec); + } + 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) + if (sysconf(_POSIX_THREAD_CPUTIME) != -1) { + // clock_gettime() gives us per-thread CPU time. It isn't + // reliable on Linux, but it's the best we have. + struct timespec ts; + 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(); @@ -132,7 +153,7 @@ Ticks getThreadCPUTime(void) nat getPageFaults(void) { -#if !defined(HAVE_GETRUSAGE) || irix_HOST_OS +#if !defined(HAVE_GETRUSAGE) || irix_HOST_OS || haiku_HOST_OS return 0; #else struct rusage t;