void show_area_being_processed(char *area, int n) { static char *last_area = NULL; if (verbose < 0) return; if (last_area) { if (total_shown) show_total(); fputs(")", stdout); col += 1; } if (!last_area || !STREQ(area, last_area)) { if (last_area) { col_cleanup(0); total_shown = 0; total_mmm = show_range + 1; } (void) col_output(strlen(area) + 2); fprintf(stdout, "[%s", area); last_area = area; } fputs(" (", stdout); col += 2; show_range = n; total_mmm = n + 1; fflush(stdout); }
void col_cleanup(int eoj) { if (verbose < 0) return; if (eoj) { show_total(); fputs(")]", stdout); } if (col) { fputc('\n', stdout); col = 0; } }
void show_new(char *msg) { if (verbose < 0) return; total_shown++; if (total_mmm > show_range) { show_total(); } else if (total_mmm == 0) { fputc('*', stdout); fflush(stdout); col += 1; } total_mmm++; }
int main(int argc,char *argv[]) { char *mname; FILE *fp; long size,len; char *buf,*p; int i,nrecs = 0; struct profdata *pdata,*pd; if (argc >= 2) { if (*argv[1]=='-' || *argv[1]=='?') { printf("%s V%d.%d%c (c)1998 by Frank Wille\n" "Usage:\n %s [mon.out]\n",argv[0], VERSION,REVISION,PLEVEL?('a'+PLEVEL-1):' ',argv[0]); exit(1); } else mname = argv[1]; } else mname = DEFAULTNAME; if (fp = fopen(mname,"r")) { /* determine file size */ fseek(fp,0,SEEK_END); size = ftell(fp); fseek(fp,0,SEEK_SET); if (size < 0) { fclose(fp); fprintf(stderr,"%s: Seek error on %s!\n",argv[0],mname); exit(EXIT_FAILURE); } /* allocate buffer and read file */ if (!(buf = malloc(size))) { fclose(fp); fprintf(stderr,"%s: Not enough memory!\n",argv[0]); exit(EXIT_FAILURE); } if (fread(buf,1,size,fp) != size) { fclose(fp); fprintf(stderr,"%s: %s had a read error!\n",argv[0],mname); exit(EXIT_FAILURE); } fclose(fp); /* count number of entries in mon.out and allocate profdata array */ p = buf; while (p < buf+size) { nrecs++; p = skipname(p) + 2*sizeof(unsigned long); } if (p!=buf+size || nrecs==0) { fprintf(stderr,"%s: %s: Corrupted file format.\n",argv[0],mname); exit(EXIT_FAILURE); } if (!(pdata = malloc(nrecs * sizeof(struct profdata)))) { fprintf(stderr,"%s: Not enough memory!\n",argv[0]); exit(EXIT_FAILURE); } /* fill profdata array */ for (i=0,p=buf,pd=pdata; i<nrecs; i++,pd++) { pd->funcname = p; p = skipname(p); pd->ncalls = *(unsigned long *)p; pd->tottime = *(unsigned long *)(p+sizeof(unsigned long)); p += 2*sizeof(unsigned long); } /* display */ show_total(pdata,nrecs); } else { fprintf(stderr,"%s: Can't open %s.\n",argv[0],mname); exit(EXIT_FAILURE); } return 0; }