xref: /onnv-gate/usr/src/lib/libbc/libc/compat/4.1/vtimes.c (revision 722:636b850d4ee9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*722Smuffin /*
23*722Smuffin  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
24*722Smuffin  * Use is subject to license terms.
25*722Smuffin  */
26*722Smuffin 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/time.h>
300Sstevel@tonic-gate #include <sys/resource.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * Backwards compatible vtimes.
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate struct vtimes {
360Sstevel@tonic-gate 	int	vm_utime;		/* user time (60'ths) */
370Sstevel@tonic-gate 	int	vm_stime;		/* system time (60'ths) */
380Sstevel@tonic-gate 	/* divide next two by utime+stime to get averages */
390Sstevel@tonic-gate 	unsigned vm_idsrss;		/* integral of d+s rss */
400Sstevel@tonic-gate 	unsigned vm_ixrss;		/* integral of text rss */
410Sstevel@tonic-gate 	int	vm_maxrss;		/* maximum rss */
420Sstevel@tonic-gate 	int	vm_majflt;		/* major page faults */
430Sstevel@tonic-gate 	int	vm_minflt;		/* minor page faults */
440Sstevel@tonic-gate 	int	vm_nswap;		/* number of swaps */
450Sstevel@tonic-gate 	int	vm_inblk;		/* block reads */
460Sstevel@tonic-gate 	int	vm_oublk;		/* block writes */
470Sstevel@tonic-gate };
480Sstevel@tonic-gate 
49*722Smuffin static void	getvtimes(struct rusage *, struct vtimes *);
50*722Smuffin static int	scale60(struct timeval *);
51*722Smuffin 
52*722Smuffin int
vtimes(struct vtimes * par,struct vtimes * chi)53*722Smuffin vtimes(struct vtimes *par, struct vtimes *chi)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate 	struct rusage ru;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	if (par) {
580Sstevel@tonic-gate 		if (getrusage(RUSAGE_SELF, &ru) < 0)
590Sstevel@tonic-gate 			return (-1);
600Sstevel@tonic-gate 		getvtimes(&ru, par);
610Sstevel@tonic-gate 	}
620Sstevel@tonic-gate 	if (chi) {
630Sstevel@tonic-gate 		if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
640Sstevel@tonic-gate 			return (-1);
650Sstevel@tonic-gate 		getvtimes(&ru, chi);
660Sstevel@tonic-gate 	}
670Sstevel@tonic-gate 	return (0);
680Sstevel@tonic-gate }
690Sstevel@tonic-gate 
70*722Smuffin static void
getvtimes(struct rusage * aru,struct vtimes * avt)71*722Smuffin getvtimes(struct rusage *aru, struct vtimes *avt)
720Sstevel@tonic-gate {
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	avt->vm_utime = scale60(&aru->ru_utime);
750Sstevel@tonic-gate 	avt->vm_stime = scale60(&aru->ru_stime);
760Sstevel@tonic-gate 	avt->vm_idsrss = ((aru->ru_idrss+aru->ru_isrss) / 100) * 60;
770Sstevel@tonic-gate 	avt->vm_ixrss = aru->ru_ixrss / 100 * 60;
780Sstevel@tonic-gate 	avt->vm_maxrss = aru->ru_maxrss;
790Sstevel@tonic-gate 	avt->vm_majflt = aru->ru_majflt;
800Sstevel@tonic-gate 	avt->vm_minflt = aru->ru_minflt;
810Sstevel@tonic-gate 	avt->vm_nswap = aru->ru_nswap;
820Sstevel@tonic-gate 	avt->vm_inblk = aru->ru_inblock;
830Sstevel@tonic-gate 	avt->vm_oublk = aru->ru_oublock;
840Sstevel@tonic-gate }
850Sstevel@tonic-gate 
86*722Smuffin static int
scale60(struct timeval * tvp)87*722Smuffin scale60(struct timeval *tvp)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);
910Sstevel@tonic-gate }
92