acctmerg.c revision 414388d7cb2ee98771e2ac7c2338c460abd44304
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * CDDL HEADER START
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * The contents of this file are subject to the terms of the
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * Common Development and Distribution License, Version 1.0 only
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * (the "License"). You may not use this file except in compliance
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * with the License.
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * See the License for the specific language governing permissions
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * and limitations under the License.
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * When distributing Covered Code, include this CDDL HEADER in each
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * If applicable, add the following below this CDDL HEADER, with the
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * fields enclosed by brackets "[]" replaced with your own identifying
cc6ccc94bd50cdd55be1e94c95826b7820dde91cDavid Luna * information: Portions Copyright [yyyy] [name of copyright owner]
cc6ccc94bd50cdd55be1e94c95826b7820dde91cDavid Luna * CDDL HEADER END
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
4f39fae2f8671f7389a26412a6203c455b80f06dDavid Luna/* All Rights Reserved */
cc6ccc94bd50cdd55be1e94c95826b7820dde91cDavid Luna * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * Use is subject to license terms.
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings#pragma ident "%Z%%M% %I% %E% SMI"
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * acctmerg [-a] [-i] [-p] [-t] [-u] [-v] [file...]
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * -a output in tacct.h/ascii (instead of tacct.h)
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * -i input is in tacct.h/ascii (instead of tacct.h)
8279d2cb2de322c2dd643c10b0722a32f5eca939David Luna * -p print input files with no processing
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * -t output single record that totals all input
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * -u summarize by uid, rather than uid/name
716579c1eaca460b012b046afe7c50107eff7081David Luna * -v output in verbose tacct.h/ascii
716579c1eaca460b012b046afe7c50107eff7081David Luna * reads std input and 0-NFILE files, all in tacct.h format,
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * sorted by uid/name.
37183f9f7fc44e4a154cfc28805bf2719e13f6a6Diego Colantoni * merge/adds all records with same uid/name (or same uid if -u,
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * or all records if -t], writes to std. output
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * (still in tacct.h format)
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * note that this can be used to summarize the std input
716579c1eaca460b012b046afe7c50107eff7081David Lunastruct tacct tb[NFILE]; /* current record from each file */
cc6ccc94bd50cdd55be1e94c95826b7820dde91cDavid Luna while (--argc > 0) {
cc6ccc94bd50cdd55be1e94c95826b7820dde91cDavid Luna switch (*++*argv) {
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings fprintf(stderr, "acctmerg: >%d files\n", NFILE);
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings if ((fl[nfile] = fopen(*argv, "r")) == NULL) {
4f39fae2f8671f7389a26412a6203c455b80f06dDavid Luna fprintf(stderr, "acctmerg: can't open %s\n", *argv);
fcd6acb1b62bf3deb3c74185be351e86cf636325David Luna /* exit(1); */
8279d2cb2de322c2dd643c10b0722a32f5eca939David Luna for (i = 0; i <= nfile; i++)
c45f849ecddd875604998c51bda1f1b14ae86f98Peter Major for (i = 0; i <= nfile; i++)
c45f849ecddd875604998c51bda1f1b14ae86f98Peter Major if(getnext(i) == 0) {
716579c1eaca460b012b046afe7c50107eff7081David Luna fprintf(stderr,"acctmerg: read error file %d. File may be empty.\n", i);
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings while ((tp = getleast()) != NULL) /* get least uid of all files, */
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings sumcurr(tp); /* sum all entries for that uid, */
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings if (totalonly) /* and write the 'summed' record */
4f39fae2f8671f7389a26412a6203c455b80f06dDavid Luna * getleast returns ptr to least (lowest uid) element of current
4f39fae2f8671f7389a26412a6203c455b80f06dDavid Luna * avail, NULL if none left; always returns 1st of equals
4f39fae2f8671f7389a26412a6203c455b80f06dDavid Luna (strncmp(tp->ta_name, least->ta_name, NSZ) < 0)))
fcd6acb1b62bf3deb3c74185be351e86cf636325David Luna * sumcurr sums all entries with same uid/name (into tp->tacct record)
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * writes it out, gets new entry
fcd6acb1b62bf3deb3c74185be351e86cf636325David Luna getnext(tp-&tb[0]); /* get next one in same file */
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings t1->ta_cpu[0] = t1->ta_cpu[0] + t2->ta_cpu[0];
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings t1->ta_cpu[1] = t1->ta_cpu[1] + t2->ta_cpu[1];
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings t1->ta_kcore[0] = t1->ta_kcore[0] + t2->ta_kcore[0];
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings t1->ta_kcore[1] = t1->ta_kcore[1] + t2->ta_kcore[1];
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings t1->ta_con[0] = t1->ta_con[0] + t2->ta_con[0];
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings * getnext reads next record from stream i, returns 1 if one existed
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbings "%ld\t%s\t%e %e %e %e %e %e %e %lu\t%hu\t%hu\t%hu",
cc6ccc94bd50cdd55be1e94c95826b7820dde91cDavid Lunachar fmt[] = "%ld\t%.*s\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\t%lu\t%hu\t%hu\t%hu\n";
d3017d563ca61f904d4baff6fcd4de8e0f748a82Ken Stubbingschar fmtv[] = "%ld\t%.*s\t%e %e %e %e %e %e %e %lu %hu\t%hu\t%hu\n";