xref: /titanic_44/usr/src/lib/libbc/libc/compat/4.1/vtimes.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 #pragma ident	"%Z%%M%	%I%	%E% SMI"
23 	  /* from UCB 4.1 83/05/31 */
24 
25 #include <sys/time.h>
26 #include <sys/resource.h>
27 
28 /*
29  * Backwards compatible vtimes.
30  */
31 struct vtimes {
32 	int	vm_utime;		/* user time (60'ths) */
33 	int	vm_stime;		/* system time (60'ths) */
34 	/* divide next two by utime+stime to get averages */
35 	unsigned vm_idsrss;		/* integral of d+s rss */
36 	unsigned vm_ixrss;		/* integral of text rss */
37 	int	vm_maxrss;		/* maximum rss */
38 	int	vm_majflt;		/* major page faults */
39 	int	vm_minflt;		/* minor page faults */
40 	int	vm_nswap;		/* number of swaps */
41 	int	vm_inblk;		/* block reads */
42 	int	vm_oublk;		/* block writes */
43 };
44 
45 vtimes(par, chi)
46 	register struct vtimes *par, *chi;
47 {
48 	struct rusage ru;
49 
50 	if (par) {
51 		if (getrusage(RUSAGE_SELF, &ru) < 0)
52 			return (-1);
53 		getvtimes(&ru, par);
54 	}
55 	if (chi) {
56 		if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
57 			return (-1);
58 		getvtimes(&ru, chi);
59 	}
60 	return (0);
61 }
62 
63 static
64 getvtimes(aru, avt)
65 	register struct rusage *aru;
66 	register struct vtimes *avt;
67 {
68 
69 	avt->vm_utime = scale60(&aru->ru_utime);
70 	avt->vm_stime = scale60(&aru->ru_stime);
71 	avt->vm_idsrss = ((aru->ru_idrss+aru->ru_isrss) / 100) * 60;
72 	avt->vm_ixrss = aru->ru_ixrss / 100 * 60;
73 	avt->vm_maxrss = aru->ru_maxrss;
74 	avt->vm_majflt = aru->ru_majflt;
75 	avt->vm_minflt = aru->ru_minflt;
76 	avt->vm_nswap = aru->ru_nswap;
77 	avt->vm_inblk = aru->ru_inblock;
78 	avt->vm_oublk = aru->ru_oublock;
79 }
80 
81 static
82 scale60(tvp)
83 	register struct timeval *tvp;
84 {
85 
86 	return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);
87 }
88