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 */
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 * acctprc2 <ptmp1 >ptacct
32 * reads std. input (in ptmp.h/ascii format)
33 * hashes items with identical uid/name together, sums times
34 * sorts in uid/name order, writes tacct.h records to output
37 #include <sys/types.h>
38 #include <sys/param.h>
51 float ut_cpu
[2]; /* cpu time (mins) */
52 float ut_kcore
[2]; /* kcore-mins */
53 long ut_pc
; /* # processes */
60 void enter(struct ptmp
*);
63 main(int argc
, char **argv
)
66 while (scanf("%ld\t%s\t%lu\t%lu\t%u",
69 &pb
.pt_cpu
[0], &pb
.pt_cpu
[1],
76 int node_compare(const void *node1
, const void *node2
)
78 if (((const struct utab
*)node1
)->ut_uid
> \
79 ((const struct utab
*)node2
)->ut_uid
)
81 else if (((const struct utab
*)node1
)->ut_uid
< \
82 ((const struct utab
*)node2
)->ut_uid
)
84 else return(strcmp(((const struct utab
*) node1
)->ut_name
,
85 ((const struct utab
*) node2
)->ut_name
));
96 /* clear end of short users' names */
97 for(i
= strlen(p
->pt_name
) + 1; i
< NSZ
; p
->pt_name
[i
++] = '\0') ;
99 if ((ub
= (struct utab
*)malloc(sizeof (struct utab
))) == NULL
) {
100 fprintf(stderr
, "acctprc2: malloc fail!\n");
104 ub
->ut_uid
= p
->pt_uid
;
105 CPYN(ub
->ut_name
, p
->pt_name
);
106 ub
->ut_cpu
[0] = MINT(p
->pt_cpu
[0]);
107 ub
->ut_cpu
[1] = MINT(p
->pt_cpu
[1]);
108 memk
= KCORE(pb
.pt_mem
);
109 ub
->ut_kcore
[0] = memk
* MINT(p
->pt_cpu
[0]);
110 ub
->ut_kcore
[1] = memk
* MINT(p
->pt_cpu
[1]);
113 if (*(pt
= (struct utab
**)tsearch((void *)ub
, (void **)&root
, \
114 node_compare
)) == NULL
) {
115 fprintf(stderr
, "Not enough space available to build tree\n");
120 (*pt
)->ut_cpu
[0] += MINT(p
->pt_cpu
[0]);
121 (*pt
)->ut_cpu
[1] += MINT(p
->pt_cpu
[1]);
122 (*pt
)->ut_kcore
[0] += memk
* MINT(p
->pt_cpu
[0]);
123 (*pt
)->ut_kcore
[1] += memk
* MINT(p
->pt_cpu
[1]);
129 void print_node(const void *node
, VISIT order
, int level
) {
130 if (order
== postorder
|| order
== leaf
) {
131 tb
.ta_uid
= (*(struct utab
**)node
)->ut_uid
;
132 CPYN(tb
.ta_name
, (*(struct utab
**)node
)->ut_name
);
133 tb
.ta_cpu
[0] = ((*(struct utab
**)node
)->ut_cpu
[0]);
134 tb
.ta_cpu
[1] = ((*(struct utab
**)node
)->ut_cpu
[1]);
135 tb
.ta_kcore
[0] = (*(struct utab
**)node
)->ut_kcore
[0];
136 tb
.ta_kcore
[1] = (*(struct utab
**)node
)->ut_kcore
[1];
137 tb
.ta_pc
= (*(struct utab
**)node
)->ut_pc
;
138 fwrite(&tb
, sizeof(tb
), 1, stdout
);
145 twalk((struct utab
*)root
, print_node
);