summaryrefslogtreecommitdiff
path: root/rts/posix/GetTime.c
diff options
context:
space:
mode:
authormrchebas@gmail.com <unknown>2006-11-08 17:14:52 +0000
committermrchebas@gmail.com <unknown>2006-11-08 17:14:52 +0000
commitfe07f054d7ae5e10b14d5fed730fe4424dabd587 (patch)
tree37b9be9c87726d5d910e72c195688b029d31a4c5 /rts/posix/GetTime.c
parent74a87d705449e2f9ad4021aeebf8149ce35a6a2e (diff)
downloadhaskell-fe07f054d7ae5e10b14d5fed730fe4424dabd587.tar.gz
Addition of PAPI to RTS
This patch still requires the addition of the USE_PAPI define to compile with PAPI. Also, programs must be compiled and linked with the appropriate library flags for papi.
Diffstat (limited to 'rts/posix/GetTime.c')
-rw-r--r--rts/posix/GetTime.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index a2d9a31060..db7378d62b 100644
--- a/rts/posix/GetTime.c
+++ b/rts/posix/GetTime.c
@@ -32,6 +32,10 @@
# include <sys/times.h>
#endif
+#ifdef USE_PAPI
+# include <papi.h>
+#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,7 +127,14 @@ void getProcessTimes(Ticks *user, Ticks *elapsed)
Ticks getThreadCPUTime(void)
{
-#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_THREAD_CPUTIME_ID)
+#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(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;