diff options
author | Garrett D'Amore <gdamore@opensolaris.org> | 2009-11-30 21:22:02 -0800 |
---|---|---|
committer | Garrett D'Amore <gdamore@opensolaris.org> | 2009-11-30 21:22:02 -0800 |
commit | 6e244e4d729480b2c2e62235ed72346fc20d4a22 (patch) | |
tree | 85514e49202727455fdebced23b0425b82ec96a9 /usr/src/cmd/sa | |
parent | bd984e57880898cc60d556b709d3c6e7c1913a08 (diff) | |
download | illumos-gate-6e244e4d729480b2c2e62235ed72346fc20d4a22.tar.gz |
PSARC 2009/632 EOF sag
6905472 hi ho hi ho sag has got to go
Diffstat (limited to 'usr/src/cmd/sa')
-rw-r--r-- | usr/src/cmd/sa/Makefile | 12 | ||||
-rw-r--r-- | usr/src/cmd/sa/saga.c | 582 | ||||
-rw-r--r-- | usr/src/cmd/sa/sagb.c | 490 | ||||
-rw-r--r-- | usr/src/cmd/sa/saghdr.h | 62 |
4 files changed, 3 insertions, 1143 deletions
diff --git a/usr/src/cmd/sa/Makefile b/usr/src/cmd/sa/Makefile index bb1ff6f10d..39aea59f50 100644 --- a/usr/src/cmd/sa/Makefile +++ b/usr/src/cmd/sa/Makefile @@ -38,7 +38,6 @@ SADC= sadc SADP= sadp SAR= sar TIMEX= timex -SAG= sag SA1= sa1 SA2= sa2 @@ -46,7 +45,7 @@ sadc := LDLIBS += -lkstat # Executables produced BINPROG= $(TIMEX) -SBINPROG= $(SAR) $(SAG) +SBINPROG= $(SAR) LIBPROG= $(SADC) LIBSHELL= $(SA1) $(SA2) INITSHELL= $(PERF) @@ -57,10 +56,9 @@ TXTS= $(SADP).c README ALL= $(PROGS) $(SHELLS) # Source files -SAG_OBJECTS= $(SAG)a.o $(SAG)b.o SADC_OBJECTS= $(SADC).o srcs= $(TIMEX) $(SAR) $(SADC) -SRCS= $(srcs:%=%.c) $(SAG_OBJECTS:%.o=%.c) +SRCS= $(srcs:%=%.c) SHSRCS= $(SHELLS:%=%.sh) # Set of target install directories @@ -93,10 +91,6 @@ $(LIBSAD)/$(SADC) := FILEMODE = 0555 all: $(ALL) $(TXTS) -$(SAG): $(SAG_OBJECTS) - $(LINK.c) -o $@ $(SAG_OBJECTS) $(LDLIBS) - $(POST_PROCESS) - $(SADC): $(SADC_OBJECTS) $(LINK.c) -o $@ $(SADC_OBJECTS) $(LDLIBS) $(POST_PROCESS) @@ -133,7 +127,7 @@ $(ETCINITD)/%: % check: $(CHKMANIFEST) clean: - $(RM) $(SAG_OBJECTS) $(SADC_OBJECTS) $(PROGS) $(SHELLS) $(SADP) + $(RM) $(SADC_OBJECTS) $(PROGS) $(SHELLS) $(SADP) lint: lint_SRCS diff --git a/usr/src/cmd/sa/saga.c b/usr/src/cmd/sa/saga.c deleted file mode 100644 index 1e62238fa0..0000000000 --- a/usr/src/cmd/sa/saga.c +++ /dev/null @@ -1,582 +0,0 @@ -/* - * 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 - * or http://www.opensolaris.org/os/licensing. - * 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" - -#include "saghdr.h" -#include <limits.h> -#include <strings.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -char fld[NFLD][10]; -char cmd[300]; -long sardoff; -FILE *sard; - -static void printar(struct array *ptr); -static void parse(struct p *p); -static void plot(struct p[], int, char *, char *, char *, char *); -static void scale(struct p[], int, char *, char *, char *, char *); - -int -main(int argc, char *argv[]) -{ - extern char cmd[]; - extern char fld[NFLD][FLDCH]; - char sarg[10]; - char earg[10]; - char iarg[10]; - char farg[PATH_MAX + 4]; - char yarg[200]; - char xarg[100]; - char Targ[10]; - char title[60]; - int nplot, nchar; - int n, i; - char xlab_s[10], xlab_e[10]; - - struct p p[6]; - - char sardfile[20]; - int c; - char temp[80]; - char *strcpy(); - - *Targ = '\0'; - - strcpy(sarg, "-s 08:00"); - strcpy(earg, "-e 18:00"); - strcpy(iarg, ""); - strcpy(farg, ""); -#ifndef u370 - strcpy( - yarg, "%usr 0 100; %usr + %sys 0 100; %usr + %sys + %wio 0 100"); -#else - strcpy(yarg, - "%usr 0 100; %usr + %usup 0 100; %usr + %usup + %tss 0 100"); -#endif - strcpy(xarg, "time"); - - while ((c = getopt(argc, argv, "s:e:i:f:y:x:T:")) != EOF) - switch (c) { - case 's': - strcpy(sarg, "-s "); - if (strlcat(sarg, optarg, sizeof (sarg)) >= - sizeof (sarg)) { - fprintf(stderr, - "-s argument too long: %s\n", optarg); - exit(1); - } - break; - case 'e': - strcpy(earg, "-e "); - if (strlcat(earg, optarg, sizeof (earg)) >= - sizeof (earg)) { - fprintf(stderr, - "-e argument too long: %s\n", optarg); - exit(1); - } - break; - case 'i': - strcpy(iarg, "-i "); - if (strlcat(iarg, optarg, sizeof (iarg)) >= - sizeof (iarg)) { - fprintf(stderr, - "-i argument too long: %s\n", optarg); - exit(1); - } - break; - case 'f': - strcpy(farg, "-f "); - if (strlcat(farg, optarg, sizeof (farg)) >= - sizeof (farg)) { - fprintf(stderr, - "-f argument too long: %s\n", optarg); - exit(1); - } - break; - case 'y': - if (strlcat(yarg, optarg, sizeof (yarg)) >= - sizeof (yarg)) { - fprintf(stderr, - "-y argument too long: %s\n", optarg); - exit(1); - } - break; - case 'x': - if (strlcat(xarg, optarg, sizeof (xarg)) >= - sizeof (xarg)) { - fprintf(stderr, - "-x argument too long: %s\n", optarg); - exit(1); - } - break; - case 'T': - strcpy(Targ, "-T"); - if (strlcat(Targ, optarg, sizeof (Targ)) >= - sizeof (Targ)) { - fprintf(stderr, - "-T argument too long: %s\n", optarg); - exit(1); - } - break; - case '?': - fprintf(stderr, - "Usage: sag -s hh:mm -e hh:mm -i " - "sec -f safile -T term\n"); - fprintf(stderr, - "\t -x \"spec\" -y \"spec[;spec]...\"\n"); - fprintf(stderr, - "\twhere spec is name[ op name]...[lo hi]\n"); - fprintf(stderr, - "\tand name is a hdrstr that may include " - "[devstr]\n"); - exit(2); - } - for (; optind < argc; optind++) - fprintf(stderr, "\"%s\" ignored\n", argv[optind]); - /* - * Test xarg, break yarg into ";" separated graph commands - */ - - *temp = '\0'; - *(p[0].spec) = '\0'; - sscanf(xarg, "%[^;];%s", p[0].spec, temp); - if (stribl(temp) > 0) { - fprintf(stderr, - "More than one x-axis spec not allowed:\n%s\n", xarg); - exit(2); - } - for (nplot = nchar = 0, i = 1; i < 6; ) { - *temp = '\0'; - *(p[i].spec) = '\0'; - n = sscanf(yarg+nchar, "%[^;]%s", p[i].spec, temp); - nchar += strlen(p[i].spec) + 1; - if (stribl(p[i].spec) > 0) { - nplot++; - i++; - } - if (n < 2) - break; - } - if (DEBUG) { - fprintf(stderr, "nplot:%d\n", nplot); - for (i = 0; i < 6; i++) - fprintf(stderr, "p[%d].spec:%s\n", i, p[i].spec); - } - /* - * Parse each spec - */ - for (i = 0; i <= nplot; i++) - parse(&p[i]); - - /* - * Run sar, with output to sardfile. - */ - sprintf(sardfile, "/tmp/sard%ld", getpid()); - sprintf(cmd, "sar -ubdycwaqmvpr %s %s %s %s | sed " - "-e '/:/h' " - "-e '/:/s/ .*//' " - "-e '/:/x' " - "-e '/^ /G' " - "-e '/^ /s/\\(.*\\)\\n\\(.*\\)/\\2\\1/' " - "-e '/proc-sz/,$s/\\/ */\\//g' " - "-e '/proc-sz/,$s/\\/[^ ]*//g' " - "-e 's/ / /g' " - "-e 's/ */ /g' " - "-e '/^ /s///' " - "-e '/^$/d' " - "> %s", - sarg, earg, iarg, farg, sardfile); - system(cmd); - - sard = fopen(sardfile, "r"); - if ((n = getfld()) == EOF) { - fprintf(stderr, "No sar data!\n"); - exit(2); - } - sardoff = ftell(sard); - for (i = 0; i < n; i++) { - strcat(title, fld[i]); - strcat(title, " "); - } - - for (i = 0; i <= nplot; i++) - if (reduce(&p[i]) < 0) { - fprintf(stderr, "Can't reduce %s\n", p[i].spec); - exit(2); - } - else - if (DEBUG > 1) printar(p[i].c[0].dptr); - - fclose(sard); - - scale(p, nplot, sarg, earg, xlab_s, xlab_e); - - plot(p, nplot, xlab_s, xlab_e, title, Targ); - unlink(sardfile); - exit(0); -} - -static void -printar(struct array *ptr) -{ - int i; - - fprintf(stderr, "hname:%s\n", ptr->hname); - for (i = 0; i < NPTS; i++) { - if (ptr->ent[i].hr == 0) - break; - fprintf(stderr, "tm:%s hr:%f val:%f qfld:%s\n", - ptr->ent[i].tm, - ptr->ent[i].hr, - ptr->ent[i].val, - ptr->ent[i].qfld); - } -} - -/* - * Parses command string for one graph parameter - * found in p->spec, placing field names in p->c[j].name, - * operators in p->c[j].op, and ranges in p->mn, p->mx, p->min, and p->max - */ -static void -parse(struct p *p) -{ - int n, j; - char f[11][18]; - char *strcpy(); - - n = sscanf(p->spec, - "%s %s %s %s %s %s %s %s %s %s %s ", - f[0], f[1], f[2], f[3], f[4], f[5], - f[6], f[7], f[8], f[9], f[10]); - if (n % 2 == 0) - fprintf(stderr, "Can't parse:%s:\nNeed odd # of arg's\n", - p->spec); - for (j = 0; j < n; j += 2) { - strcpy(p->c[j/2].name, f[j]); - p->c[j/2].dptr = NULL; - if (j == n-1) { - p->c[j/2].op = '\0'; - break; - } else if ((strcmp(f[j+1], "+") == 0) || - (strcmp(f[j+1], "-") == 0) || - (strcmp(f[j+1], "*") == 0) || - (strcmp(f[j+1], "/") == 0)) - p->c[j/2].op = f[j+1][0]; - else { - p->c[j/2].op = '\0'; - strcpy(p->mn, f[j+1]); - strcpy(p->mx, f[j+2]); - p->min = (float)atoi(p->mn); - p->max = (float)atoi(p->mx); - break; - } - } - if (DEBUG) { - for (n = 0; n <= j/2; n++) - fprintf(stderr, "\"%s\" %c ", - p->c[n].name, p->c[n].op); - fprintf(stderr, ", limits: %f %f\n", p->min, p->max); - } -} - -static void -plot(struct p p[], int nplot, char *xlab_s, char *xlab_e, char *title, - char *Targ) -{ - extern char cmd[]; - FILE *pipe, *popen(); - static char pchar[] = {'+', '-', '=', '#', 'o', 'x'}; - char plotfile[20]; - int i; - int a, b; - struct array *ara, *arb; - - sprintf(plotfile, "/tmp/sag%ld", getpid()); - - /* Construct graph commands for left edge labels */ - - sprintf(cmd, "graph -x 0 1 -y 0 1 -r 0 -h .8 -u .2 -g 0 -b > %s", - plotfile); - fflush(stdout); - if (pipe = popen(cmd, "w")) { - for (i = 1; i <= nplot; i++) - fprintf(pipe, "%.3f %.3f \"%c%3.0f\"\n", - 0., (1-.02*(float)(i-1)), pchar[i-1], p[i].max); - for (i = 1; i <= nplot; i++) - fprintf(pipe, "%.3f %.3f \"%c%3.0f\"\n", - 0., (0+.02*(float)(i-1)), pchar[i-1], p[i].min); - pclose(pipe); - } - - /* Construct graph commands for bottom labels and title */ - - sprintf(cmd, "graph -x 0 1 -y 0 1 -r .1 -h .8 -u 0 -g 0 -b -s >> %s", - plotfile); - fflush(stdout); - if (pipe = popen(cmd, "w")) { - fprintf(pipe, "%.3f %.3f \"%s\"\n%.3f %.3f \"%s\"\n", - 0., .22, xlab_s, - 1., .22, xlab_e); - for (i = 1; i <= nplot; i++) - fprintf(pipe, "%.3f %.3f \"%c %s\"\n", - .05, (.18 -.18*(float)(i-1)/5), - pchar[i-1], p[i].c[0].dptr->hname); - fprintf(pipe, "%.3f %.3f \"vs %s\"\n", - .05, (.18 -.18*(float)nplot/5), p[0].c[0].dptr->hname); - fprintf(pipe, "%.3f %.3f \"%s\"\n", - .5 - (float)strlen(title)/(5.75*10.*2.), .22, title); - pclose(pipe); - } - - /* Form grid */ - - sprintf(cmd, - "graph -x %.3f %.3f -y 0 1 -r .1 -h .8 -u .2 -g 1 -s >> %s", - p[0].min, p[0].max, plotfile); - fflush(stdout); - if (pipe = popen(cmd, "w")) - pclose(pipe); - - /* Construct graph commands for plotting, nplot cases */ - - for (i = 1; i <= nplot; i++) { - if (p[i].mode == 0) - sprintf(cmd, "graph -x %.3f %.3f -y %.3f %.3f -r " - ".1 -h .8 -u .2 -g 0 -s -m %d -c \"%c\" >> %s", - p[0].min, p[0].max, p[i].min, p[i].max, - (strmatch("time", p[0].spec) >= 0 ? 1 : 0), - pchar[i-1], plotfile); - else - sprintf(cmd, "graph -x %.3f %.3f -y %.3f %.3f -r " - ".1 -h .8 -u .2 -g 0 -s -m 0 >> %s", - p[0].min, p[0].max, p[i].min, p[i].max, - plotfile); - fflush(stdout); - if (pipe = popen(cmd, "w")) { - ara = p[0].c[0].dptr; - arb = p[i].c[0].dptr; - for (a = b = 0; a < NPTS && b < NPTS; ) { - if ((ara->ent[a].hr == 0) || - (arb->ent[b].hr == 0)) - break; - if (ara->ent[a].hr < arb->ent[b].hr) { - /* b data missing */ - fprintf(pipe, "%.3f %.3f\n", - ara->ent[a].val, -100.); - a++; - } else if (ara->ent[a].hr > arb->ent[b].hr) { - /* error - a missing */ - fprintf(pipe, "%.3 %.3f\n", - ara->ent[a].val, -100.); - b++; - } else { /* a & b hr agree */ - if (p[i].mode == 0) - fprintf(pipe, "%.3f %.3f\n", - ara->ent[a].val, - arb->ent[b].val); - else - fprintf(pipe, - "%.3f %.3f \"%c\"\n", - ara->ent[a].val, - arb->ent[b].val, - arb->ent[b].qfld[ - strlen( - arb->ent[b].qfld) - 1]); - /* - * Test which index can be incremented without - * incurring a change in ..hr - */ - if ((ara->ent[a+1].hr == - ara->ent[a].hr) && - (arb->ent[b+1].hr != - arb->ent[b].hr)) - /* a free, b constrained */ - a++; - else if ((ara->ent[a+1].hr != - ara->ent[a].hr) && - (arb->ent[b+1].hr == - arb->ent[b].hr)) - /* a constrained, b free */ - b++; - else { - /* Both free or constrained */ - a++; - b++; - } - } - } - pclose(pipe); - } - } - sprintf(cmd, "tplot %s < %s", Targ, plotfile); - fflush(stdout); - system(cmd); - sprintf(cmd, "rm %s", plotfile); - fflush(stdout); - system(cmd); -} - -int -reduce(struct p *pr) -{ - int i, j; - struct array *popar(); - - for (i = 0; i < 4; ) { - if (DEBUG) { - fprintf(stderr, "reduce pr->spec:%s\n", pr->spec); - fprintf(stderr, "pr->c[%d].op:%c\n", i, pr->c[i].op); - } - switch (pr->c[i].op) { - case '+': - case '-': - for (j = i; j < i+2; j++) - if (pr->c[j].dptr == NULL) - if (getdata(pr->c[j].name, - pr->c[j].dptr = popar()) < 0) - return (-1); - combine(pr, i); - break; - case '\0': - if (pr->c[i].dptr == NULL) - if (getdata(pr->c[i].name, - pr->c[i].dptr = popar()) < 0) - return (-1); - if (i == 0) - return (0); - else - goto muldiv; - break; - default: - i++; - break; - } - } - - muldiv: - while (pr->c[0].op != '\0') { - if (DEBUG) - fprintf(stderr, "pr->c[\"0\"].op:%c\n", pr->c[0].op); - for (j = 0; j < 2; j++) - if (pr->c[j].dptr == NULL) - if (getdata(pr->c[j].name, - pr->c[j].dptr = popar()) < 0) - return (-1); - combine(pr, 0); - } - return (0); -} - -static void -scale(struct p p[], int nplot, char *sarg, char *earg, char *xlab_s, - char *xlab_e) -{ - /* - * Scans each data set to find and label those that contain - * multiple entries. Also truncates data values to fit within - * given plotting limits, or if unspecified, finds max value - * over all such data sets and sets their limits. - * If p[0] contains "time" values, its limits are taken from - * the -s and -e args. - */ - - float yrange(); - char *strcpy(); - int i = 0; - int j; - struct array *ara; - float maxd = -1000; - float hrb; - float hr, min; - - if (strmatch("time", p[0].spec) >= 0) { - sscanf(sarg, "-s %s", xlab_s); - hr = min = 0; - sscanf(sarg, "-s %f:%f", &hr, &min); - p[0].min = hr + min/60; - sscanf(earg, "-e %s", xlab_e); - hr = min = 0; - sscanf(earg, "-e %f:%f", &hr, &min); - p[0].max = hr + min/60; - p[0].mode = 0; - i = 1; - } - for (; i <= nplot; i++) { - p[i].mode = 0; - hrb = 0; - ara = p[i].c[0].dptr; - - for (j = 0; j < NPTS; j++) { - if (ara->ent[j].hr == 0) - break; - if (p[i].max > 0) { - ara->ent[j].val = (ara->ent[j].val > - p[i].max) ? p[i].max : ara->ent[j].val; - if (ara->ent[j].val > -1000.) - ara->ent[j].val = - (ara->ent[j].val < p[i].min) ? - p[i].min : ara->ent[j].val; - } - else - maxd = (ara->ent[j].val > maxd) ? - ara->ent[j].val : maxd; - if (ara->ent[j].hr == hrb) - p[i].mode = 1; - hrb = ara->ent[j].hr; - } - - if (i == 0) { - if (p[0].max == 0) { - p[0].min = 0; - p[0].max = yrange(maxd); - maxd = -1000; - } - sprintf(xlab_s, "%1.1f", p[0].min); - sprintf(xlab_e, "%1.1f", p[0].max); - } - } - - /* - * Now that data range has been found, set limits of unspecified - * cases - */ - for (i = 1; i <= nplot; i++) - if (p[i].max == 0) { - p[i].max = yrange(maxd); - p[i].min = 0; - if (p[i].max == 0) - p[i].max = 1.; - } -} diff --git a/usr/src/cmd/sa/sagb.c b/usr/src/cmd/sa/sagb.c deleted file mode 100644 index 5c8a591b02..0000000000 --- a/usr/src/cmd/sa/sagb.c +++ /dev/null @@ -1,490 +0,0 @@ -/* - * 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 - * or http://www.opensolaris.org/os/licensing. - * 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" - -#include "saghdr.h" -#include <strings.h> -#include <stdlib.h> - -void -combine(struct p *p, int pn) -{ - int a, b, c; - int i; - int qi = 0; - float vala, valb; - struct array *ara, *arb, *arc; - struct array *popar(); - - ara = p->c[pn].dptr; - arb = p->c[pn+1].dptr; - arc = popar(); - if (DEBUG) { - fprintf(stderr, - "combine p->c[%d].name:%s & p->c[%d].name:%s\n", - pn, p->c[pn].name, pn+1, p->c[pn+1].name); - fprintf(stderr, " alias ara->hname:%s arb->hname:%s\n", - ara->hname, arb->hname); - } - - for (a = b = c = 0; a < NPTS && b < NPTS && c < NPTS; ) { - if ((ara->ent[a].hr == 0) || (arb->ent[b].hr == 0)) { - /* End of file */ - arc->ent[c].hr = 0; - break; - } - - if ((ara->ent[0].hr < 0) || (arb->ent[0].hr < 0)) { - /* One or both is a constant */ - if ((ara->ent[a].val <= -1000) || - (arb->ent[b].val <= -1000)) - arc->ent[c].val = -1000; - else - switch (p->c[pn].op) { - case '+': - arc->ent[c].val = - ara->ent[a].val + arb->ent[b].val; - break; - case '-': - arc->ent[c].val = - ara->ent[a].val - arb->ent[b].val; - break; - case '*': - arc->ent[c].val = - ara->ent[a].val * arb->ent[b].val; - break; - case '/': - if (arb->ent[b].val != 0) - arc->ent[c].val = - ara->ent[a].val / - arb->ent[b].val; - else - arc->ent[c].val = 0; - break; - default: - break; - } - - if (ara->ent[0].hr >= 0) { - /* a is variable */ - strcpy(arc->ent[c].tm, ara->ent[a].tm); - strcpy(arc->ent[c].qfld, ara->ent[a].qfld); - arc->ent[c].hr = ara->ent[a].hr; - a++; - } else if (arb->ent[0].hr >= 0) { - /* b is variable */ - strcpy(arc->ent[c].tm, arb->ent[b].tm); - strcpy(arc->ent[c].qfld, arb->ent[b].qfld); - arc->ent[c].hr = arb->ent[b].hr; - b++; - } else { - /* Both are constant */ - strcpy(arc->ent[c].tm, ara->ent[a].tm); - strcpy(arc->ent[c].qfld, ara->ent[a].qfld); - arc->ent[c].hr = ara->ent[a].hr; - a++; - b++; - } - c++; - continue; - } - - if (ara->ent[a].hr < arb->ent[b].hr) { - /* b missing */ - arc->ent[c].hr = ara->ent[a].hr; - strcpy(arc->ent[c].tm, ara->ent[a].tm); - strcpy(arc->ent[c].qfld, ara->ent[a].qfld); - vala = ara->ent[a].val; - valb = 0.; - a++; - } else if (ara->ent[a].hr > arb->ent[b].hr) { - /* a missing */ - arc->ent[c].hr = arb->ent[b].hr; - strcpy(arc->ent[c].tm, arb->ent[b].tm); - strcpy(arc->ent[c].qfld, arb->ent[b].qfld); - valb = arb->ent[b].val; - vala = 0.; - b++; - } else { - /* a & b hrs equal */ - arc->ent[c].hr = ara->ent[a].hr; - strcpy(arc->ent[c].tm, ara->ent[a].tm); - vala = ara->ent[a].val; - valb = arb->ent[b].val; - /* - * Test which index can be incremented without - * incurring a change in ..hr - */ - if ((ara->ent[a+1].hr == ara->ent[a].hr) && - (arb->ent[b+1].hr != arb->ent[b].hr)) { - /* a free, b constrained */ - strcpy(arc->ent[c].qfld, ara->ent[a].qfld); - qi = 0; - a++; - } else if ((ara->ent[a+1].hr != ara->ent[a].hr) && - (arb->ent[b+1].hr == arb->ent[b].hr)) { - /* a constrained, b free */ - strcpy(arc->ent[c].qfld, arb->ent[b].qfld); - qi = 1; - b++; - } else { - /* Both free or both constrained */ - if (qi == 1) - strcpy(arc->ent[c].qfld, - arb->ent[b].qfld); - else - strcpy(arc->ent[c].qfld, - ara->ent[a].qfld); - a++; - b++; - } - } - if ((vala <= -1000) || (valb <= -1000)) - arc->ent[c].val = -1000; - else - switch (p->c[pn].op) { - case '+': - arc->ent[c].val = vala + valb; - break; - case '-': - arc->ent[c].val = vala - valb; - break; - case '*': - arc->ent[c].val = vala * valb; - break; - case '/': - if (valb != 0) - arc->ent[c].val = vala / valb; - else - arc->ent[c].val = 0; - break; - default: - break; - } - c++; - } - - sprintf(arc->hname, "%s %c %s", ara->hname, p->c[pn].op, arb->hname); - if (DEBUG) { - printar(ara); - printar(arb); - printar(arc); - } - pushar(ara); - pushar(arb); - p->c[pn].op = p->c[pn+1].op; - p->c[pn].dptr = arc; - for (i = pn + 1; i < 4; i++) { - strcpy(p->c[i].name, p->c[i+1].name); - p->c[i].op = p->c[i+1].op; - p->c[i].dptr = p->c[i+1].dptr; - } -} - - - -/* - * Extracts data from sarc[] array and puts into array entries. Hunts for name - * string among column headers in sarc, and copies following data items from - * corresponding field up to next "Average" line. Special treatment when name - * string contains an integer or "time". - */ -int -getdata(char *name, struct array *array) -{ - extern char fld[NFLD][FLDCH]; - extern FILE *sard; - extern long sardoff; - int fnum; - char nm[18], ql[8]; - int nparts; - int i, j; - int timeflg; - int hr, min, sec; - int nmloc; - float hour; - char *tok; - - if (DEBUG) - fprintf(stderr, "getdata-> name:%s\n", name); - - /* name contains a constant */ - if (sscanf(name, "%f", &array->ent[0].val) == 1) { - /* no sar data is required */ - strcpy(array->ent[0].tm, "***"); - strcpy(array->hname, name); - array->ent[0].hr = -1; - array->ent[0].qfld[0] = '\0'; - array->ent[1].hr = 0; - return (0); - } - - if (strmatch("time", name) >= 0) { - /* Pick up time values from 1st sar group - %usr */ - if (DEBUG) - fprintf(stderr, "name matches time\n"); - strcpy(nm, "%usr"); - strcpy(ql, ""); - nparts = 1; - timeflg = 1; - } else { - nparts = 0; - timeflg = 0; - if ((tok = strtok(name, "[]")) != NULL) { - nparts = 1; - strcpy(nm, tok); - } - if ((tok = strtok(0, "[]")) != NULL) { - nparts++; - strcpy(ql, tok); - } else - strcpy(ql, ""); - } - - /* fprintf(stderr, "nparts:%d nm:%s ql:%s\n", nparts, nm, ql); */ - - fseek(sard, sardoff, 0); /* seek to line 2 of sard */ - while ((fnum = getfld()) != EOF) { - for (i = 0; i < fnum; i++) - if (strmatch(nm, fld[i]) >= 0) { - if (timeflg == 1) { - nmloc = 0; - strcpy(array->hname, "time"); - } else { - nmloc = i; - if (nparts < 2) - strcpy(array->hname, fld[i]); - else - sprintf(array->hname, "%s[%s]", - fld[i], ql); - } - goto readin; - } - } - fprintf(stderr, "\"%s\" data not found\n", nm); - return (-1); - -readin: - for (i = 0; i < NPTS; ) { - if (((fnum = getfld()) == EOF) || (strmatch(":", fld[0]) < 0)) { - array->ent[i].hr = 0; - return (0); - } - if (DEBUG > 1) { - for (j = 0; j < fnum; j++) - fprintf(stderr, " %s", fld[j]); - fputc('\n', stderr); - } - sscanf(fld[0], "%d:%d:%d", &hr, &min, &sec); - hour = (float)hr + (float)min/60 + (float)sec/3600; - if (timeflg == 1) { - strcpy(array->ent[i].tm, fld[0]); - array->ent[i].hr = hour; - array->ent[i].val = hour; - strcpy(array->ent[i].qfld, ""); - i++; - continue; - } - if (strmatch("unix", fld[1]) >= 0) { - strcpy(array->ent[i].tm, fld[0]); - array->ent[i].hr = hour; - array->ent[i].val = -1000.; - strcpy(array->ent[i].qfld, ""); - i++; - continue; - } - if ((nparts > 1) && (strmatch(ql, fld[1]) < 0)) - continue; - - strcpy(array->ent[i].tm, fld[0]); - array->ent[i].hr = hour; - array->ent[i].val = atof(fld[nmloc]); - strcpy(array->ent[i].qfld, fld[1]); - - if (DEBUG > 1) - fprintf(stderr, " .val:%.3f\n", array->ent[i].val); - i++; - } - return (0); -} - - - -/* - * Scans characters pointed to by cp; puts non-blank strings into - * fld[NFLD][FLDCH] up to first newline or EOF. - * - * Returns number of fld's filled (or EOF), with cp updated to next readable - * char. - */ -int -getfld() -{ - extern char fld[NFLD][FLDCH]; - extern FILE *sard; - int fnum = 0, i = 0; - int c; - - while ((c = getc(sard)) != EOF) - switch ((char)c) { - case ' ': - fld[fnum][i] = '\0'; - i = 0; - if (++fnum >= 9) - return (fnum); - break; - case '\n': - fld[fnum][i] = '\0'; - return (++fnum); - break; - default: - fld[fnum][i++] = c; - break; - } - - fld[fnum][i] = '\0'; - if ((i == 0) && (fnum == 0)) - return (EOF); - else - return (++fnum); -} - - -static struct array stack[10]; -static struct array *sp[] = { - &stack[0], - &stack[1], - &stack[2], - &stack[3], - &stack[4], - &stack[5], - &stack[6], - &stack[7], - &stack[8], - &stack[9]}; -static int spn = 10; - - - -struct array * -popar() -{ - if (spn > 0) - return (sp[--spn]); - else - { - fprintf(stderr, "Stack empty\n"); - exit(1); - } -} - - -int -pushar(struct array *par) -{ - if (spn < 10) { - sp[spn++] = par; - return (1); - } else { - fprintf(stderr, "Stack full\n"); - return (0); - } -} - - - -/* - * Strips leading and trailing blanks from string - * by moving string pointer to first non-blank character, - * and replacing trailing blanks with '\0'. - * Returns number of remaining characters. - */ -int -stribl(char *s) -{ - char *a, *b; - - a = b = s; - while (*b == ' ') - b++; - while ((*a++ = *b++) != '\0') - ; - a--; - while (a-- > s) - if (*a != ' ') - break; - else - *a = '\0'; - return (int)(a-s+1); -} - - - -/* - * strmatch looks for an occurrence of string pat - * inside string targ. It returns the number of - * the first starting character position (zero is valid), - * or -1 for no match. - */ -int -strmatch(char *pat, char *targ) -{ - int i, c, ifirst; - - for (ifirst = 0; ; ifirst++) { - i = 0; - do { - if (pat[i] == '\0') - return (ifirst); - if (targ[ifirst + i] == '\0') - return (-1); - c = i++; - } while (pat[c] == targ[ifirst + c]); - } -} - - - -float -yrange(float ff) -{ - static float ylimit[] = {1.0, 1.5, 2.5, 5.0, 10.0}; - float div = 1; - int i = 0; - if (ff <= 0.) - return (0); - while (ff/div > 10.) - div *= 10.; - while (ff/div < 1.) - div /= 10.; - while ((ff/div) > ylimit[i]) - i++; - return (ylimit[i] * div); -} diff --git a/usr/src/cmd/sa/saghdr.h b/usr/src/cmd/sa/saghdr.h deleted file mode 100644 index b9acf1868a..0000000000 --- a/usr/src/cmd/sa/saghdr.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 - * or http://www.opensolaris.org/os/licensing. - * 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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */ -/* saghdr.h 1.4 of 5/13/85 */ -#include <stdio.h> -#define NPTS 100 -#define NFLD 9 -#define FLDCH 10 -#ifndef DEBUG -#define DEBUG 0 -#endif - -struct entry { - char tm[9]; - float hr; - float val; - char qfld[8]; - }; - -struct array { - char hname[56]; - struct entry ent[NPTS]; - }; - - -struct c { - char name[60]; - char op; - struct array *dptr; - }; - -struct p { - char spec[60]; - struct c c[5]; - char mn[10], mx[10]; - float min, max; - int jitems; - int mode; - }; |