add the -s option to summarize multiple runs
authorKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Thu, 12 Nov 1981 13:53:32 +0000 (05:53 -0800)
committerKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Thu, 12 Nov 1981 13:53:32 +0000 (05:53 -0800)
SCCS-vsn: usr.bin/gprof/gprof.c 1.9
SCCS-vsn: usr.bin/gprof/gprof.h 1.8

usr/src/usr.bin/gprof/gprof.c
usr/src/usr.bin/gprof/gprof.h

index d131dca..4a59c80 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-    static     char *sccsid = "@(#)gprof.c     1.8 (Berkeley) %G%";
+    static     char *sccsid = "@(#)gprof.c     1.9 (Berkeley) %G%";
 #endif lint
 
 #include "gprof.h"
 #endif lint
 
 #include "gprof.h"
@@ -14,21 +14,30 @@ main(argc, argv)
     debug = 0;
     while ( *argv != 0 && **argv == '-' ) {
        (*argv)++;
     debug = 0;
     while ( *argv != 0 && **argv == '-' ) {
        (*argv)++;
-       if ( **argv == 'd' ) {
+       switch ( **argv ) {
+       case 'd':
            (*argv)++;
            debug |= atoi( *argv );
            debug |= ANYDEBUG;
 #          ifdef DEBUG
                printf( "[main] debug = %d\n" , debug );
 #          endif DEBUG
            (*argv)++;
            debug |= atoi( *argv );
            debug |= ANYDEBUG;
 #          ifdef DEBUG
                printf( "[main] debug = %d\n" , debug );
 #          endif DEBUG
-       } else if ( **argv == 'a' ) {
+           break;
+       case 'a':
            aflag++;
            aflag++;
-       } else if ( **argv == 'b' ) {
+           break;
+       case 'b':
            bflag++;
            bflag++;
-       } else if ( **argv == 'c' ) {
+           break;
+       case 'c':
            cflag++;
            cflag++;
-       } else if ( **argv == 'z' ) {
+           break;
+       case 's':
+           sflag++;
+           break;
+       case 'z':
            zflag++;
            zflag++;
+           break;
        }
        argv++;
     }
        }
        argv++;
     }
@@ -51,7 +60,18 @@ main(argc, argv)
        /*
         *      get information about mon.out file(s).
         */
        /*
         *      get information about mon.out file(s).
         */
-    getpfile( gmonname );
+    do {
+       getpfile( gmonname );
+       if ( *argv != 0 ) {
+           gmonname = *argv;
+       }
+    } while ( sflag && *argv++ != 0 );
+       /*
+        *      dump out a gmon.sum file if requested
+        */
+       if ( sflag ) {
+           dumpsum( GMONSUM );
+       }
        /*
         *      assign samples to procedures
         */
        /*
         *      assign samples to procedures
         */
@@ -255,13 +275,20 @@ FILE *
 openpfile(filename)
     char *filename;
 {
 openpfile(filename)
     char *filename;
 {
+    struct hdr tmp;
     FILE       *pfile;
 
     if((pfile = fopen(filename, "r")) == NULL) {
        perror(filename);
        done();
     }
     FILE       *pfile;
 
     if((pfile = fopen(filename, "r")) == NULL) {
        perror(filename);
        done();
     }
-    fread(&h, sizeof(struct hdr), 1, pfile);
+    fread(&tmp, sizeof(struct hdr), 1, pfile);
+    if ( s_highpc != 0 && ( tmp.lowpc != h.lowpc ||
+        tmp.highpc != h.highpc || tmp.ncnt != h.ncnt ) ) {
+       fprintf(stderr, "%s: incompatible with first gmon file\n", filename);
+       done();
+    }
+    h = tmp;
     s_lowpc = (unsigned long) h.lowpc;
     s_highpc = (unsigned long) h.highpc;
     lowpc = h.lowpc - (UNIT *)0;
     s_lowpc = (unsigned long) h.lowpc;
     s_highpc = (unsigned long) h.highpc;
     lowpc = h.lowpc - (UNIT *)0;
@@ -289,6 +316,58 @@ tally( rawp )
     addarc( parentp , childp , rawp -> raw_count );
 }
 
     addarc( parentp , childp , rawp -> raw_count );
 }
 
+/*
+ * dump out the gmon.sum file
+ */
+dumpsum( sumfile )
+    char *sumfile;
+{
+    register nltype *nlp;
+    register arctype *arcp;
+    struct rawarc arc;
+    FILE *sfile;
+
+    if ( ( sfile = fopen ( sumfile , "w" ) ) == NULL ) {
+       perror( sumfile );
+       done();
+    }
+    /*
+     * dump the header; use the last header read in
+     */
+    if ( fwrite( &h , sizeof h , 1 , sfile ) != 1 ) {
+       perror( sumfile );
+       done();
+    }
+    /*
+     * dump the samples
+     */
+    if (fwrite(samples, sizeof(unsigned UNIT), nsamples, sfile) != nsamples) {
+       perror( sumfile );
+       done();
+    }
+    /*
+     * dump the normalized raw arc information
+     */
+    for ( nlp = nl ; nlp < npe - 1 ; nlp++ ) {
+       for ( arcp = nlp -> children ; arcp ; arcp = arcp -> arc_childlist ) {
+           arc.raw_frompc = arcp -> arc_parentp -> value;
+           arc.raw_selfpc = arcp -> arc_childp -> value;
+           arc.raw_count = arcp -> arc_count;
+           if ( fwrite ( &arc , sizeof arc , 1 , sfile ) != 1 ) {
+               perror( sumfile );
+               done();
+           }
+#          ifdef DEBUG
+               if ( debug & SAMPLEDEBUG ) {
+                   printf( "[dumpsum] frompc 0x%x selfpc 0x%x count %d\n" ,
+                           arc.raw_frompc , arc.raw_selfpc , arc.raw_count );
+               }
+#          endif DEBUG
+       }
+    }
+    fclose( sfile );
+}
+
 valcmp(p1, p2)
     nltype *p1, *p2;
 {
 valcmp(p1, p2)
     nltype *p1, *p2;
 {
index 1de4bdf..5adb7e5 100644 (file)
@@ -1,11 +1,11 @@
-    /* sccsid:  @(#)gprof.h    1.7 (Berkeley) %G% */
+    /* sccsid:  @(#)gprof.h    1.8 (Berkeley) %G% */
 
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <a.out.h>
 #include <pagsiz.h>
 
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <a.out.h>
 #include <pagsiz.h>
-#include "monitor.h"
+#include "gmcrt0.h"
 
     /*
      * ticks per second
 
     /*
      * ticks per second
@@ -18,6 +18,7 @@ char  *a_outname;
 
 char   *gmonname;
 #define        GMONNAME                "gmon.out"
 
 char   *gmonname;
 #define        GMONNAME                "gmon.out"
+#define        GMONSUM                 "gmon.sum"
 
     /*
      * a constructed arc,
 
     /*
      * a constructed arc,
@@ -131,6 +132,7 @@ unsigned char       *textspace;             /* text space of a.out in core */
 int    aflag;                          /* static functions, too */
 int    bflag;                          /* blurbs, too */
 int    cflag;                          /* discovered call graph, too */
 int    aflag;                          /* static functions, too */
 int    bflag;                          /* blurbs, too */
 int    cflag;                          /* discovered call graph, too */
+int    sflag;                          /* sum multiple gmon.out files */
 int    zflag;                          /* zero time/called functions, too */
 
     /*
 int    zflag;                          /* zero time/called functions, too */
 
     /*