xref: /titanic_51/usr/src/lib/libbc/libc/compat/4.1/vtimes.c (revision faebf79429f1b4c0f9334ac0f880806edf891f1f)
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 /*
23  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/time.h>
30 #include <sys/resource.h>
31 
32 /*
33  * Backwards compatible vtimes.
34  */
35 struct vtimes {
36 	int	vm_utime;		/* user time (60'ths) */
37 	int	vm_stime;		/* system time (60'ths) */
38 	/* divide next two by utime+stime to get averages */
39 	unsigned vm_idsrss;		/* integral of d+s rss */
40 	unsigned vm_ixrss;		/* integral of text rss */
41 	int	vm_maxrss;		/* maximum rss */
42 	int	vm_majflt;		/* major page faults */
43 	int	vm_minflt;		/* minor page faults */
44 	int	vm_nswap;		/* number of swaps */
45 	int	vm_inblk;		/* block reads */
46 	int	vm_oublk;		/* block writes */
47 };
48 
49 static void	getvtimes(struct rusage *, struct vtimes *);
50 static int	scale60(struct timeval *);
51 
52 int
53 vtimes(struct vtimes *par, struct vtimes *chi)
54 {
55 	struct rusage ru;
56 
57 	if (par) {
58 		if (getrusage(RUSAGE_SELF, &ru) < 0)
59 			return (-1);
60 		getvtimes(&ru, par);
61 	}
62 	if (chi) {
63 		if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
64 			return (-1);
65 		getvtimes(&ru, chi);
66 	}
67 	return (0);
68 }
69 
70 static void
71 getvtimes(struct rusage *aru, struct vtimes *avt)
72 {
73 
74 	avt->vm_utime = scale60(&aru->ru_utime);
75 	avt->vm_stime = scale60(&aru->ru_stime);
76 	avt->vm_idsrss = ((aru->ru_idrss+aru->ru_isrss) / 100) * 60;
77 	avt->vm_ixrss = aru->ru_ixrss / 100 * 60;
78 	avt->vm_maxrss = aru->ru_maxrss;
79 	avt->vm_majflt = aru->ru_majflt;
80 	avt->vm_minflt = aru->ru_minflt;
81 	avt->vm_nswap = aru->ru_nswap;
82 	avt->vm_inblk = aru->ru_inblock;
83 	avt->vm_oublk = aru->ru_oublock;
84 }
85 
86 static int
87 scale60(struct timeval *tvp)
88 {
89 
90 	return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);
91 }
92