17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate * acctcms [-a] [-c] [-j] [-n] [-s] [-p] [-o] [-t] [file...]
357c478bd9Sstevel@tonic-gate * summarize per-process accounting
367c478bd9Sstevel@tonic-gate * -a output in ascii, rather than [pt]cms.h format
377c478bd9Sstevel@tonic-gate * -c sort by total cpu, rather than total kcore-minutes
387c478bd9Sstevel@tonic-gate * -j anything used only once -> ***other
397c478bd9Sstevel@tonic-gate * -n sort by number of processes
407c478bd9Sstevel@tonic-gate * -s any following files already in pcms.h format
417c478bd9Sstevel@tonic-gate * -p output prime time command summary (only with -a)
427c478bd9Sstevel@tonic-gate * -o output non-prime time (offshift) command summary (only
437c478bd9Sstevel@tonic-gate * with -a option)
447c478bd9Sstevel@tonic-gate * -t process records in total (old) style (tcms.h) format
457c478bd9Sstevel@tonic-gate * file file in [pt]cms.h (if -s seen already) or acct.h (if not)
467c478bd9Sstevel@tonic-gate * expected use:
477c478bd9Sstevel@tonic-gate * acctcms /var/adm/pacct? > today; acctcms -s old today >new
487c478bd9Sstevel@tonic-gate * cp new old; rm new
497c478bd9Sstevel@tonic-gate * acctcms -a today; acctcms -a old
507c478bd9Sstevel@tonic-gate */
517c478bd9Sstevel@tonic-gate #include <stdio.h>
527c478bd9Sstevel@tonic-gate #include <sys/types.h>
537c478bd9Sstevel@tonic-gate #include <sys/param.h>
547c478bd9Sstevel@tonic-gate #include "acctdef.h"
557c478bd9Sstevel@tonic-gate #include <ctype.h>
56*414388d7Ssl108498 #include <string.h>
577c478bd9Sstevel@tonic-gate #include <sys/acct.h>
58*414388d7Ssl108498 #include <stdlib.h>
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate int csize = CSIZE;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate * Total cms records format
647c478bd9Sstevel@tonic-gate */
657c478bd9Sstevel@tonic-gate struct tcms {
667c478bd9Sstevel@tonic-gate char tcm_comm[8]; /* command name */
677c478bd9Sstevel@tonic-gate long tcm_pc; /* number of processes */
687c478bd9Sstevel@tonic-gate float tcm_cpu; /* cpu time(min) */
697c478bd9Sstevel@tonic-gate float tcm_real; /* real time(min) */
707c478bd9Sstevel@tonic-gate float tcm_kcore; /* kcore-minutes */
717c478bd9Sstevel@tonic-gate ulong_t tcm_io; /* chars transferred */
727c478bd9Sstevel@tonic-gate ulong_t tcm_rw; /* blocks read */
737c478bd9Sstevel@tonic-gate } ;
747c478bd9Sstevel@tonic-gate struct tcms *tcm;
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate * prime/nonprime CMS record format
777c478bd9Sstevel@tonic-gate */
787c478bd9Sstevel@tonic-gate struct pcms {
797c478bd9Sstevel@tonic-gate char pcm_comm[8]; /* command name */
807c478bd9Sstevel@tonic-gate long pcm_pc[2]; /* number of processes */
817c478bd9Sstevel@tonic-gate float pcm_cpu[2]; /* cpu time(min) */
827c478bd9Sstevel@tonic-gate float pcm_real[2]; /* real time(min) */
837c478bd9Sstevel@tonic-gate float pcm_kcore[2]; /* kcore-minutes */
847c478bd9Sstevel@tonic-gate float pcm_io[2]; /* chars transferred */
857c478bd9Sstevel@tonic-gate float pcm_rw[2]; /* blocks read */
867c478bd9Sstevel@tonic-gate } ;
877c478bd9Sstevel@tonic-gate struct pcms *pcm;
887c478bd9Sstevel@tonic-gate struct tcms tcmtmp = {{'*','*','*','o','t','h','e','r'}};
897c478bd9Sstevel@tonic-gate struct pcms pcmtmp = {{'*','*','*','o','t','h','e','r'}};
907c478bd9Sstevel@tonic-gate int aflg;
917c478bd9Sstevel@tonic-gate int cflg;
927c478bd9Sstevel@tonic-gate int jflg;
937c478bd9Sstevel@tonic-gate int nflg;
947c478bd9Sstevel@tonic-gate int sflg;
957c478bd9Sstevel@tonic-gate int pflg;
967c478bd9Sstevel@tonic-gate int oflg;
977c478bd9Sstevel@tonic-gate int tflg;
987c478bd9Sstevel@tonic-gate int errflg;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate #ifdef uts
1017c478bd9Sstevel@tonic-gate float expand();
1027c478bd9Sstevel@tonic-gate #else
1037c478bd9Sstevel@tonic-gate ulong_t expand();
1047c478bd9Sstevel@tonic-gate #endif
1057c478bd9Sstevel@tonic-gate
106*414388d7Ssl108498 void outputc(void);
107*414388d7Ssl108498 void totprnt(struct pcms *);
108*414388d7Ssl108498 void pprint(struct pcms *);
109*414388d7Ssl108498 void prnt(struct pcms *, int);
110*414388d7Ssl108498 void print(struct pcms *);
111*414388d7Ssl108498 void outputa(void);
112*414388d7Ssl108498 void toutptc(void);
113*414388d7Ssl108498 void tprint(struct tcms *);
114*414388d7Ssl108498 void toutpta(void);
115*414388d7Ssl108498 int ncmp(struct pcms *, struct pcms *);
116*414388d7Ssl108498 int tncmp(struct tcms *, struct tcms *);
117*414388d7Ssl108498 int tccmp(struct tcms *, struct tcms *);
118*414388d7Ssl108498 int tkcmp(struct tcms *, struct tcms *);
119*414388d7Ssl108498 int ccmp(struct pcms *, struct pcms *);
120*414388d7Ssl108498 int kcmp(struct pcms *, struct pcms *);
121*414388d7Ssl108498 void tdofile(char *);
122*414388d7Ssl108498 void dofile(char *);
123*414388d7Ssl108498 void tfixjunk(void);
124*414388d7Ssl108498 void fixjunk(void);
125*414388d7Ssl108498 void tcmadd(struct tcms *, struct tcms *);
126*414388d7Ssl108498 void pcmadd(struct pcms *, struct pcms *);
127*414388d7Ssl108498 void tsqueeze(void);
128*414388d7Ssl108498 void squeeze(void);
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate /* Format specification for ASCII printing */
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate char *fmtcmd = "%-8.8s",
1337c478bd9Sstevel@tonic-gate *fmtcnt = "%8ld",
1347c478bd9Sstevel@tonic-gate *fmtkcore = " %11.2f",
1357c478bd9Sstevel@tonic-gate *fmtcpu = " %9.2f",
1367c478bd9Sstevel@tonic-gate *fmtreal = " %12.2f",
1377c478bd9Sstevel@tonic-gate *fmtmsz = " %7.2f",
1387c478bd9Sstevel@tonic-gate *fmtmcpu = " %6.2f",
1397c478bd9Sstevel@tonic-gate *fmthog = " %5.2f",
1407c478bd9Sstevel@tonic-gate *fmtcharx = " %12.0f",
1417c478bd9Sstevel@tonic-gate *fmtblkx = " %10.0f" ;
1427c478bd9Sstevel@tonic-gate
143*414388d7Ssl108498 int
main(int argc,char ** argv)144*414388d7Ssl108498 main(int argc, char **argv)
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate int c;
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate while((c = getopt(argc, argv, "acjnspot")) != EOF)
1497c478bd9Sstevel@tonic-gate switch(c) {
1507c478bd9Sstevel@tonic-gate case 'a':
1517c478bd9Sstevel@tonic-gate aflg++;
1527c478bd9Sstevel@tonic-gate continue;
1537c478bd9Sstevel@tonic-gate case 'c':
1547c478bd9Sstevel@tonic-gate cflg++;
1557c478bd9Sstevel@tonic-gate continue;
1567c478bd9Sstevel@tonic-gate case 'j':
1577c478bd9Sstevel@tonic-gate jflg++;
1587c478bd9Sstevel@tonic-gate continue;
1597c478bd9Sstevel@tonic-gate case 'n':
1607c478bd9Sstevel@tonic-gate nflg++;
1617c478bd9Sstevel@tonic-gate continue;
1627c478bd9Sstevel@tonic-gate case 's':
1637c478bd9Sstevel@tonic-gate sflg++;
1647c478bd9Sstevel@tonic-gate continue;
1657c478bd9Sstevel@tonic-gate case 'p':
1667c478bd9Sstevel@tonic-gate pflg++;
1677c478bd9Sstevel@tonic-gate continue;
1687c478bd9Sstevel@tonic-gate case 'o':
1697c478bd9Sstevel@tonic-gate oflg++;
1707c478bd9Sstevel@tonic-gate continue;
1717c478bd9Sstevel@tonic-gate case 't':
1727c478bd9Sstevel@tonic-gate tflg++;
1737c478bd9Sstevel@tonic-gate continue;
1747c478bd9Sstevel@tonic-gate default:
1757c478bd9Sstevel@tonic-gate errflg++;
1767c478bd9Sstevel@tonic-gate continue;
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate if(errflg){
1797c478bd9Sstevel@tonic-gate fprintf(stderr, "Usage: %s [-acjnspot] [file ...]\n", argv[0]);
1807c478bd9Sstevel@tonic-gate exit(1);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate if(tflg) {
1837c478bd9Sstevel@tonic-gate if( (tcm = (struct tcms *)calloc(CSIZE, sizeof(struct tcms))) == NULL) {
1847c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Cannot allocate memory\n", argv[0]);
1857c478bd9Sstevel@tonic-gate exit(5);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate for(; optind < argc; optind++)
1887c478bd9Sstevel@tonic-gate tdofile(argv[optind]);
1897c478bd9Sstevel@tonic-gate if (jflg)
1907c478bd9Sstevel@tonic-gate tfixjunk();
1917c478bd9Sstevel@tonic-gate tsqueeze();
192*414388d7Ssl108498 qsort(tcm, csize, sizeof(tcm[0]),
193*414388d7Ssl108498 (int (*)(const void *, const void *))
194*414388d7Ssl108498 ( nflg ? tncmp: (cflg? tccmp: tkcmp)));
1957c478bd9Sstevel@tonic-gate if (aflg)
1967c478bd9Sstevel@tonic-gate toutpta();
1977c478bd9Sstevel@tonic-gate else
1987c478bd9Sstevel@tonic-gate toutptc();
1997c478bd9Sstevel@tonic-gate } else {
2007c478bd9Sstevel@tonic-gate if( (pcm = (struct pcms *)calloc(CSIZE, sizeof(struct pcms))) == NULL) {
2017c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Cannot allocate memory\n", argv[0]);
2027c478bd9Sstevel@tonic-gate exit(6);
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate for(; optind < argc; optind++)
2057c478bd9Sstevel@tonic-gate dofile(argv[optind]);
2067c478bd9Sstevel@tonic-gate if (jflg)
2077c478bd9Sstevel@tonic-gate fixjunk();
2087c478bd9Sstevel@tonic-gate squeeze();
209*414388d7Ssl108498 qsort(pcm, csize, sizeof(pcm[0]),
210*414388d7Ssl108498 (int (*)(const void *, const void *))
211*414388d7Ssl108498 (nflg? ncmp: (cflg? ccmp: kcmp)));
2127c478bd9Sstevel@tonic-gate if (aflg)
2137c478bd9Sstevel@tonic-gate outputa();
2147c478bd9Sstevel@tonic-gate else
2157c478bd9Sstevel@tonic-gate outputc();
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate exit(0);
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
221*414388d7Ssl108498 void
tdofile(char * fname)222*414388d7Ssl108498 tdofile(char *fname)
2237c478bd9Sstevel@tonic-gate {
2247c478bd9Sstevel@tonic-gate struct tcms cmt;
2257c478bd9Sstevel@tonic-gate union {
2267c478bd9Sstevel@tonic-gate struct acct ab; /* SVR4 acct structure */
2277c478bd9Sstevel@tonic-gate struct o_acct oab; /* SVR3 acct structure */
2287c478bd9Sstevel@tonic-gate } acct;
2297c478bd9Sstevel@tonic-gate int ver = 0;
2307c478bd9Sstevel@tonic-gate ulong_t mem;
2317c478bd9Sstevel@tonic-gate ulong_t cpu;
2327c478bd9Sstevel@tonic-gate ulong_t real;
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate if (freopen(fname, "r", stdin) == NULL) {
2357c478bd9Sstevel@tonic-gate fprintf(stderr, "acctcms: cannot open %s\n", fname);
2367c478bd9Sstevel@tonic-gate return;
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate if (sflg)
2407c478bd9Sstevel@tonic-gate while (fread(&cmt, sizeof(cmt), 1, stdin) == 1)
2417c478bd9Sstevel@tonic-gate tenter(&cmt);
2427c478bd9Sstevel@tonic-gate else {
2437c478bd9Sstevel@tonic-gate if (fread(&acct.ab, sizeof(acct.ab), 1, stdin) == 1)
2447c478bd9Sstevel@tonic-gate /* check for expanded account structure flag */
2457c478bd9Sstevel@tonic-gate if (acct.ab.ac_flag & AEXPND)
2467c478bd9Sstevel@tonic-gate ver = 2; /* 4.0 acct file */
2477c478bd9Sstevel@tonic-gate else
2487c478bd9Sstevel@tonic-gate ver = 1; /* SVR3.x acct file */
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate rewind(stdin); /* reset file pointer */
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate switch(ver) {
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate default:
2557c478bd9Sstevel@tonic-gate /* this can't happen */
2567c478bd9Sstevel@tonic-gate fprintf(stderr, "acctcms: encountered bad version number\n");
2577c478bd9Sstevel@tonic-gate return;
2587c478bd9Sstevel@tonic-gate case 1 :
2597c478bd9Sstevel@tonic-gate while (fread(&acct.oab, sizeof(acct.oab), 1, stdin) == 1) {
2607c478bd9Sstevel@tonic-gate CPYN(cmt.tcm_comm, acct.oab.ac_comm);
2617c478bd9Sstevel@tonic-gate cmt.tcm_pc = 1;
2627c478bd9Sstevel@tonic-gate cpu = expand(acct.oab.ac_stime)+
2637c478bd9Sstevel@tonic-gate expand(acct.oab.ac_utime);
2647c478bd9Sstevel@tonic-gate cmt.tcm_cpu = MINT(cpu);
2657c478bd9Sstevel@tonic-gate real = expand(acct.oab.ac_etime);
2667c478bd9Sstevel@tonic-gate cmt.tcm_real = MINT(real);
2677c478bd9Sstevel@tonic-gate mem = expand(acct.oab.ac_mem);
2687c478bd9Sstevel@tonic-gate cmt.tcm_kcore = MINT(KCORE(mem));
2697c478bd9Sstevel@tonic-gate cmt.tcm_io = expand(acct.oab.ac_io);
2707c478bd9Sstevel@tonic-gate cmt.tcm_rw = expand(acct.oab.ac_rw);
2717c478bd9Sstevel@tonic-gate tenter(&cmt);
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate break;
2747c478bd9Sstevel@tonic-gate case 2 :
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate while (fread(&acct.ab, sizeof(acct.ab), 1, stdin) == 1) {
2777c478bd9Sstevel@tonic-gate CPYN(cmt.tcm_comm, acct.ab.ac_comm);
2787c478bd9Sstevel@tonic-gate cmt.tcm_pc = 1;
2797c478bd9Sstevel@tonic-gate cpu = expand(acct.oab.ac_stime)+
2807c478bd9Sstevel@tonic-gate expand(acct.oab.ac_utime);
2817c478bd9Sstevel@tonic-gate cmt.tcm_cpu = MINT(cpu);
2827c478bd9Sstevel@tonic-gate real = expand(acct.ab.ac_etime);
2837c478bd9Sstevel@tonic-gate cmt.tcm_real = MINT(real);
2847c478bd9Sstevel@tonic-gate mem = expand(acct.ab.ac_mem);
2857c478bd9Sstevel@tonic-gate cmt.tcm_kcore = MINT(KCORE(mem));
2867c478bd9Sstevel@tonic-gate cmt.tcm_io = expand(acct.ab.ac_io);
2877c478bd9Sstevel@tonic-gate cmt.tcm_rw = expand(acct.ab.ac_rw);
2887c478bd9Sstevel@tonic-gate tenter(&cmt);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate break;
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate
295*414388d7Ssl108498 void
dofile(char * fname)296*414388d7Ssl108498 dofile(char *fname)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate union {
2997c478bd9Sstevel@tonic-gate struct acct ab;
3007c478bd9Sstevel@tonic-gate struct o_acct oab;
3017c478bd9Sstevel@tonic-gate } acct;
3027c478bd9Sstevel@tonic-gate struct pcms pcmt;
3037c478bd9Sstevel@tonic-gate double ratio;
3047c478bd9Sstevel@tonic-gate long elaps[2];
3057c478bd9Sstevel@tonic-gate ulong_t etime;
3067c478bd9Sstevel@tonic-gate double dtmp;
3077c478bd9Sstevel@tonic-gate unsigned long ltmp;
3087c478bd9Sstevel@tonic-gate ulong_t mem;
3097c478bd9Sstevel@tonic-gate ulong_t cpu;
3107c478bd9Sstevel@tonic-gate ulong_t real;
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate if (freopen(fname, "r", stdin) == NULL) {
3137c478bd9Sstevel@tonic-gate fprintf(stderr, "acctcms: cannot open %s\n", fname);
3147c478bd9Sstevel@tonic-gate return;
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate if (sflg)
3187c478bd9Sstevel@tonic-gate while (fread(&pcmt, sizeof(pcmt), 1, stdin) == 1)
3197c478bd9Sstevel@tonic-gate enter(&pcmt);
3207c478bd9Sstevel@tonic-gate else {
3217c478bd9Sstevel@tonic-gate int ver = 0;
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate if (fread(&acct.ab, sizeof(acct.ab), 1, stdin) == 1)
3247c478bd9Sstevel@tonic-gate /* check for expanded account structure flag */
3257c478bd9Sstevel@tonic-gate if (acct.ab.ac_flag & AEXPND)
3267c478bd9Sstevel@tonic-gate ver = 2; /* 4.0 acct file */
3277c478bd9Sstevel@tonic-gate else
3287c478bd9Sstevel@tonic-gate ver = 1; /* SVR3.x acct file */
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate rewind(stdin); /* reset file pointer */
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate switch(ver) {
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate default :
3357c478bd9Sstevel@tonic-gate /* this can't happen */
3367c478bd9Sstevel@tonic-gate fprintf(stderr, "acctcms: encountered bad version number\n");
3377c478bd9Sstevel@tonic-gate return;
3387c478bd9Sstevel@tonic-gate case 1 :
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate while (fread(&acct.oab, sizeof(acct.oab), 1, stdin) == 1) {
3417c478bd9Sstevel@tonic-gate CPYN(pcmt.pcm_comm, acct.oab.ac_comm);
3427c478bd9Sstevel@tonic-gate /*
3437c478bd9Sstevel@tonic-gate ** Approximate P/NP split as same as elapsed time
3447c478bd9Sstevel@tonic-gate */
3457c478bd9Sstevel@tonic-gate if((etime = SECS(expand(acct.oab.ac_etime))) == 0)
3467c478bd9Sstevel@tonic-gate etime = 1;
3477c478bd9Sstevel@tonic-gate if (pnpsplit(acct.oab.ac_btime, etime, elaps)
3487c478bd9Sstevel@tonic-gate == 0) {
3497c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "acctcms: could "
3507c478bd9Sstevel@tonic-gate "not calculate prime/non-prime "
3517c478bd9Sstevel@tonic-gate "hours\n");
3527c478bd9Sstevel@tonic-gate exit(1);
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate ratio = (double)elaps[PRIME]/(double)etime;
3557c478bd9Sstevel@tonic-gate if(elaps[PRIME] > elaps[NONPRIME]) {
3567c478bd9Sstevel@tonic-gate pcmt.pcm_pc[PRIME] = 1;
3577c478bd9Sstevel@tonic-gate pcmt.pcm_pc[NONPRIME] = 0;
3587c478bd9Sstevel@tonic-gate } else {
3597c478bd9Sstevel@tonic-gate pcmt.pcm_pc[PRIME] = 0;
3607c478bd9Sstevel@tonic-gate pcmt.pcm_pc[NONPRIME] = 1;
3617c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate cpu = expand(acct.oab.ac_stime)+
3637c478bd9Sstevel@tonic-gate expand(acct.oab.ac_utime);
3647c478bd9Sstevel@tonic-gate dtmp = MINT(cpu);
3657c478bd9Sstevel@tonic-gate pcmt.pcm_cpu[PRIME] = dtmp * ratio;
3667c478bd9Sstevel@tonic-gate pcmt.pcm_cpu[NONPRIME] = (ratio == 1.0) ? 0.0 :
3677c478bd9Sstevel@tonic-gate (dtmp - pcmt.pcm_cpu[PRIME]);
3687c478bd9Sstevel@tonic-gate real = expand(acct.oab.ac_etime);
3697c478bd9Sstevel@tonic-gate dtmp = MINT(real);
3707c478bd9Sstevel@tonic-gate pcmt.pcm_real[PRIME] = dtmp * ratio;
3717c478bd9Sstevel@tonic-gate pcmt.pcm_real[NONPRIME] = (ratio == 1.0) ? 0.0 :
3727c478bd9Sstevel@tonic-gate (dtmp - pcmt.pcm_real[PRIME]);
3737c478bd9Sstevel@tonic-gate mem = expand(acct.oab.ac_mem);
3747c478bd9Sstevel@tonic-gate dtmp = MINT(KCORE(mem));
3757c478bd9Sstevel@tonic-gate pcmt.pcm_kcore[PRIME] = dtmp * ratio;
3767c478bd9Sstevel@tonic-gate pcmt.pcm_kcore[NONPRIME] = (ratio == 1.0) ? 0.0 :
3777c478bd9Sstevel@tonic-gate (dtmp - pcmt.pcm_kcore[PRIME]);
3787c478bd9Sstevel@tonic-gate ltmp = expand(acct.oab.ac_io);
3797c478bd9Sstevel@tonic-gate pcmt.pcm_io[PRIME] = (double)ltmp * ratio;
3807c478bd9Sstevel@tonic-gate pcmt.pcm_io[NONPRIME] = (ratio == 1.0) ? 0.0 :
3817c478bd9Sstevel@tonic-gate ((double)ltmp - pcmt.pcm_io[PRIME]);
3827c478bd9Sstevel@tonic-gate ltmp = expand(acct.oab.ac_rw);
3837c478bd9Sstevel@tonic-gate pcmt.pcm_rw[PRIME] = (double)ltmp * ratio;
3847c478bd9Sstevel@tonic-gate pcmt.pcm_rw[NONPRIME] = (ratio == 1.0) ? 0.0 :
3857c478bd9Sstevel@tonic-gate ((double)ltmp - pcmt.pcm_rw[PRIME]);
3867c478bd9Sstevel@tonic-gate enter(&pcmt);
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate break;
3907c478bd9Sstevel@tonic-gate case 2 :
3917c478bd9Sstevel@tonic-gate while (fread(&acct.ab, sizeof(acct.ab), 1, stdin) == 1) {
3927c478bd9Sstevel@tonic-gate CPYN(pcmt.pcm_comm, acct.ab.ac_comm);
3937c478bd9Sstevel@tonic-gate /*
3947c478bd9Sstevel@tonic-gate ** Approximate P/NP split as same as elapsed time
3957c478bd9Sstevel@tonic-gate */
3967c478bd9Sstevel@tonic-gate if((etime = SECS(expand(acct.ab.ac_etime))) == 0)
3977c478bd9Sstevel@tonic-gate etime = 1;
3987c478bd9Sstevel@tonic-gate if(pnpsplit(acct.ab.ac_btime, etime, elaps) == 0) {
3997c478bd9Sstevel@tonic-gate fprintf(stderr, "acctcms: could not calculate prime/non-prime hours\n");
4007c478bd9Sstevel@tonic-gate exit(1);
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate ratio = (double)elaps[PRIME]/(double)etime;
4037c478bd9Sstevel@tonic-gate if(elaps[PRIME] > elaps[NONPRIME]) {
4047c478bd9Sstevel@tonic-gate pcmt.pcm_pc[PRIME] = 1;
4057c478bd9Sstevel@tonic-gate pcmt.pcm_pc[NONPRIME] = 0;
4067c478bd9Sstevel@tonic-gate } else {
4077c478bd9Sstevel@tonic-gate pcmt.pcm_pc[PRIME] = 0;
4087c478bd9Sstevel@tonic-gate pcmt.pcm_pc[NONPRIME] = 1;
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate cpu = expand(acct.ab.ac_stime)+
4117c478bd9Sstevel@tonic-gate expand(acct.ab.ac_utime);
4127c478bd9Sstevel@tonic-gate dtmp = MINT(cpu);
4137c478bd9Sstevel@tonic-gate pcmt.pcm_cpu[PRIME] = dtmp * ratio;
4147c478bd9Sstevel@tonic-gate pcmt.pcm_cpu[NONPRIME] = (ratio == 1.0) ? 0.0 :
4157c478bd9Sstevel@tonic-gate (dtmp - pcmt.pcm_cpu[PRIME]);
4167c478bd9Sstevel@tonic-gate real = expand(acct.ab.ac_etime);
4177c478bd9Sstevel@tonic-gate dtmp = MINT(real);
4187c478bd9Sstevel@tonic-gate pcmt.pcm_real[PRIME] = dtmp * ratio;
4197c478bd9Sstevel@tonic-gate pcmt.pcm_real[NONPRIME] = (ratio == 1.0) ? 0.0 :
4207c478bd9Sstevel@tonic-gate (dtmp - pcmt.pcm_real[PRIME]);
4217c478bd9Sstevel@tonic-gate mem = expand(acct.ab.ac_mem);
4227c478bd9Sstevel@tonic-gate dtmp = MINT(KCORE(mem));
4237c478bd9Sstevel@tonic-gate pcmt.pcm_kcore[PRIME] = dtmp * ratio;
4247c478bd9Sstevel@tonic-gate pcmt.pcm_kcore[NONPRIME] = (ratio == 1.0) ? 0.0 :
4257c478bd9Sstevel@tonic-gate (dtmp - pcmt.pcm_kcore[PRIME]);
4267c478bd9Sstevel@tonic-gate ltmp = expand(acct.ab.ac_io);
4277c478bd9Sstevel@tonic-gate pcmt.pcm_io[PRIME] = (double)ltmp * ratio;
4287c478bd9Sstevel@tonic-gate pcmt.pcm_io[NONPRIME] = (ratio == 1.0) ? 0.0 :
4297c478bd9Sstevel@tonic-gate ((double)ltmp - pcmt.pcm_io[PRIME]);
4307c478bd9Sstevel@tonic-gate ltmp = expand(acct.ab.ac_rw);
4317c478bd9Sstevel@tonic-gate pcmt.pcm_rw[PRIME] = (double)ltmp * ratio;
4327c478bd9Sstevel@tonic-gate pcmt.pcm_rw[NONPRIME] = (ratio == 1.0) ? 0.0 :
4337c478bd9Sstevel@tonic-gate ((double)ltmp - pcmt.pcm_rw[PRIME]);
4347c478bd9Sstevel@tonic-gate enter(&pcmt);
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate break;
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate
442*414388d7Ssl108498 int
tenter(struct tcms * p)443*414388d7Ssl108498 tenter(struct tcms *p)
4447c478bd9Sstevel@tonic-gate {
445*414388d7Ssl108498 int i;
446*414388d7Ssl108498 int j;
447*414388d7Ssl108498 struct tcms *ntcm;
4487c478bd9Sstevel@tonic-gate for (i = j = 0; j < sizeof(p->tcm_comm); j++) {
4497c478bd9Sstevel@tonic-gate if (p->tcm_comm[j] && p->tcm_comm[j] <= 037)
4507c478bd9Sstevel@tonic-gate p->tcm_comm[j] = '?';
4517c478bd9Sstevel@tonic-gate i = i*7 + p->tcm_comm[j]; /* hash function */
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate if (i < 0)
4547c478bd9Sstevel@tonic-gate i = -i;
4557c478bd9Sstevel@tonic-gate for (i %= csize, j = 0; tcm[i].tcm_comm[0] && j != csize; i = (i+1)%csize, j++)
4567c478bd9Sstevel@tonic-gate if (EQN(p->tcm_comm, tcm[i].tcm_comm))
4577c478bd9Sstevel@tonic-gate break;
4587c478bd9Sstevel@tonic-gate if(j == csize) {
4597c478bd9Sstevel@tonic-gate if ((ntcm = (struct tcms *) realloc(tcm,
4607c478bd9Sstevel@tonic-gate (csize + CSIZE - 1) * sizeof (struct tcms))) == NULL) {
4617c478bd9Sstevel@tonic-gate fprintf(stderr,
4627c478bd9Sstevel@tonic-gate "acctcms: Cannot reallocate memory (tcm)\n");
4637c478bd9Sstevel@tonic-gate return(-1);
4647c478bd9Sstevel@tonic-gate } else {
4657c478bd9Sstevel@tonic-gate memset(&ntcm[csize], 0, CSIZE - 1);
4667c478bd9Sstevel@tonic-gate tcm = ntcm;
4677c478bd9Sstevel@tonic-gate if (!EQN(p->tcm_comm, tcm[i].tcm_comm))
4687c478bd9Sstevel@tonic-gate i = csize;
4697c478bd9Sstevel@tonic-gate csize = csize + CSIZE - 1;
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate if (tcm[i].tcm_comm[0] == 0)
4737c478bd9Sstevel@tonic-gate CPYN(tcm[i].tcm_comm, p->tcm_comm);
4747c478bd9Sstevel@tonic-gate tcmadd(&tcm[i], p);
4757c478bd9Sstevel@tonic-gate return(i);
4767c478bd9Sstevel@tonic-gate }
477*414388d7Ssl108498
478*414388d7Ssl108498 int
enter(struct pcms * p)479*414388d7Ssl108498 enter(struct pcms *p)
4807c478bd9Sstevel@tonic-gate {
481*414388d7Ssl108498 int i;
482*414388d7Ssl108498 int j;
483*414388d7Ssl108498 struct pcms *npcm;
4847c478bd9Sstevel@tonic-gate for (i = j = 0; j < sizeof(p->pcm_comm); j++) {
4857c478bd9Sstevel@tonic-gate if (p->pcm_comm[j] && p->pcm_comm[j] <= 037)
4867c478bd9Sstevel@tonic-gate p->pcm_comm[j] = '?';
4877c478bd9Sstevel@tonic-gate i = i*7 + p->pcm_comm[j]; /* hash function */
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate if (i < 0)
4907c478bd9Sstevel@tonic-gate i = -i;
4917c478bd9Sstevel@tonic-gate for (i %= csize, j = 0; pcm[i].pcm_comm[0] && j != csize; i = (i+1)%csize, j++)
4927c478bd9Sstevel@tonic-gate if (EQN(p->pcm_comm, pcm[i].pcm_comm))
4937c478bd9Sstevel@tonic-gate break;
4947c478bd9Sstevel@tonic-gate if(j == csize) {
4957c478bd9Sstevel@tonic-gate if ((npcm = (struct pcms *) realloc(pcm,
4967c478bd9Sstevel@tonic-gate (csize + CSIZE - 1) * sizeof (struct pcms))) == NULL) {
4977c478bd9Sstevel@tonic-gate fprintf(stderr,
4987c478bd9Sstevel@tonic-gate "acctcms: Cannot reallocate memory (pcm)\n");
4997c478bd9Sstevel@tonic-gate return(-1);
5007c478bd9Sstevel@tonic-gate } else {
5017c478bd9Sstevel@tonic-gate memset(&npcm[csize], 0, CSIZE - 1);
5027c478bd9Sstevel@tonic-gate pcm = npcm;
5037c478bd9Sstevel@tonic-gate if (!EQN(p->pcm_comm, pcm[i].pcm_comm))
5047c478bd9Sstevel@tonic-gate i = csize;
5057c478bd9Sstevel@tonic-gate csize = csize + CSIZE - 1;
5067c478bd9Sstevel@tonic-gate }
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate if (pcm[i].pcm_comm[0] == 0)
5097c478bd9Sstevel@tonic-gate CPYN(pcm[i].pcm_comm, p->pcm_comm);
5107c478bd9Sstevel@tonic-gate pcmadd(&pcm[i], p);
5117c478bd9Sstevel@tonic-gate return(i);
5127c478bd9Sstevel@tonic-gate }
513*414388d7Ssl108498
514*414388d7Ssl108498 void
tfixjunk(void)515*414388d7Ssl108498 tfixjunk(void) /* combine commands used only once */
5167c478bd9Sstevel@tonic-gate {
517*414388d7Ssl108498 int i, j;
518*414388d7Ssl108498 j = tenter(&tcmtmp);
5197c478bd9Sstevel@tonic-gate for (i = 0; i < csize; i++)
5207c478bd9Sstevel@tonic-gate if (i != j && tcm[i].tcm_comm[0] && tcm[i].tcm_pc <= 1) {
5217c478bd9Sstevel@tonic-gate tcmadd(&tcm[j], &tcm[i]);
5227c478bd9Sstevel@tonic-gate tcm[i].tcm_comm[0] = 0;
5237c478bd9Sstevel@tonic-gate }
5247c478bd9Sstevel@tonic-gate }
525*414388d7Ssl108498
526*414388d7Ssl108498 void
fixjunk(void)527*414388d7Ssl108498 fixjunk(void) /* combine commands used only once */
5287c478bd9Sstevel@tonic-gate {
529*414388d7Ssl108498 int i, j;
5307c478bd9Sstevel@tonic-gate j = enter(&pcmtmp);
5317c478bd9Sstevel@tonic-gate for (i = 0; i < csize; i++)
5327c478bd9Sstevel@tonic-gate if (i != j && pcm[i].pcm_comm[0] && (pcm[i].pcm_pc[PRIME] + pcm[i].pcm_pc[NONPRIME]) <= 1) {
5337c478bd9Sstevel@tonic-gate pcmadd(&pcm[j], &pcm[i]);
5347c478bd9Sstevel@tonic-gate pcm[i].pcm_comm[0] = 0;
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate }
5377c478bd9Sstevel@tonic-gate
538*414388d7Ssl108498 void
tcmadd(struct tcms * p1,struct tcms * p2)539*414388d7Ssl108498 tcmadd(struct tcms *p1, struct tcms *p2)
5407c478bd9Sstevel@tonic-gate {
5417c478bd9Sstevel@tonic-gate p1->tcm_pc += p2->tcm_pc;
5427c478bd9Sstevel@tonic-gate p1->tcm_cpu = p1->tcm_cpu + p2->tcm_cpu;
5437c478bd9Sstevel@tonic-gate p1->tcm_real = p1->tcm_real + p2->tcm_real;
5447c478bd9Sstevel@tonic-gate p1->tcm_kcore = p1->tcm_kcore + p2->tcm_kcore;
5457c478bd9Sstevel@tonic-gate p1->tcm_io += p2->tcm_io;
5467c478bd9Sstevel@tonic-gate p1->tcm_rw += p2->tcm_rw;
5477c478bd9Sstevel@tonic-gate }
548*414388d7Ssl108498
549*414388d7Ssl108498 void
pcmadd(struct pcms * p1,struct pcms * p2)550*414388d7Ssl108498 pcmadd(struct pcms *p1, struct pcms *p2)
5517c478bd9Sstevel@tonic-gate {
5527c478bd9Sstevel@tonic-gate p1->pcm_pc[PRIME] += p2->pcm_pc[PRIME];
5537c478bd9Sstevel@tonic-gate p1->pcm_pc[NONPRIME] += p2->pcm_pc[NONPRIME];
5547c478bd9Sstevel@tonic-gate p1->pcm_cpu[PRIME] += p2->pcm_cpu[PRIME];
5557c478bd9Sstevel@tonic-gate p1->pcm_cpu[NONPRIME] += p2->pcm_cpu[NONPRIME];
5567c478bd9Sstevel@tonic-gate p1->pcm_real[PRIME] += p2->pcm_real[PRIME];
5577c478bd9Sstevel@tonic-gate p1->pcm_real[NONPRIME] += p2->pcm_real[NONPRIME];
5587c478bd9Sstevel@tonic-gate p1->pcm_kcore[PRIME] += p2->pcm_kcore[PRIME];
5597c478bd9Sstevel@tonic-gate p1->pcm_kcore[NONPRIME] += p2->pcm_kcore[NONPRIME];
5607c478bd9Sstevel@tonic-gate p1->pcm_io[PRIME] += p2->pcm_io[PRIME];
5617c478bd9Sstevel@tonic-gate p1->pcm_io[NONPRIME] += p2->pcm_io[NONPRIME];
5627c478bd9Sstevel@tonic-gate p1->pcm_rw[PRIME] += p2->pcm_rw[PRIME];
5637c478bd9Sstevel@tonic-gate p1->pcm_rw[NONPRIME] += p2->pcm_rw[NONPRIME];
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate
566*414388d7Ssl108498 void
tsqueeze(void)567*414388d7Ssl108498 tsqueeze(void) /* get rid of holes in hash table */
5687c478bd9Sstevel@tonic-gate {
569*414388d7Ssl108498 int i, k;
5707c478bd9Sstevel@tonic-gate
5717c478bd9Sstevel@tonic-gate for (i = k = 0; i < csize; i++)
5727c478bd9Sstevel@tonic-gate if (tcm[i].tcm_comm[0]) {
5737c478bd9Sstevel@tonic-gate CPYN(tcm[k].tcm_comm, tcm[i].tcm_comm);
5747c478bd9Sstevel@tonic-gate tcm[k].tcm_pc = tcm[i].tcm_pc;
5757c478bd9Sstevel@tonic-gate tcm[k].tcm_cpu = tcm[i].tcm_cpu;
5767c478bd9Sstevel@tonic-gate tcm[k].tcm_real = tcm[i].tcm_real;
5777c478bd9Sstevel@tonic-gate tcm[k].tcm_kcore = tcm[i].tcm_kcore;
5787c478bd9Sstevel@tonic-gate tcm[k].tcm_io = tcm[i].tcm_io;
5797c478bd9Sstevel@tonic-gate tcm[k].tcm_rw = tcm[i].tcm_rw;
5807c478bd9Sstevel@tonic-gate k++;
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate csize = k;
5837c478bd9Sstevel@tonic-gate }
584*414388d7Ssl108498
585*414388d7Ssl108498 void
squeeze(void)586*414388d7Ssl108498 squeeze(void) /* get rid of holes in hash table */
5877c478bd9Sstevel@tonic-gate {
588*414388d7Ssl108498 int i, k;
5897c478bd9Sstevel@tonic-gate
5907c478bd9Sstevel@tonic-gate for (i = k = 0; i < csize; i++)
5917c478bd9Sstevel@tonic-gate if (pcm[i].pcm_comm[0]) {
5927c478bd9Sstevel@tonic-gate CPYN(pcm[k].pcm_comm, pcm[i].pcm_comm);
5937c478bd9Sstevel@tonic-gate pcm[k].pcm_pc[PRIME] = pcm[i].pcm_pc[PRIME];
5947c478bd9Sstevel@tonic-gate pcm[k].pcm_pc[NONPRIME] = pcm[i].pcm_pc[NONPRIME];
5957c478bd9Sstevel@tonic-gate pcm[k].pcm_cpu[PRIME] = pcm[i].pcm_cpu[PRIME];
5967c478bd9Sstevel@tonic-gate pcm[k].pcm_cpu[NONPRIME] = pcm[i].pcm_cpu[NONPRIME];
5977c478bd9Sstevel@tonic-gate pcm[k].pcm_real[PRIME] = pcm[i].pcm_real[PRIME];
5987c478bd9Sstevel@tonic-gate pcm[k].pcm_real[NONPRIME] = pcm[i].pcm_real[NONPRIME];
5997c478bd9Sstevel@tonic-gate pcm[k].pcm_kcore[PRIME] = pcm[i].pcm_kcore[PRIME];
6007c478bd9Sstevel@tonic-gate pcm[k].pcm_kcore[NONPRIME] = pcm[i].pcm_kcore[NONPRIME];
6017c478bd9Sstevel@tonic-gate pcm[k].pcm_io[PRIME] = pcm[i].pcm_io[PRIME];
6027c478bd9Sstevel@tonic-gate pcm[k].pcm_io[NONPRIME] = pcm[i].pcm_io[NONPRIME];
6037c478bd9Sstevel@tonic-gate pcm[k].pcm_rw[PRIME] = pcm[i].pcm_rw[PRIME];
6047c478bd9Sstevel@tonic-gate pcm[k].pcm_rw[NONPRIME] = pcm[i].pcm_rw[NONPRIME];
6057c478bd9Sstevel@tonic-gate k++;
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate csize = k;
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate
610*414388d7Ssl108498 int
tccmp(struct tcms * p1,struct tcms * p2)611*414388d7Ssl108498 tccmp(struct tcms *p1, struct tcms *p2)
6127c478bd9Sstevel@tonic-gate {
6137c478bd9Sstevel@tonic-gate if (p1->tcm_cpu == p2->tcm_cpu)
6147c478bd9Sstevel@tonic-gate return(0);
6157c478bd9Sstevel@tonic-gate return ((p2->tcm_cpu > p1->tcm_cpu)? 1 : -1);
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate
618*414388d7Ssl108498 int
ccmp(struct pcms * p1,struct pcms * p2)619*414388d7Ssl108498 ccmp(struct pcms *p1, struct pcms *p2)
6207c478bd9Sstevel@tonic-gate {
621*414388d7Ssl108498 int index;
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate if( (pflg && oflg) || (!pflg && !oflg) ) {
6247c478bd9Sstevel@tonic-gate if (p1->pcm_cpu[PRIME] + p1->pcm_cpu[NONPRIME] == p2->pcm_cpu[PRIME] + p2->pcm_cpu[NONPRIME])
6257c478bd9Sstevel@tonic-gate return(0);
6267c478bd9Sstevel@tonic-gate return ((p2->pcm_cpu[PRIME] + p2->pcm_cpu[NONPRIME] > p1->pcm_cpu[PRIME] + p1->pcm_cpu[NONPRIME])? 1 : -1);
6277c478bd9Sstevel@tonic-gate }
6287c478bd9Sstevel@tonic-gate index = pflg ? PRIME : NONPRIME;
6297c478bd9Sstevel@tonic-gate if (p1->pcm_cpu[index] == p2->pcm_cpu[index])
6307c478bd9Sstevel@tonic-gate return(0);
6317c478bd9Sstevel@tonic-gate return ((p2->pcm_cpu[index] > p1->pcm_cpu[index])? 1 : -1);
6327c478bd9Sstevel@tonic-gate }
6337c478bd9Sstevel@tonic-gate
634*414388d7Ssl108498 int
tkcmp(struct tcms * p1,struct tcms * p2)635*414388d7Ssl108498 tkcmp(struct tcms *p1, struct tcms *p2)
6367c478bd9Sstevel@tonic-gate {
6377c478bd9Sstevel@tonic-gate if (p1->tcm_kcore == p2->tcm_kcore)
6387c478bd9Sstevel@tonic-gate return(0);
6397c478bd9Sstevel@tonic-gate return ((p2->tcm_kcore > p1->tcm_kcore)? 1 : -1);
6407c478bd9Sstevel@tonic-gate }
6417c478bd9Sstevel@tonic-gate
642*414388d7Ssl108498 int
kcmp(struct pcms * p1,struct pcms * p2)643*414388d7Ssl108498 kcmp(struct pcms *p1, struct pcms *p2)
6447c478bd9Sstevel@tonic-gate {
645*414388d7Ssl108498 int index;
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate if( (pflg && oflg) || (!pflg && !pflg) ){
6487c478bd9Sstevel@tonic-gate if (p1->pcm_kcore[PRIME] + p1->pcm_kcore[NONPRIME] == p2->pcm_kcore[PRIME] + p2->pcm_kcore[NONPRIME])
6497c478bd9Sstevel@tonic-gate return(0);
6507c478bd9Sstevel@tonic-gate return ((p2->pcm_kcore[PRIME] + p2->pcm_kcore[NONPRIME] > p1->pcm_kcore[PRIME] + p1->pcm_kcore[NONPRIME])? 1 : -1);
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate index = pflg ? PRIME : NONPRIME;
6537c478bd9Sstevel@tonic-gate if (p1->pcm_kcore[index] == p2->pcm_kcore[index])
6547c478bd9Sstevel@tonic-gate return(0);
6557c478bd9Sstevel@tonic-gate return ((p2->pcm_kcore[index] > p1->pcm_kcore[index])? 1 : -1);
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate
658*414388d7Ssl108498 int
tncmp(struct tcms * p1,struct tcms * p2)659*414388d7Ssl108498 tncmp(struct tcms *p1, struct tcms *p2)
6607c478bd9Sstevel@tonic-gate {
6617c478bd9Sstevel@tonic-gate if (p1->tcm_pc == p2->tcm_pc)
6627c478bd9Sstevel@tonic-gate return(0);
6637c478bd9Sstevel@tonic-gate return ((p2->tcm_pc > p1->tcm_pc)? 1 : -1);
6647c478bd9Sstevel@tonic-gate }
6657c478bd9Sstevel@tonic-gate
666*414388d7Ssl108498 int
ncmp(struct pcms * p1,struct pcms * p2)667*414388d7Ssl108498 ncmp(struct pcms *p1, struct pcms *p2)
6687c478bd9Sstevel@tonic-gate {
669*414388d7Ssl108498 int index;
6707c478bd9Sstevel@tonic-gate
6717c478bd9Sstevel@tonic-gate if( (pflg && oflg) || (!pflg && !oflg) ) {
6727c478bd9Sstevel@tonic-gate if (p1->pcm_pc[PRIME] + p1->pcm_pc[NONPRIME] == p2->pcm_pc[PRIME] + p2->pcm_pc[NONPRIME])
6737c478bd9Sstevel@tonic-gate return(0);
6747c478bd9Sstevel@tonic-gate return ((p2->pcm_pc[PRIME] + p2->pcm_pc[NONPRIME] > p1->pcm_pc[PRIME] + p1->pcm_pc[NONPRIME])? 1 : -1);
6757c478bd9Sstevel@tonic-gate }
6767c478bd9Sstevel@tonic-gate index = pflg ? PRIME : NONPRIME;
6777c478bd9Sstevel@tonic-gate if (p1->pcm_pc[index] == p2->pcm_pc[index])
6787c478bd9Sstevel@tonic-gate return(0);
6797c478bd9Sstevel@tonic-gate return ((p2->pcm_pc[index] > p1->pcm_pc[index])? 1 : -1);
6807c478bd9Sstevel@tonic-gate }
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate char thd1[] =
6837c478bd9Sstevel@tonic-gate "COMMAND NUMBER TOTAL TOTAL TOTAL MEAN MEAN HOG CHARS BLOCKS\n";
6847c478bd9Sstevel@tonic-gate char thd2[] =
6857c478bd9Sstevel@tonic-gate "NAME CMDS KCOREMIN CPU-MIN REAL-MIN SIZE-K CPU-MIN FACTOR TRNSFD READ\n";
686*414388d7Ssl108498
687*414388d7Ssl108498 void
toutpta(void)688*414388d7Ssl108498 toutpta(void)
6897c478bd9Sstevel@tonic-gate {
690*414388d7Ssl108498 int i;
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate printf(thd1);
6937c478bd9Sstevel@tonic-gate printf(thd2);
6947c478bd9Sstevel@tonic-gate printf("\n");
6957c478bd9Sstevel@tonic-gate for (i = 0; i < csize; i++)
6967c478bd9Sstevel@tonic-gate tcmadd(&tcmtmp, &tcm[i]);
6977c478bd9Sstevel@tonic-gate CPYN(tcmtmp.tcm_comm, "TOTALS");
6987c478bd9Sstevel@tonic-gate tprint(&tcmtmp);
6997c478bd9Sstevel@tonic-gate printf("\n");
7007c478bd9Sstevel@tonic-gate for (i = 0; i < csize; i++)
7017c478bd9Sstevel@tonic-gate tprint(&tcm[i]);
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate
704*414388d7Ssl108498 void
tprint(struct tcms * p)705*414388d7Ssl108498 tprint(struct tcms *p)
7067c478bd9Sstevel@tonic-gate {
7077c478bd9Sstevel@tonic-gate printf("%-8.8s", p->tcm_comm);
7087c478bd9Sstevel@tonic-gate printf(" %7ld", p->tcm_pc);
7097c478bd9Sstevel@tonic-gate printf(" %11.2f", p->tcm_kcore);
7107c478bd9Sstevel@tonic-gate printf(" %10.2f", p->tcm_cpu);
7117c478bd9Sstevel@tonic-gate printf(" %12.2f", p->tcm_real);
7127c478bd9Sstevel@tonic-gate if(p->tcm_cpu == 0) p->tcm_cpu = 1;
7137c478bd9Sstevel@tonic-gate printf(" %6.2f", p->tcm_kcore/p->tcm_cpu);
7147c478bd9Sstevel@tonic-gate if(p->tcm_pc == 0) p->tcm_pc = 1;
7157c478bd9Sstevel@tonic-gate printf(" %7.2f", p->tcm_cpu/p->tcm_pc);
7167c478bd9Sstevel@tonic-gate if (p->tcm_real == 0)
7177c478bd9Sstevel@tonic-gate p->tcm_real = 1;
7187c478bd9Sstevel@tonic-gate printf(" %8.2f", p->tcm_cpu/p->tcm_real);
7197c478bd9Sstevel@tonic-gate printf(" %11lu", p->tcm_io);
7207c478bd9Sstevel@tonic-gate printf(" %11lu\n", p->tcm_rw);
7217c478bd9Sstevel@tonic-gate }
7227c478bd9Sstevel@tonic-gate
723*414388d7Ssl108498 void
toutptc(void)724*414388d7Ssl108498 toutptc(void)
7257c478bd9Sstevel@tonic-gate {
726*414388d7Ssl108498 int i;
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate for (i = 0; i < csize; i++)
7297c478bd9Sstevel@tonic-gate fwrite(&tcm[i], sizeof(tcm[i]), 1, stdout);
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate char hd1[] =
7337c478bd9Sstevel@tonic-gate "COMMAND NUMBER TOTAL TOTAL TOTAL MEAN MEAN HOG CHARS BLOCKS\n";
7347c478bd9Sstevel@tonic-gate char hd2[] =
7357c478bd9Sstevel@tonic-gate "NAME CMDS KCOREMIN CPU-MIN REAL-MIN SIZE-K CPU-MIN FACTOR TRNSFD READ\n";
7367c478bd9Sstevel@tonic-gate char hd3[] =
7377c478bd9Sstevel@tonic-gate "COMMAND NUMBER TOTAL CPU-MIN REAL-MIN MEAN MEAN HOG CHARS BLOCKS\n";
7387c478bd9Sstevel@tonic-gate char hd4[] =
7397c478bd9Sstevel@tonic-gate "NAME (P) (NP) KCOREMIN (P) (NP) (P) (NP) SIZE-K CPU-MIN FACTOR TRNSFD READ\n";
7407c478bd9Sstevel@tonic-gate char hdprime[] =
7417c478bd9Sstevel@tonic-gate " PRIME TIME COMMAND SUMMARY\n";
7427c478bd9Sstevel@tonic-gate char hdnonprime[] =
7437c478bd9Sstevel@tonic-gate " NON-PRIME TIME COMMAND SUMMARY\n";
7447c478bd9Sstevel@tonic-gate char hdtot[] =
7457c478bd9Sstevel@tonic-gate " TOTAL COMMAND SUMMARY\n";
7467c478bd9Sstevel@tonic-gate char hdp[] =
7477c478bd9Sstevel@tonic-gate " PRIME/NON-PRIME TIME COMMAND SUMMARY\n";
7487c478bd9Sstevel@tonic-gate
749*414388d7Ssl108498 void
outputa(void)750*414388d7Ssl108498 outputa(void)
7517c478bd9Sstevel@tonic-gate {
752*414388d7Ssl108498 int i;
7537c478bd9Sstevel@tonic-gate
7547c478bd9Sstevel@tonic-gate if( pflg && oflg ) printf(hdp);
7557c478bd9Sstevel@tonic-gate else if(pflg) printf(hdprime);
7567c478bd9Sstevel@tonic-gate else if(oflg) printf(hdnonprime);
7577c478bd9Sstevel@tonic-gate else printf(hdtot);
7587c478bd9Sstevel@tonic-gate if( (!pflg && !oflg) || (pflg ^ oflg)) {
7597c478bd9Sstevel@tonic-gate printf(hd1);
7607c478bd9Sstevel@tonic-gate printf(hd2);
7617c478bd9Sstevel@tonic-gate }
7627c478bd9Sstevel@tonic-gate else {
7637c478bd9Sstevel@tonic-gate printf(hd3);
7647c478bd9Sstevel@tonic-gate printf(hd4);
7657c478bd9Sstevel@tonic-gate }
7667c478bd9Sstevel@tonic-gate printf("\n");
7677c478bd9Sstevel@tonic-gate for (i = 0; i < csize; i++)
7687c478bd9Sstevel@tonic-gate pcmadd(&pcmtmp, &pcm[i]);
7697c478bd9Sstevel@tonic-gate CPYN(pcmtmp.pcm_comm, "TOTALS");
7707c478bd9Sstevel@tonic-gate print(&pcmtmp);
7717c478bd9Sstevel@tonic-gate printf("\n");
7727c478bd9Sstevel@tonic-gate for (i = 0; i < csize; i++)
7737c478bd9Sstevel@tonic-gate print(&pcm[i]);
7747c478bd9Sstevel@tonic-gate }
7757c478bd9Sstevel@tonic-gate
776*414388d7Ssl108498 void
print(struct pcms * p)777*414388d7Ssl108498 print(struct pcms *p)
7787c478bd9Sstevel@tonic-gate {
7797c478bd9Sstevel@tonic-gate if(pflg && oflg) pprint(p);
7807c478bd9Sstevel@tonic-gate else if(pflg || oflg) prnt(p, pflg ? PRIME : NONPRIME);
7817c478bd9Sstevel@tonic-gate else totprnt(p);
7827c478bd9Sstevel@tonic-gate }
7837c478bd9Sstevel@tonic-gate
784*414388d7Ssl108498 void
prnt(struct pcms * p,int hr)785*414388d7Ssl108498 prnt(struct pcms *p, int hr)
7867c478bd9Sstevel@tonic-gate {
7877c478bd9Sstevel@tonic-gate if(p->pcm_pc[hr] == 0) return;
7887c478bd9Sstevel@tonic-gate printf(fmtcmd, p->pcm_comm);
7897c478bd9Sstevel@tonic-gate printf(fmtcnt, p->pcm_pc[hr]);
7907c478bd9Sstevel@tonic-gate printf(fmtkcore, p->pcm_kcore[hr]);
7917c478bd9Sstevel@tonic-gate printf(fmtcpu, p->pcm_cpu[hr]);
7927c478bd9Sstevel@tonic-gate printf(fmtreal, p->pcm_real[hr]);
7937c478bd9Sstevel@tonic-gate if(p->pcm_cpu[hr] == 0) p->pcm_cpu[hr] = 1;
7947c478bd9Sstevel@tonic-gate printf(fmtmsz, p->pcm_kcore[hr]/p->pcm_cpu[hr]);
7957c478bd9Sstevel@tonic-gate if(p->pcm_pc[hr] == 0) p->pcm_pc[hr] = 1;
7967c478bd9Sstevel@tonic-gate printf(fmtmcpu, p->pcm_cpu[hr]/p->pcm_pc[hr]);
7977c478bd9Sstevel@tonic-gate if (p->pcm_real[hr] == 0)
7987c478bd9Sstevel@tonic-gate p->pcm_real[hr] = 1;
7997c478bd9Sstevel@tonic-gate printf(fmthog, p->pcm_cpu[hr]/p->pcm_real[hr]);
8007c478bd9Sstevel@tonic-gate printf(fmtcharx,p->pcm_io[hr]);
8017c478bd9Sstevel@tonic-gate printf(fmtblkx,p->pcm_rw[hr]);
8027c478bd9Sstevel@tonic-gate printf("\n");
8037c478bd9Sstevel@tonic-gate }
8047c478bd9Sstevel@tonic-gate
805*414388d7Ssl108498 void
pprint(struct pcms * p)806*414388d7Ssl108498 pprint(struct pcms *p)
8077c478bd9Sstevel@tonic-gate {
8087c478bd9Sstevel@tonic-gate printf(fmtcmd, p->pcm_comm);
8097c478bd9Sstevel@tonic-gate printf(fmtcnt, p->pcm_pc[PRIME]);
8107c478bd9Sstevel@tonic-gate printf(fmtcnt, p->pcm_pc[NONPRIME]);
8117c478bd9Sstevel@tonic-gate printf(fmtkcore, TOTAL(p->pcm_kcore));
8127c478bd9Sstevel@tonic-gate printf(fmtcpu, p->pcm_cpu[PRIME]);
8137c478bd9Sstevel@tonic-gate printf(fmtcpu, p->pcm_cpu[NONPRIME]);
8147c478bd9Sstevel@tonic-gate printf(fmtreal, p->pcm_real[PRIME]);
8157c478bd9Sstevel@tonic-gate printf(fmtreal, p->pcm_real[NONPRIME]);
8167c478bd9Sstevel@tonic-gate if(TOTAL(p->pcm_cpu) == 0) p->pcm_cpu[PRIME] = 1;
8177c478bd9Sstevel@tonic-gate printf(fmtmsz, TOTAL(p->pcm_kcore)/TOTAL(p->pcm_cpu));
8187c478bd9Sstevel@tonic-gate if(TOTAL(p->pcm_pc) == 0) p->pcm_pc[PRIME] = 1;
8197c478bd9Sstevel@tonic-gate printf(fmtmcpu, TOTAL(p->pcm_cpu)/TOTAL(p->pcm_pc));
8207c478bd9Sstevel@tonic-gate if ( TOTAL(p->pcm_real) == 0)
8217c478bd9Sstevel@tonic-gate p->pcm_real[PRIME] = 1;
8227c478bd9Sstevel@tonic-gate printf(fmthog, TOTAL(p->pcm_cpu)/TOTAL(p->pcm_real));
8237c478bd9Sstevel@tonic-gate printf(fmtcharx,TOTAL(p->pcm_io));
8247c478bd9Sstevel@tonic-gate printf(fmtblkx, TOTAL(p->pcm_rw));
8257c478bd9Sstevel@tonic-gate printf("\n");
8267c478bd9Sstevel@tonic-gate }
8277c478bd9Sstevel@tonic-gate
828*414388d7Ssl108498 void
totprnt(struct pcms * p)829*414388d7Ssl108498 totprnt(struct pcms *p)
8307c478bd9Sstevel@tonic-gate {
8317c478bd9Sstevel@tonic-gate printf(fmtcmd, p->pcm_comm);
8327c478bd9Sstevel@tonic-gate printf(fmtcnt, TOTAL(p->pcm_pc));
8337c478bd9Sstevel@tonic-gate printf(fmtkcore, TOTAL(p->pcm_kcore));
8347c478bd9Sstevel@tonic-gate printf(fmtcpu, TOTAL(p->pcm_cpu));
8357c478bd9Sstevel@tonic-gate printf(fmtreal, TOTAL(p->pcm_real));
8367c478bd9Sstevel@tonic-gate if(TOTAL(p->pcm_cpu) == 0) p->pcm_cpu[PRIME] = 1;
8377c478bd9Sstevel@tonic-gate printf(fmtmsz, TOTAL(p->pcm_kcore)/TOTAL(p->pcm_cpu));
8387c478bd9Sstevel@tonic-gate if(TOTAL(p->pcm_pc) == 0) p->pcm_pc[PRIME] = 1;
8397c478bd9Sstevel@tonic-gate printf(fmtmcpu, TOTAL(p->pcm_cpu)/TOTAL(p->pcm_pc));
8407c478bd9Sstevel@tonic-gate if (TOTAL(p->pcm_real) == 0)
8417c478bd9Sstevel@tonic-gate p->pcm_real[PRIME] = 1;
8427c478bd9Sstevel@tonic-gate printf(fmthog, TOTAL(p->pcm_cpu)/TOTAL(p->pcm_real));
8437c478bd9Sstevel@tonic-gate printf(fmtcharx,TOTAL(p->pcm_io));
8447c478bd9Sstevel@tonic-gate printf(fmtblkx,TOTAL(p->pcm_rw));
8457c478bd9Sstevel@tonic-gate printf("\n");
8467c478bd9Sstevel@tonic-gate }
847*414388d7Ssl108498
848*414388d7Ssl108498 void
outputc(void)849*414388d7Ssl108498 outputc(void)
8507c478bd9Sstevel@tonic-gate {
851*414388d7Ssl108498 int i;
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate for (i = 0; i < csize; i++)
8547c478bd9Sstevel@tonic-gate fwrite(&pcm[i], sizeof(pcm[i]), 1, stdout);
8557c478bd9Sstevel@tonic-gate }
856