1998-02-26 05:46:47 +01:00
|
|
|
/* $Id: getrusage.c,v 1.7 1998/02/26 04:34:00 momjian Exp $ */
|
1997-12-19 14:35:17 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#include <math.h> /* for pow() prototype */
|
1997-03-25 08:54:53 +01:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include "rusagestub.h"
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#if 0 /* this is from univel port ... how does
|
|
|
|
* compiler define? */
|
|
|
|
/* same for i386_solaris port ... how does compiler define? */
|
|
|
|
/* same for sco port ... how does compiler define? */
|
|
|
|
/* same for sparc_solaris port ... how does compiler define? */
|
|
|
|
/* same for svr4 port ... how does compiler define? */
|
1997-03-25 08:54:53 +01:00
|
|
|
int
|
1997-09-07 07:04:48 +02:00
|
|
|
getrusage(int who, struct rusage * rusage)
|
1997-03-25 08:54:53 +01:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
struct tms tms;
|
1998-02-26 05:46:47 +01:00
|
|
|
int tick_rate = CLK_TCK; /* ticks per second */
|
1997-09-08 04:41:22 +02:00
|
|
|
clock_t u,
|
|
|
|
s;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (rusage == (struct rusage *) NULL)
|
|
|
|
{
|
|
|
|
errno = EFAULT;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (times(&tms) < 0)
|
|
|
|
{
|
|
|
|
/* errno set by times */
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
switch (who)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case RUSAGE_SELF:
|
|
|
|
u = tms.tms_utime;
|
|
|
|
s = tms.tms_stime;
|
|
|
|
break;
|
|
|
|
case RUSAGE_CHILDREN:
|
|
|
|
u = tms.tms_cutime;
|
|
|
|
s = tms.tms_cstime;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-03-25 08:54:53 +01:00
|
|
|
#define TICK_TO_SEC(T, RATE) ((T)/(RATE))
|
1997-09-07 07:04:48 +02:00
|
|
|
#define TICK_TO_USEC(T,RATE) (((T)%(RATE)*1000000)/RATE)
|
|
|
|
rusage->ru_utime.tv_sec = TICK_TO_SEC(u, tick_rate);
|
|
|
|
rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate);
|
|
|
|
rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate);
|
|
|
|
rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate);
|
|
|
|
return (0);
|
1997-03-25 08:54:53 +01:00
|
|
|
}
|
1998-02-26 05:46:47 +01:00
|
|
|
|
1997-12-19 03:46:25 +01:00
|
|
|
#endif
|
1997-03-25 08:54:53 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#if 0 /* this is for hpux port ... how does
|
|
|
|
* compiler define? */
|
1997-12-19 03:46:25 +01:00
|
|
|
getrusage(int who, struct rusage * ru)
|
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
return (syscall(SYS_GETRUSAGE, who, ru));
|
1997-12-19 03:46:25 +01:00
|
|
|
}
|
1998-02-26 05:46:47 +01:00
|
|
|
|
1997-12-19 03:46:25 +01:00
|
|
|
#endif
|