acctcms.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* acctcms [-a] [-c] [-j] [-n] [-s] [-p] [-o] [-t] [file...]
* summarize per-process accounting
* -a output in ascii, rather than [pt]cms.h format
* -c sort by total cpu, rather than total kcore-minutes
* -j anything used only once -> ***other
* -n sort by number of processes
* -s any following files already in pcms.h format
* -p output prime time command summary (only with -a)
* -o output non-prime time (offshift) command summary (only
* with -a option)
* -t process records in total (old) style (tcms.h) format
* expected use:
* cp new old; rm new
* acctcms -a today; acctcms -a old
*/
#include <stdio.h>
#include "acctdef.h"
#include <ctype.h>
/*
* Total cms records format
*/
struct tcms {
long tcm_pc; /* number of processes */
float tcm_cpu; /* cpu time(min) */
float tcm_real; /* real time(min) */
float tcm_kcore; /* kcore-minutes */
} ;
/*
*/
struct pcms {
} ;
int aflg;
int cflg;
int jflg;
int nflg;
int sflg;
int pflg;
int oflg;
int tflg;
int errflg;
#ifdef uts
float expand();
#else
#endif
char *strncpy();
/* Format specification for ASCII printing */
char *fmtcmd = "%-8.8s",
*fmtcnt = "%8ld",
*fmtkcore = " %11.2f",
*fmtcpu = " %9.2f",
*fmtreal = " %12.2f",
*fmtmsz = " %7.2f",
*fmtmcpu = " %6.2f",
*fmthog = " %5.2f",
*fmtcharx = " %12.0f",
*fmtblkx = " %10.0f" ;
char **argv;
{
int c;
extern int optind;
extern char *optarg;
switch(c) {
case 'a':
aflg++;
continue;
case 'c':
cflg++;
continue;
case 'j':
jflg++;
continue;
case 'n':
nflg++;
continue;
case 's':
sflg++;
continue;
case 'p':
pflg++;
continue;
case 'o':
oflg++;
continue;
case 't':
tflg++;
continue;
default:
errflg++;
continue;
}
if(errflg){
exit(1);
}
if(tflg) {
exit(5);
}
if (jflg)
tfixjunk();
tsqueeze();
if (aflg)
toutpta();
else
toutptc();
} else {
exit(6);
}
if (jflg)
fixjunk();
squeeze();
if (aflg)
outputa();
else
outputc();
}
exit(0);
}
char *fname;
{
union {
} acct;
int ver = 0;
return;
}
if (sflg)
else {
/* check for expanded account structure flag */
else
switch(ver) {
default:
/* this can't happen */
return;
case 1 :
}
break;
case 2 :
}
break;
}
}
}
char *fname;
{
union {
} acct;
double ratio;
long elaps[2];
double dtmp;
unsigned long ltmp;
return;
}
if (sflg)
else {
int ver = 0;
/* check for expanded account structure flag */
else
switch(ver) {
default :
/* this can't happen */
return;
case 1 :
/*
*/
etime = 1;
== 0) {
"hours\n");
exit(1);
}
} else {
}
}
break;
case 2 :
/*
*/
etime = 1;
exit(1);
}
} else {
}
}
break;
}
}
}
tenter(p)
register struct tcms *p;
{
register i;
register j;
for (i = j = 0; j < sizeof(p->tcm_comm); j++) {
p->tcm_comm[j] = '?';
}
if (i < 0)
i = -i;
break;
if(j == csize) {
"acctcms: Cannot reallocate memory (tcm)\n");
return(-1);
} else {
i = csize;
}
}
return(i);
}
enter(p)
register struct pcms *p;
{
register i;
register j;
for (i = j = 0; j < sizeof(p->pcm_comm); j++) {
p->pcm_comm[j] = '?';
}
if (i < 0)
i = -i;
break;
if(j == csize) {
"acctcms: Cannot reallocate memory (pcm)\n");
return(-1);
} else {
i = csize;
}
}
return(i);
}
tfixjunk() /* combine commands used only once */
{
register i, j;
for (i = 0; i < csize; i++)
}
}
fixjunk() /* combine commands used only once */
{
register i, j;
for (i = 0; i < csize; i++)
}
}
{
}
{
}
tsqueeze() /* get rid of holes in hash table */
{
register i, k;
for (i = k = 0; i < csize; i++)
k++;
}
csize = k;
}
squeeze() /* get rid of holes in hash table */
{
register i, k;
for (i = k = 0; i < csize; i++)
k++;
}
csize = k;
}
{
return(0);
}
{
register int index;
return(0);
return ((p2->pcm_cpu[PRIME] + p2->pcm_cpu[NONPRIME] > p1->pcm_cpu[PRIME] + p1->pcm_cpu[NONPRIME])? 1 : -1);
}
return(0);
}
{
return(0);
}
{
register int index;
if (p1->pcm_kcore[PRIME] + p1->pcm_kcore[NONPRIME] == p2->pcm_kcore[PRIME] + p2->pcm_kcore[NONPRIME])
return(0);
return ((p2->pcm_kcore[PRIME] + p2->pcm_kcore[NONPRIME] > p1->pcm_kcore[PRIME] + p1->pcm_kcore[NONPRIME])? 1 : -1);
}
return(0);
}
{
return(0);
}
{
register int index;
return(0);
return ((p2->pcm_pc[PRIME] + p2->pcm_pc[NONPRIME] > p1->pcm_pc[PRIME] + p1->pcm_pc[NONPRIME])? 1 : -1);
}
return(0);
}
char thd1[] =
"COMMAND NUMBER TOTAL TOTAL TOTAL MEAN MEAN HOG CHARS BLOCKS\n";
char thd2[] =
"NAME CMDS KCOREMIN CPU-MIN REAL-MIN SIZE-K CPU-MIN FACTOR TRNSFD READ\n";
toutpta()
{
register i;
printf("\n");
for (i = 0; i < csize; i++)
printf("\n");
for (i = 0; i < csize; i++)
}
tprint(p)
register struct tcms *p;
{
if (p->tcm_real == 0)
p->tcm_real = 1;
}
toutptc()
{
register i;
for (i = 0; i < csize; i++)
}
char hd1[] =
"COMMAND NUMBER TOTAL TOTAL TOTAL MEAN MEAN HOG CHARS BLOCKS\n";
char hd2[] =
"NAME CMDS KCOREMIN CPU-MIN REAL-MIN SIZE-K CPU-MIN FACTOR TRNSFD READ\n";
char hd3[] =
"COMMAND NUMBER TOTAL CPU-MIN REAL-MIN MEAN MEAN HOG CHARS BLOCKS\n";
char hd4[] =
"NAME (P) (NP) KCOREMIN (P) (NP) (P) (NP) SIZE-K CPU-MIN FACTOR TRNSFD READ\n";
char hdprime[] =
" PRIME TIME COMMAND SUMMARY\n";
char hdnonprime[] =
" NON-PRIME TIME COMMAND SUMMARY\n";
char hdtot[] =
" TOTAL COMMAND SUMMARY\n";
char hdp[] =
outputa()
{
register i;
}
else {
}
printf("\n");
for (i = 0; i < csize; i++)
printf("\n");
for (i = 0; i < csize; i++)
}
print(p)
register struct pcms *p;
{
else totprnt(p);
}
register struct pcms *p;
register int hr;
{
printf("\n");
}
pprint(p)
register struct pcms *p;
{
printf("\n");
}
totprnt(p)
register struct pcms *p;
{
printf("\n");
}
outputc()
{
register i;
for (i = 0; i < csize; i++)
}