projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Don't overwrite old memory with 0xaa when doing a realloc
[ghc-hetmet.git]
/
rts
/
posix
/
GetTime.c
diff --git
a/rts/posix/GetTime.c
b/rts/posix/GetTime.c
index
3a0764c
..
db7378d
100644
(file)
--- a/
rts/posix/GetTime.c
+++ b/
rts/posix/GetTime.c
@@
-32,6
+32,10
@@
# include <sys/times.h>
#endif
# 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
#if ! ((defined(HAVE_GETRUSAGE) && !irix_HOST_OS) || defined(HAVE_TIMES))
#error No implementation for getProcessCPUTime() available.
#endif
@@
-44,7
+48,7
@@
Ticks getProcessCPUTime(void)
{
struct rusage t;
getrusage(RUSAGE_SELF, &t);
{
struct rusage t;
getrusage(RUSAGE_SELF, &t);
- return (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);
}
((Ticks)t.ru_utime.tv_usec * TICKS_PER_SECOND)/1000000);
}
@@
-52,7
+56,7
@@
Ticks getProcessElapsedTime(void)
{
struct timeval tv;
gettimeofday(&tv, (struct timezone *) NULL);
{
struct timeval tv;
gettimeofday(&tv, (struct timezone *) NULL);
- return (tv.tv_sec * TICKS_PER_SECOND +
+ return ((Ticks)tv.tv_sec * TICKS_PER_SECOND +
((Ticks)tv.tv_usec * TICKS_PER_SECOND)/1000000);
}
((Ticks)tv.tv_usec * TICKS_PER_SECOND)/1000000);
}
@@
-68,9
+72,17
@@
void getProcessTimes(Ticks *user, Ticks *elapsed)
Ticks getProcessCPUTime(void)
{
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;
Ticks user, elapsed;
getProcessTimes(&user,&elapsed);
return user;
+#endif
}
Ticks getProcessElapsedTime(void)
}
Ticks getProcessElapsedTime(void)
@@
-89,7
+101,7
@@
void getProcessTimes(Ticks *user, Ticks *elapsed)
long ticks;
ticks = sysconf(_SC_CLK_TCK);
if ( ticks == -1 ) {
long ticks;
ticks = sysconf(_SC_CLK_TCK);
if ( ticks == -1 ) {
- errorBelch("sysconf\n");
+ sysErrorBelch("sysconf");
stg_exit(EXIT_FAILURE);
}
ClockFreq = ticks;
stg_exit(EXIT_FAILURE);
}
ClockFreq = ticks;
@@
-115,16
+127,25
@@
void getProcessTimes(Ticks *user, Ticks *elapsed)
Ticks getThreadCPUTime(void)
{
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;
// 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 (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
#endif
+ return getProcessCPUTime();
}
nat
}
nat