]> granicus.if.org Git - postgresql/blob - src/backend/port/getrusage.c
48469919e6697719988d7ce14f99ed16a836b8ee
[postgresql] / src / backend / port / getrusage.c
1 /* $Id: getrusage.c,v 1.4 1998/02/01 00:02:59 scrappy Exp $ */
2
3 #include <math.h>               /* for pow() prototype */
4
5 #include <errno.h>
6 #include "rusagestub.h"
7 #include "port-protos.h"
8
9 #if 0 /* this is from univel port ... how does compiler define? */
10       /* same for i386_solaris port ... how does compiler define? */
11       /* same for sco port ... how does compiler define? */
12       /* same for sparc_solaris port ... how does compiler define? */
13       /* same for svr4 port ... how does compiler define? */
14 int
15 getrusage(int who, struct rusage * rusage)
16 {
17         struct tms      tms;
18         register int tick_rate = CLK_TCK;       /* ticks per second */
19         clock_t         u,
20                                 s;
21
22         if (rusage == (struct rusage *) NULL)
23         {
24                 errno = EFAULT;
25                 return (-1);
26         }
27         if (times(&tms) < 0)
28         {
29                 /* errno set by times */
30                 return (-1);
31         }
32         switch (who)
33         {
34                 case RUSAGE_SELF:
35                         u = tms.tms_utime;
36                         s = tms.tms_stime;
37                         break;
38                 case RUSAGE_CHILDREN:
39                         u = tms.tms_cutime;
40                         s = tms.tms_cstime;
41                         break;
42                 default:
43                         errno = EINVAL;
44                         return (-1);
45         }
46 #define TICK_TO_SEC(T, RATE)    ((T)/(RATE))
47 #define TICK_TO_USEC(T,RATE)    (((T)%(RATE)*1000000)/RATE)
48         rusage->ru_utime.tv_sec = TICK_TO_SEC(u, tick_rate);
49         rusage->ru_utime.tv_usec = TICK_TO_USEC(u, tick_rate);
50         rusage->ru_stime.tv_sec = TICK_TO_SEC(s, tick_rate);
51         rusage->ru_stime.tv_usec = TICK_TO_USEC(u, tick_rate);
52         return (0);
53 }
54 #endif
55
56 #if 0 /* this is for hpux port ... how does compiler define? */
57 getrusage(int who, struct rusage * ru)
58 {
59     return (syscall(SYS_GETRUSAGE, who, ru));
60 }
61 #endif