2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
4 \subsection[getCPUTime.lc]{getCPUTime Runtime Support}
9 #define _INCLUDE_HPUX_SOURCE
15 #ifdef HAVE_SYS_TYPES_H
16 #include <sys/types.h>
23 #ifdef HAVE_SYS_TIMES_H
24 #include <sys/times.h>
27 #ifdef HAVE_SYS_TIME_H
31 #if defined(HAVE_SYS_RESOURCE_H) && ! irix_TARGET_OS
32 #include <sys/resource.h>
35 #ifdef HAVE_SYS_TIMEB_H
36 #include <sys/timeb.h>
40 #include <sys/syscall.h>
41 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
42 #define HAVE_GETRUSAGE
46 * Our caller wants a pointer to four StgInts,
47 * user seconds, user nanoseconds, system seconds, system nanoseconds.
48 * Yes, the timerval has unsigned components, but nanoseconds take only
49 * 30 bits, and our CPU usage would have to be over 68 years for the
50 * seconds to overflow 31 bits.
54 getCPUTime(STG_NO_ARGS)
58 #if defined(HAVE_GETRUSAGE) && ! irix_TARGET_OS
61 getrusage(RUSAGE_SELF, &t);
62 cpu[0] = t.ru_utime.tv_sec;
63 cpu[1] = 1000 * t.ru_utime.tv_usec;
64 cpu[2] = t.ru_stime.tv_sec;
65 cpu[3] = 1000 * t.ru_stime.tv_usec;
68 # if defined(HAVE_TIMES)
71 # define ticks CLK_TCK
74 ticks = sysconf(_SC_CLK_TCK);
78 cpu[0] = t.tms_utime / ticks;
79 cpu[1] = (t.tms_utime - cpu[0] * ticks) * (1000000000 / ticks);
80 cpu[2] = t.tms_stime / ticks;
81 cpu[3] = (t.tms_stime - cpu[2] * ticks) * (1000000000 / ticks);