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
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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
34 * reads std. input (acct.h format),
35 * writes std. output (tacct format)
41 #include <sys/types.h>
42 #include <sys/param.h>
56 float ut_cpu
[2]; /* cpu time (mins) */
57 float ut_kcore
[2]; /* kcore-mins */
58 long ut_pc
; /* # processes */
64 void enter(struct ptmp
*);
67 main(int argc
, char **argv
)
78 while (fread(&ab
, sizeof(ab
), 1, stdin
) == 1) {
79 if (!MYKIND(ab
.ac_flag
))
81 pb
.pt_uid
= ab
.ac_uid
;
82 CPYN(pb
.pt_name
, NULL
);
84 * approximate cpu P/NP split as same as elapsed time
86 if ((etime
= SECS(expand(ab
.ac_etime
))) == 0)
88 stime
= expand(ab
.ac_stime
) + expand(ab
.ac_utime
);
89 mem
= expand(ab
.ac_mem
);
90 if(pnpsplit(ab
.ac_btime
, etime
, elaps
) == 0) {
91 fprintf(stderr
, "acctprc: could not calculate prime/non-prime hours\n");
95 pb
.pt_cpu
[0] = (double)stime
* (double)elaps
[0] / etime
;
96 pb
.pt_cpu
[1] = (stime
> pb
.pt_cpu
[0])? stime
- pb
.pt_cpu
[0] : 0;
97 pb
.pt_cpu
[1] = stime
- pb
.pt_cpu
[0];
99 pb
.pt_mem
= (mem
+ stime
- 1) / stime
;
101 pb
.pt_mem
= 0; /* unlikely */
108 int node_compare(const void *node1
, const void *node2
)
110 if (((const struct utab
*)node1
)->ut_uid
> \
111 ((const struct utab
*)node2
)->ut_uid
)
113 else if (((const struct utab
*)node1
)->ut_uid
< \
114 ((const struct utab
*)node2
)->ut_uid
)
120 enter(struct ptmp
*p
)
125 if ((ub
= (struct utab
*)malloc(sizeof (struct utab
))) == NULL
) {
126 fprintf(stderr
, "acctprc: malloc fail!\n");
130 ub
->ut_uid
= p
->pt_uid
;
131 CPYN(ub
->ut_name
, p
->pt_name
);
132 ub
->ut_cpu
[0] = MINT(p
->pt_cpu
[0]);
133 ub
->ut_cpu
[1] = MINT(p
->pt_cpu
[1]);
134 memk
= KCORE(pb
.pt_mem
);
135 ub
->ut_kcore
[0] = memk
* MINT(p
->pt_cpu
[0]);
136 ub
->ut_kcore
[1] = memk
* MINT(p
->pt_cpu
[1]);
139 if (*(pt
= (struct utab
**)tsearch((void *)ub
, (void **)&root
, \
140 node_compare
)) == NULL
) {
141 fprintf(stderr
, "Not enough space available to build tree\n");
146 (*pt
)->ut_cpu
[0] += MINT(p
->pt_cpu
[0]);
147 (*pt
)->ut_cpu
[1] += MINT(p
->pt_cpu
[1]);
148 (*pt
)->ut_kcore
[0] += memk
* MINT(p
->pt_cpu
[0]);
149 (*pt
)->ut_kcore
[1] += memk
* MINT(p
->pt_cpu
[1]);
155 void print_node(const void *node
, VISIT order
, int level
) {
157 if (order
== postorder
|| order
== leaf
) {
158 tb
.ta_uid
= (*(struct utab
**)node
)->ut_uid
;
159 CPYN(tb
.ta_name
, (char *)uidtonam((*(struct utab
**)node
)->ut_uid
));
160 tb
.ta_cpu
[0] = (*(struct utab
**)node
)->ut_cpu
[0];
161 tb
.ta_cpu
[1] = (*(struct utab
**)node
)->ut_cpu
[1];
162 tb
.ta_kcore
[0] = (*(struct utab
**)node
)->ut_kcore
[0];
163 tb
.ta_kcore
[1] = (*(struct utab
**)node
)->ut_kcore
[1];
164 tb
.ta_pc
= (*(struct utab
**)node
)->ut_pc
;
165 fwrite(&tb
, sizeof(tb
), 1, stdout
);
172 twalk((struct utab
*)root
, print_node
);