8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / compat / 4.1 / vtimes.c
blob2e497c462035b9905c864d5c99628e76c9dd72bf
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/time.h>
30 #include <sys/resource.h>
33 * Backwards compatible vtimes.
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 */
49 static void getvtimes(struct rusage *, struct vtimes *);
50 static int scale60(struct timeval *);
52 int
53 vtimes(struct vtimes *par, struct vtimes *chi)
55 struct rusage ru;
57 if (par) {
58 if (getrusage(RUSAGE_SELF, &ru) < 0)
59 return (-1);
60 getvtimes(&ru, par);
62 if (chi) {
63 if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
64 return (-1);
65 getvtimes(&ru, chi);
67 return (0);
70 static void
71 getvtimes(struct rusage *aru, struct vtimes *avt)
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;
86 static int
87 scale60(struct timeval *tvp)
90 return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);