[BACK]Return to gprof.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / gprof

Diff for /src/usr.bin/gprof/gprof.c between version 1.6 and 1.7

version 1.6, 2000/12/24 00:28:46 version 1.7, 2001/03/22 05:18:30
Line 50 
Line 50 
   
 #include "gprof.h"  #include "gprof.h"
   
 char    *whoami = "gprof";  
   
     /*      /*
      *  things which get -E excluded by default.       *  things which get -E excluded by default.
      */       */
Line 59 
Line 57 
   
 static struct gmonhdr   gmonhdr;  static struct gmonhdr   gmonhdr;
   
   int
 main(argc, argv)  main(argc, argv)
     int argc;      int argc;
     char **argv;      char **argv;
Line 87 
Line 86 
 #if defined(__i386__) || defined(__vax__) || defined(__tahoe__) || defined(__sparc__)  #if defined(__i386__) || defined(__vax__) || defined(__tahoe__) || defined(__sparc__)
             cflag = TRUE;              cflag = TRUE;
 #else  #else
             fprintf(stderr, "gprof: -c isn't supported on this architecture yet\n");              fprintf(stderr, "%s: -c isn't supported on this architecture yet\n", __progname);
             exit(1);              exit(1);
 #endif  #endif
             break;              break;
Line 99 
Line 98 
 #           ifdef DEBUG  #           ifdef DEBUG
                 printf("[main] debug = %d\n", debug);                  printf("[main] debug = %d\n", debug);
 #           else not DEBUG  #           else not DEBUG
                 printf("%s: -d ignored\n", whoami);                  warnx("-d ignored");
 #           endif DEBUG  #           endif DEBUG
             break;              break;
         case 'E':          case 'E':
Line 178 
Line 177 
          */           */
     if (hz == 0) {      if (hz == 0) {
         hz = 1;          hz = 1;
         fprintf(stderr, "time is in ticks, not seconds\n");          warnx("time is in ticks, not seconds");
     }      }
         /*          /*
          *      dump out a gmon.sum file if requested           *      dump out a gmon.sum file if requested
Line 206 
Line 205 
          *      print the index           *      print the index
          */           */
     printindex();      printindex();
     done();  
       return (0);
 }  }
   
     /*      /*
Line 214 
Line 214 
      *  and optionally the text space.       *  and optionally the text space.
      * On return symbol table is sorted by value.       * On return symbol table is sorted by value.
      */       */
   void
 getnfile()  getnfile()
 {  {
     FILE        *nfile;      FILE        *nfile;
     int         valcmp();      int         valcmp();
   
     nfile = fopen( a_outname ,"r");      nfile = fopen( a_outname ,"r");
     if (nfile == NULL) {      if (nfile == NULL)
         perror( a_outname );          err(1, "fopen: %s", a_outname);
         done();  
     }  
     fread(&xbuf, 1, sizeof(xbuf), nfile);      fread(&xbuf, 1, sizeof(xbuf), nfile);
     if (N_BADMAG(xbuf)) {      if (N_BADMAG(xbuf))
         fprintf(stderr, "%s: %s: bad format\n", whoami , a_outname );          errx(1, "%s: bad format", a_outname );
         done();  
     }  
     getstrtab(nfile);      getstrtab(nfile);
     getsymtab(nfile);      getsymtab(nfile);
     gettextspace( nfile );      gettextspace( nfile );
Line 245 
Line 242 
 #   endif DEBUG  #   endif DEBUG
 }  }
   
   void
 getstrtab(nfile)  getstrtab(nfile)
     FILE        *nfile;      FILE        *nfile;
 {  {
   
     fseek(nfile, (long)(N_SYMOFF(xbuf) + xbuf.a_syms), 0);      fseek(nfile, (long)(N_SYMOFF(xbuf) + xbuf.a_syms), 0);
     if (fread(&ssiz, sizeof (ssiz), 1, nfile) == 0) {      if (fread(&ssiz, sizeof (ssiz), 1, nfile) == 0)
         fprintf(stderr, "%s: %s: no string table (old format?)\n" ,          errx(1, "%s: no string table (old format?)" , a_outname);
                 whoami , a_outname );  
         done();  
     }  
     strtab = calloc(ssiz, 1);      strtab = calloc(ssiz, 1);
     if (strtab == NULL) {      if (strtab == NULL)
         fprintf(stderr, "%s: %s: no room for %d bytes of string table\n",          errx(1, "%s: no room for %ld bytes of string table", a_outname , ssiz);
                 whoami , a_outname , ssiz);      if (fread(strtab+sizeof(ssiz), ssiz-sizeof(ssiz), 1, nfile) != 1)
         done();          err(1, "%s: reading string table", a_outname);
     }  
     if (fread(strtab+sizeof(ssiz), ssiz-sizeof(ssiz), 1, nfile) != 1) {  
         fprintf(stderr, "%s: %s: error reading string table\n",  
                 whoami , a_outname );  
         done();  
     }  
 }  }
   
     /*      /*
      * Read in symbol table       * Read in symbol table
      */       */
   void
 getsymtab(nfile)  getsymtab(nfile)
     FILE        *nfile;      FILE        *nfile;
 {  {
Line 288 
Line 278 
         }          }
         nname++;          nname++;
     }      }
     if (nname == 0) {      if (nname == 0)
         fprintf(stderr, "%s: %s: no symbols\n", whoami , a_outname );          errx(1, "%s: no symbols", a_outname);
         done();  
     }  
     askfor = nname + 1;      askfor = nname + 1;
     nl = (nltype *) calloc( askfor , sizeof(nltype) );      nl = (nltype *) calloc( askfor , sizeof(nltype) );
     if (nl == 0) {      if (nl == 0)
         fprintf(stderr, "%s: No room for %d bytes of symbol table\n",          errx(1, "No room for %d bytes of symbol table",
                 whoami, askfor * sizeof(nltype) );              askfor * sizeof(nltype));
         done();  
     }  
   
     /* pass2 - read symbols */      /* pass2 - read symbols */
     fseek(nfile, (long)N_SYMOFF(xbuf), 0);      fseek(nfile, (long)N_SYMOFF(xbuf), 0);
Line 332 
Line 318 
     /*      /*
      *  read in the text space of an a.out file       *  read in the text space of an a.out file
      */       */
   void
 gettextspace( nfile )  gettextspace( nfile )
     FILE        *nfile;      FILE        *nfile;
 {  {
Line 341 
Line 328 
     }      }
     textspace = (u_char *) malloc( xbuf.a_text );      textspace = (u_char *) malloc( xbuf.a_text );
     if ( textspace == 0 ) {      if ( textspace == 0 ) {
         fprintf( stderr , "%s: ran out room for %d bytes of text space:  " ,          warnx("ran out room for %d bytes of text space: can't do -c", xbuf.a_text );
                         whoami , xbuf.a_text );  
         fprintf( stderr , "can't do -c\n" );  
         return;          return;
     }      }
     (void) fseek( nfile , N_TXTOFF( xbuf ) , 0 );      (void) fseek( nfile , N_TXTOFF( xbuf ) , 0 );
     if ( fread( textspace , 1 , xbuf.a_text , nfile ) != xbuf.a_text ) {      if ( fread( textspace , 1 , xbuf.a_text , nfile ) != xbuf.a_text ) {
         fprintf( stderr , "%s: couldn't read text space:  " , whoami );          warnx("couldn't read text space: can't do -c");
         fprintf( stderr , "can't do -c\n" );  
         free( textspace );          free( textspace );
         textspace = 0;          textspace = NULL;
         return;          return;
     }      }
 }  }
Line 360 
Line 344 
      *  an array of sampling hits within pc ranges,       *  an array of sampling hits within pc ranges,
      *  and the arcs.       *  and the arcs.
      */       */
   void
 getpfile(filename)  getpfile(filename)
     char *filename;      char *filename;
 {  {
Line 397 
Line 382 
     int                 size;      int                 size;
     int                 rate;      int                 rate;
   
     if((pfile = fopen(filename, "r")) == NULL) {      if((pfile = fopen(filename, "r")) == NULL)
         perror(filename);          err(1, "fopen: %s", filename);
         done();  
     }  
     fread(&tmp, sizeof(struct gmonhdr), 1, pfile);      fread(&tmp, sizeof(struct gmonhdr), 1, pfile);
     if ( s_highpc != 0 && ( tmp.lpc != gmonhdr.lpc ||      if ( s_highpc != 0 && ( tmp.lpc != gmonhdr.lpc ||
          tmp.hpc != gmonhdr.hpc || tmp.ncnt != gmonhdr.ncnt ) ) {           tmp.hpc != gmonhdr.hpc || tmp.ncnt != gmonhdr.ncnt))
         fprintf(stderr, "%s: incompatible with first gmon file\n", filename);          errx(1, "%s: incompatible with first gmon file", filename);
         done();  
     }  
     gmonhdr = tmp;      gmonhdr = tmp;
     if ( gmonhdr.version == GMONVERSION ) {      if ( gmonhdr.version == GMONVERSION ) {
         rate = gmonhdr.profrate;          rate = gmonhdr.profrate;
Line 419 
Line 400 
     }      }
     if (hz == 0) {      if (hz == 0) {
         hz = rate;          hz = rate;
     } else if (hz != rate) {      } else if (hz != rate)
         fprintf(stderr,          errx(1, "%s: profile clock rate (%d) incompatible with clock rate "
             "%s: profile clock rate (%d) %s (%d) in first gmon file\n",              "(%ld) in first gmon file", filename, rate, hz);
             filename, rate, "incompatible with clock rate", hz);  
         done();  
     }  
     s_lowpc = (unsigned long) gmonhdr.lpc;      s_lowpc = (unsigned long) gmonhdr.lpc;
     s_highpc = (unsigned long) gmonhdr.hpc;      s_highpc = (unsigned long) gmonhdr.hpc;
     lowpc = (unsigned long)gmonhdr.lpc / sizeof(UNIT);      lowpc = (unsigned long)gmonhdr.lpc / sizeof(UNIT);
Line 447 
Line 425 
     return(pfile);      return(pfile);
 }  }
   
   void
 tally( rawp )  tally( rawp )
     struct rawarc       *rawp;      struct rawarc       *rawp;
 {  {
Line 475 
Line 454 
 /*  /*
  * dump out the gmon.sum file   * dump out the gmon.sum file
  */   */
   void
 dumpsum( sumfile )  dumpsum( sumfile )
     char *sumfile;      char *sumfile;
 {  {
Line 483 
Line 463 
     struct rawarc arc;      struct rawarc arc;
     FILE *sfile;      FILE *sfile;
   
     if ( ( sfile = fopen ( sumfile , "w" ) ) == NULL ) {      if ( ( sfile = fopen ( sumfile , "w" ) ) == NULL )
         perror( sumfile );          err(1, "fopen: %s", sumfile);
         done();  
     }  
     /*      /*
      * dump the header; use the last header read in       * dump the header; use the last header read in
      */       */
     if ( fwrite( &gmonhdr , sizeof gmonhdr , 1 , sfile ) != 1 ) {      if ( fwrite( &gmonhdr , sizeof gmonhdr , 1 , sfile ) != 1 )
         perror( sumfile );          err(1, "fwrite: %s", sumfile);
         done();  
     }  
     /*      /*
      * dump the samples       * dump the samples
      */       */
     if (fwrite(samples, sizeof (UNIT), nsamples, sfile) != nsamples) {      if (fwrite(samples, sizeof (UNIT), nsamples, sfile) != nsamples)
         perror( sumfile );          err(1, "fwrite: %s", sumfile);
         done();  
     }  
     /*      /*
      * dump the normalized raw arc information       * dump the normalized raw arc information
      */       */
Line 509 
Line 483 
             arc.raw_frompc = arcp -> arc_parentp -> value;              arc.raw_frompc = arcp -> arc_parentp -> value;
             arc.raw_selfpc = arcp -> arc_childp -> value;              arc.raw_selfpc = arcp -> arc_childp -> value;
             arc.raw_count = arcp -> arc_count;              arc.raw_count = arcp -> arc_count;
             if ( fwrite ( &arc , sizeof arc , 1 , sfile ) != 1 ) {              if (fwrite ( &arc , sizeof arc , 1 , sfile ) != 1)
                 perror( sumfile );                  err(1, "fwrite: %s", sumfile);
                 done();  
             }  
 #           ifdef DEBUG  #           ifdef DEBUG
                 if ( debug & SAMPLEDEBUG ) {                  if ( debug & SAMPLEDEBUG ) {
                     printf( "[dumpsum] frompc 0x%x selfpc 0x%x count %d\n" ,                      printf( "[dumpsum] frompc 0x%x selfpc 0x%x count %d\n" ,
Line 524 
Line 496 
     fclose( sfile );      fclose( sfile );
 }  }
   
   int
 valcmp(p1, p2)  valcmp(p1, p2)
     nltype *p1, *p2;      nltype *p1, *p2;
 {  {
Line 536 
Line 509 
     return EQUALTO;      return EQUALTO;
 }  }
   
   void
 readsamples(pfile)  readsamples(pfile)
     FILE        *pfile;      FILE        *pfile;
 {  {
     register i;  
     UNIT        sample;      UNIT        sample;
       register int i;
   
     if (samples == 0) {      if (samples == 0) {
         samples = (UNIT *) calloc(sampbytes, sizeof (UNIT));          samples = (UNIT *) calloc(sampbytes, sizeof (UNIT));
         if (samples == 0) {          if (samples == 0)
             fprintf( stderr , "%s: No room for %d sample pc's\n",              errx(1, "No room for %d sample pc's", sampbytes / sizeof (UNIT));
                 whoami , sampbytes / sizeof (UNIT));  
             done();  
         }  
     }      }
     for (i = 0; i < nsamples; i++) {      for (i = 0; i < nsamples; i++) {
         fread(&sample, sizeof (UNIT), 1, pfile);          fread(&sample, sizeof (UNIT), 1, pfile);
Line 556 
Line 527 
                 break;                  break;
         samples[i] += sample;          samples[i] += sample;
     }      }
     if (i != nsamples) {      if (i != nsamples)
         fprintf(stderr,          errx(1, "unexpected EOF after reading %d/%d samples", i, nsamples );
             "%s: unexpected EOF after reading %d/%d samples\n",  
                 whoami , i , nsamples );  
         done();  
     }  
 }  }
   
 /*  /*
Line 596 
Line 563 
  *      only one sample for every four bytes of text space and never   *      only one sample for every four bytes of text space and never
  *      have any overlap (the two end cases, above).   *      have any overlap (the two end cases, above).
  */   */
   void
 asgnsamples()  asgnsamples()
 {  {
     register int        j;      register int        j;
Line 685 
Line 653 
      *  if it turns out that the entry point is in one bucket and the code       *  if it turns out that the entry point is in one bucket and the code
      *  for a routine is in the next bucket.       *  for a routine is in the next bucket.
      */       */
   void
 alignentries()  alignentries()
 {  {
     register struct nl  *nlp;      register struct nl  *nlp;
Line 742 
Line 711 
                 return TRUE;                  return TRUE;
     }      }
 #endif  #endif
     while ( c = *name++ ) {      while ((c = *name++))
         if ( c == '.' ) {          if (c == '.')
             return FALSE;              return FALSE;
         }  
     }  
     return TRUE;  
 }  
   
 done()      return TRUE;
 {  
   
     exit(0);  
 }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7