2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
4 \subsection[getCPUTime.lc]{getCPUTime Runtime Support}
8 #define NON_POSIX_SOURCE /*needed for solaris2 only?*/
10 /* how is this to work given we have not read platform.h yet? */
12 #define _INCLUDE_HPUX_SOURCE
17 #ifdef HAVE_SYS_TYPES_H
18 #include <sys/types.h>
25 #ifdef HAVE_SYS_TIMES_H
26 #include <sys/times.h>
29 #ifdef HAVE_SYS_TIME_H
33 #if defined(HAVE_SYS_RESOURCE_H) && ! irix_TARGET_OS
34 #include <sys/resource.h>
37 #ifdef HAVE_SYS_TIMEB_H
38 #include <sys/timeb.h>
42 #include <sys/syscall.h>
43 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
44 #define HAVE_GETRUSAGE
60 * Our caller wants a pointer to four StgInts,
61 * user seconds, user nanoseconds, system seconds, system nanoseconds.
62 * Yes, the timerval has unsigned components, but nanoseconds take only
63 * 30 bits, and our CPU usage would have to be over 68 years for the
64 * seconds to overflow 31 bits.
68 getCPUTime(StgByteArray cpuStruct)
70 StgInt *cpu=(StgInt *)cpuStruct;
72 #if defined(HAVE_GETRUSAGE) && ! irix_TARGET_OS
75 getrusage(RUSAGE_SELF, &t);
76 cpu[0] = t.ru_utime.tv_sec;
77 cpu[1] = 1000 * t.ru_utime.tv_usec;
78 cpu[2] = t.ru_stime.tv_sec;
79 cpu[3] = 1000 * t.ru_stime.tv_usec;
82 # if defined(HAVE_TIMES)
85 # define ticks CLK_TCK
88 ticks = sysconf(_SC_CLK_TCK);
92 cpu[0] = t.tms_utime / ticks;
93 cpu[1] = (t.tms_utime - cpu[0] * ticks) * (1000000000 / ticks);
94 cpu[2] = t.tms_stime / ticks;
95 cpu[3] = (t.tms_stime - cpu[2] * ticks) * (1000000000 / ticks);
101 return (StgByteArray) cpuStruct;