1: /*
   2:  *  Print execution profile
   3:  */
   4: 
   5: struct nl {
   6:     char name[8];
   7:     int value;
   8:     float time;
   9:     int ncall[2];
  10: };
  11: 
  12: struct nl nl[600];
  13: 
  14: struct fnl {
  15:     char fname[8];
  16:     int flag;
  17:     int fvalue;
  18: };
  19: 
  20: struct cnt {
  21:     int cvalue;
  22:     int cncall[2];
  23: } cbuf[200];
  24: 
  25: struct inode {
  26:     int idev;
  27:     int inum;
  28:     int flags;
  29:     char nlink;
  30:     char uid;
  31:     char    gid;
  32:     char    size0;
  33:     int size;
  34:     int ptr[8];
  35:     int ctime[2];
  36:     int mtime[2];
  37:     int fill;
  38: };
  39: 
  40: int ibuf[259];
  41: int obuf[259];
  42: int buf[17];
  43: int i;
  44: int j;
  45: int highpc;
  46: int lowpc;
  47: int ccnt;
  48: int pcl;
  49: int pch;
  50: int bufs;
  51: int nname;
  52: double  time;
  53: double  totime;
  54: double  maxtime;
  55: double  scale;
  56: double  lastx;
  57: double  lasty;
  58: struct nl *np;
  59: struct nl *npe;
  60: int aflg;
  61: int vflg;
  62: int lflg;
  63: int symoff;
  64: int symsiz;
  65: int vf;
  66: int etext;
  67: int ncount;
  68: 
  69: main(argc, argv)
  70: char **argv;
  71: {
  72:     char *namfil;
  73:     int timcmp(), valcmp();
  74:     int nf, pf, overlap;
  75:     double fnc, ltod(), lastsx;
  76:     struct cnt *cp;
  77: 
  78:     obuf[0] = 1;
  79:     argv++;
  80:     namfil = "a.out";
  81:     while (argc>1) {
  82:         if (**argv == '-') {
  83:             if (*++*argv == 'l')
  84:                 lflg++;
  85:             if (**argv == 'a')
  86:                 aflg = 040;
  87:             if(**argv == 'v')
  88:                 vflg++;
  89:         } else
  90:             namfil = *argv;
  91:         argc--;
  92:         argv++;
  93:     }
  94:     if ((nf = open(namfil, 0)) < 0) {
  95:         printf("Can't find %s\n", namfil);
  96:         done();
  97:     }
  98:     read(nf, buf, 020);
  99:     if (buf[0] != 0407 && buf[0] != 0410 && buf[0] != 0411) { /* a.out magic */
 100:         printf("Bad format: %s\n", namfil);
 101:         done();
 102:     }
 103:     symsiz = buf[4];
 104:     symoff = buf[1] + buf[2];
 105:     if (buf[7] != 1)
 106:         symoff =<< 1;
 107:     seek(nf, symoff+020, 0);
 108:     if ((pf = open("mon.out", 0)) < 0) {
 109:         printf("No mon.out\n");
 110:         done();
 111:     }
 112:     fstat(pf, buf);
 113:     read(pf, &lowpc, 2);
 114:     read(pf, &highpc, 2);
 115:     read(pf, &ncount, 2);
 116:     bufs = buf->size/2 - 3*(ncount+1);
 117:     read(pf, cbuf, ncount*6);
 118:     lowpc = (lowpc>>1) & 077777;
 119:     highpc = (highpc>>1) & 077777;
 120:     npe = nl;
 121:     initf(nf);
 122:     for (nname = 0; symsiz > 0; symsiz =- 12) {
 123:         for(i=0; i<12; i++)
 124:             buf->fname[i] = getc(ibuf);
 125:         if ((buf->flag | aflg) != 042)
 126:             continue;
 127:         buf->fvalue = (buf->fvalue>>1) & 077777;
 128:         npe->value = buf->fvalue;
 129:         for (i=0; i<8; i++)
 130:             npe->name[i] = buf->fname[i];
 131:         npe++;
 132:         nname++;
 133:     }
 134:     if (nname == 0) {
 135:         printf("No symbols: %s\n", namfil);
 136:         done();
 137:     }
 138:     npe->value = 077777;
 139:     npe++;
 140:     for (cp = cbuf; cp < &cbuf[ncount]; cp++)
 141:         for (np = nl; np < npe; np++)
 142:             if (cp->cvalue-8 == np->value<<1) {
 143:                 np->ncall[0] = cp->cncall[0];
 144:                 np->ncall[1] = cp->cncall[1];
 145:                 break;
 146:             }
 147:     qsort(nl, nname, 18, &valcmp);
 148:     scale = (highpc-lowpc)/(bufs+0.0);
 149:     initf(pf);
 150:     for (i=0; (j = getc(ibuf)) != -1; i++) {
 151:         ccnt.fname[0] = j;
 152:         ccnt.fname[1] = getc(ibuf);
 153:         if (ccnt == 0)
 154:             continue;
 155:         time = ccnt;
 156:         if (ccnt<0)
 157:             time =+ 65536.;
 158:         totime =+ time;
 159:         if(time > maxtime)
 160:             maxtime = time;
 161:         pcl = lowpc + scale*i - 1;
 162:         pch = lowpc + scale*(i+1) - 1;
 163:         for (j=0; j<nname; j++) {
 164:             if (pch < nl[j].value)
 165:                 break;
 166:             if (pcl >= nl[j+1].value)
 167:                 continue;
 168:             overlap=(min(pch,nl[j+1].value)-max(pcl,nl[j].value));
 169:             nl[j].time =+ overlap*time/scale;
 170:         }
 171:     }
 172:     if (totime==0.0) {
 173:         printf("No time accumulated\n");
 174:         done();
 175:     }
 176:     if(!vflg)
 177:         goto print;
 178:     vf = open("/dev/vt0", 1);
 179:     if(vf < 0) {
 180:         printf("Cannot open vt\n");
 181:         done();
 182:     }
 183:     obuf[0] = vf;
 184:     vtch(1);
 185:     vtch(1);
 186:     vtch(3);
 187:     point(-2048., -2048.);
 188:     point(-2048., 2048.);
 189:     vtch(3);
 190:     point(0., -2048.);
 191:     point(0., 2048.);
 192:     for(j=0; j<9; j++) {
 193:         vtch(3);
 194:         point(-2048., 2048. - j*512.);
 195:         point(0., 2048. - j*512.);
 196:     }
 197:     lastx = 0.;
 198:     lasty = 2048.;
 199:     scale = 4096./(i+2);
 200:     seek(pf, 6*(ncount+1), 0);
 201:     initf(pf);
 202:     lastsx = 0.0;
 203:     while((j = getc(ibuf)) != -1) {
 204:         ccnt.fname[0] = j;
 205:         ccnt.fname[1] = getc(ibuf);
 206:         time = ccnt;
 207:         if(ccnt < 0)
 208:             time =+ 65536.;
 209:         vtch(3);
 210:         point(lastsx, lasty);
 211:         lastsx =- 2000.*time/totime;
 212:         point(lastsx, lasty-scale);
 213:         if (ccnt!=0 || lastx!=0.0) {
 214:             vtch(3);
 215:             point(lastx, lasty);
 216:             lastx = -time*2000./maxtime;
 217:             point(lastx, lasty);
 218:         }
 219:         lasty =- scale;
 220:     }
 221:     scale = 4096./(highpc-lowpc);
 222:     lastx = 50.;
 223:     for(np = nl; np<npe;  np++) {
 224:         if(np->value < lowpc)
 225:             continue;
 226:         if(np->value >= highpc)
 227:             continue;
 228:         time = np->time/totime;
 229:         lasty = 2048. - (np->value - lowpc)*scale;
 230:         vtch(3);
 231:         point(0., lasty);
 232:         point(50., lasty);
 233:         vtch(3);
 234:         point(lastx-50., lasty);
 235:         point(lastx, lasty);
 236:         vtch(9);
 237:         point(lastx+10., lasty+60.);
 238:         vtch(1);
 239:         vtch(3);
 240:         for(j=0; j<8; j++)
 241:             if(np->name[j] != '_')
 242:             vtch(np->name[j]);
 243:         vtch(0);
 244:         lastx =+ 500.;
 245:         if(lastx > 2000.)
 246:             lastx = 50.;
 247:     }
 248:     done();
 249: 
 250: print:
 251:     printf("    name %%time #call  ms/call\n");
 252:     if (!lflg)
 253:         qsort(nl, nname, 18, &timcmp);
 254:     for (np = nl; np<npe-1; np++) {
 255:         time = np->time/totime;
 256:         printf("%8.8s%6.1f", np->name, 100*time);
 257:         fnc = ltod(np->ncall);
 258:         if (fnc != 0.0) {
 259:             printf("%6s", locv(np->ncall[0], np->ncall[1]));
 260:             printf(" %7.2f\n", np->time/(fnc*.06));
 261:         } else
 262:             printf("\n");
 263:     }
 264:     done();
 265: }
 266: 
 267: min(a, b)
 268: {
 269:     if (a<b)
 270:         return(a);
 271:     return(b);
 272: }
 273: 
 274: max(a, b)
 275: {
 276:     if (a>b)
 277:         return(a);
 278:     return(b);
 279: }
 280: 
 281: valcmp(p1, p2)
 282: struct nl *p1, *p2;
 283: {
 284:     return(p1->value - p2->value);
 285: }
 286: 
 287: timcmp(p1, p2)
 288: struct nl *p1, *p2;
 289: {
 290:     float d;
 291: 
 292:     d = p2->time - p1->time;
 293:     if (d > 0.0)
 294:         return(1);
 295:     if (d < 0.0)
 296:         return(-1);
 297:     return(0);
 298: }
 299: 
 300: vtch(c)
 301: int c;
 302: {
 303: 
 304:     putchar(c&0377);
 305: }
 306: 
 307: point(x, y)
 308: float x, y;
 309: {
 310: 
 311:     point1(x);
 312:     point1(y);
 313: }
 314: 
 315: putchar(c)
 316: {
 317: 
 318:     putc(c, obuf);
 319: }
 320: 
 321: point1(xy)
 322: float xy;
 323: {
 324:     int ixy;
 325:     struct { char b1; char b2;};
 326: 
 327:     if(xy > 2047.)
 328:         xy = 2047.;
 329:     if(xy < -2048.)
 330:         xy = -2048.;
 331:     ixy = xy;
 332:     vtch(ixy.b1);
 333:     vtch(ixy.b2);
 334: }
 335: 
 336: done()
 337: {
 338: 
 339:     fflush(obuf);
 340:     exit();
 341: }
 342: 
 343: initf(f)
 344: {
 345: 
 346:     ibuf[0] = f;
 347:     ibuf[1] = 0;
 348:     ibuf[2] = 0;
 349:     ibuf[3] = 0;
 350: }

Defined functions

done defined in line 336; used 8 times
initf defined in line 343; used 3 times
main defined in line 69; never used
max defined in line 274; used 1 times
min defined in line 267; used 1 times
point defined in line 307; used 15 times
point1 defined in line 321; used 2 times
putchar defined in line 315; used 1 times
timcmp defined in line 287; used 2 times
valcmp defined in line 281; used 2 times
vtch defined in line 300; used 16 times

Defined variables

aflg defined in line 60; used 2 times
buf defined in line 42; used 16 times
bufs defined in line 50; used 2 times
cbuf defined in line 23; used 3 times
ccnt defined in line 47; used 10 times
etext defined in line 66; never used
highpc defined in line 45; used 6 times
i defined in line 43; used 14 times
ibuf defined in line 40; used 9 times
j defined in line 44; used 22 times
lastx defined in line 56; used 12 times
lasty defined in line 57; used 12 times
lflg defined in line 62; used 2 times
lowpc defined in line 46; used 9 times
maxtime defined in line 54; used 3 times
ncount defined in line 67; used 5 times
nl defined in line 12; used 11 times
nname defined in line 51; used 6 times
np defined in line 58; used 24 times
npe defined in line 59; used 9 times
obuf defined in line 41; used 4 times
pch defined in line 49; used 3 times
pcl defined in line 48; used 3 times
scale defined in line 55; used 9 times
symoff defined in line 63; used 3 times
symsiz defined in line 64; used 3 times
time defined in line 52; used 26 times
totime defined in line 53; used 5 times
vf defined in line 65; used 3 times
vflg defined in line 61; used 2 times

Defined struct's

cnt defined in line 20; used 2 times
  • in line 76(2)
fnl defined in line 14; never used
inode defined in line 25; never used
nl defined in line 5; used 10 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1629
Valid CSS Valid XHTML 1.0 Strict