add {strcat,strcmp,strcpy}n.c; they aren't Sys V routines, they're
[unix-history] / usr / src / lib / libcompat / 4.1 / vtimes.c
CommitLineData
bb0cfa24
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
2ce81398
DS
7#if defined(LIBC_SCCS) && !defined(lint)
8static char sccsid[] = "@(#)vtimes.c 5.2 (Berkeley) %G%";
9#endif LIBC_SCCS and not lint
2fe5b800
SL
10
11#include <sys/time.h>
12#include <sys/resource.h>
13
14/*
15 * Backwards compatible vtimes.
16 */
17struct vtimes {
18 int vm_utime; /* user time (60'ths) */
19 int vm_stime; /* system time (60'ths) */
20 /* divide next two by utime+stime to get averages */
21 unsigned vm_idsrss; /* integral of d+s rss */
22 unsigned vm_ixrss; /* integral of text rss */
23 int vm_maxrss; /* maximum rss */
24 int vm_majflt; /* major page faults */
25 int vm_minflt; /* minor page faults */
26 int vm_nswap; /* number of swaps */
27 int vm_inblk; /* block reads */
28 int vm_oublk; /* block writes */
29};
30
31vtimes(par, chi)
32 register struct vtimes *par, *chi;
33{
34 struct rusage ru;
35
36 if (par) {
37 if (getrusage(RUSAGE_SELF, &ru) < 0)
38 return (-1);
39 getvtimes(&ru, par);
40 }
41 if (chi) {
42 if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
43 return (-1);
44 getvtimes(&ru, chi);
45 }
46 return (0);
47}
48
49static
50getvtimes(aru, avt)
51 register struct rusage *aru;
52 register struct vtimes *avt;
53{
54
55 avt->vm_utime = scale60(&aru->ru_utime);
56 avt->vm_stime = scale60(&aru->ru_stime);
57 avt->vm_idsrss = ((aru->ru_idrss+aru->ru_isrss) / 100) * 60;
58 avt->vm_ixrss = aru->ru_ixrss / 100 * 60;
59 avt->vm_maxrss = aru->ru_maxrss;
60 avt->vm_majflt = aru->ru_majflt;
61 avt->vm_minflt = aru->ru_minflt;
62 avt->vm_nswap = aru->ru_nswap;
63 avt->vm_inblk = aru->ru_inblock;
64 avt->vm_oublk = aru->ru_oublock;
65}
66
67static
68scale60(tvp)
69 register struct timeval *tvp;
70{
71
72 return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);
73}