1 /* $Id: resource.c 6135 2003-01-19 01:15:40Z rra $
12 #include <sys/resource.h>
14 #define TIMEVALasDOUBLE(t) \
15 ((double)(t).tv_sec + ((double)(t).tv_usec) / 1000000.0)
17 int getrusage(int who, struct rusage *rusage);
19 int GetResourceUsage(double *usertime, double *systime)
23 if (getrusage(RUSAGE_SELF, &R) < 0)
25 *usertime = TIMEVALasDOUBLE(R.ru_utime);
26 *systime = TIMEVALasDOUBLE(R.ru_stime);
30 #else /* HAVE_GETRUSAGE */
32 #include <sys/param.h>
33 #include <sys/times.h>
37 #endif /* !defined(HZ) */
39 #define CPUTIMEasDOUBLE(t1, t2) ((double)(t1 + t2) / (double)HZ)
41 int GetResourceUsage(double *usertime, double *systime)
47 *usertime = CPUTIMEasDOUBLE(T.tms_utime, T.tms_cutime);
48 *systime = CPUTIMEasDOUBLE(T.tms_stime, T.tms_cstime);
52 #endif /* !HAVE_GETRUSAGE */