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