date and time created 83/02/24 12:56:06 by mckusick
[unix-history] / usr / src / usr.bin / gprof / printgprof.c
index f16e42f..1604ae4 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-    static     char *sccsid = "@(#)printgprof.c        1.9 (Berkeley) %G%";
+    static     char *sccsid = "@(#)printgprof.c        1.13 (Berkeley) %G%";
 #endif lint
 
 #include "gprof.h"
 #endif lint
 
 #include "gprof.h"
@@ -12,7 +12,16 @@ printprof()
 
     printf( "\ngranularity: each sample hit covers %d byte(s)" ,
            (long) scale * sizeof(UNIT) );
 
     printf( "\ngranularity: each sample hit covers %d byte(s)" ,
            (long) scale * sizeof(UNIT) );
-    printf( " for %.2f%% of %.2f seconds\n\n" , 100.0/totime , totime / HZ );
+    if ( totime > 0.0 ) {
+       printf( " for %.2f%% of %.2f seconds\n\n" ,
+               100.0/totime , totime / hz );
+    } else {
+       printf( " no time accumulated\n\n" );
+           /*
+            *  this doesn't hurt sinc eall the numerators will be zero.
+            */
+       totime = 1.0;
+    }
     actime = 0.0;
     flatprofheader();
        /*
     actime = 0.0;
     flatprofheader();
        /*
@@ -59,7 +68,7 @@ flatprofheader()
 {
     
     if ( bflag ) {
 {
     
     if ( bflag ) {
-       printblurb( "flat.blurb" );
+       printblurb( FLAT_BLURB );
     }
     printf( "%5.5s %7.7s %7.7s %7.7s %-8.8s\n" ,
            "%time" , "cumsecs" , "seconds" , "calls" , "name" );
     }
     printf( "%5.5s %7.7s %7.7s %7.7s %-8.8s\n" ,
            "%time" , "cumsecs" , "seconds" , "calls" , "name" );
@@ -74,7 +83,7 @@ flatprofline( np )
     }
     actime += np -> time;
     printf( "%5.1f %7.2f %7.2f" ,
     }
     actime += np -> time;
     printf( "%5.1f %7.2f %7.2f" ,
-       100 * np -> time / totime , actime / HZ , np -> time / HZ );
+       100 * np -> time / totime , actime / hz , np -> time / hz );
     if ( np -> ncall != 0 ) {
        printf( " %7d" , np -> ncall );
     } else {
     if ( np -> ncall != 0 ) {
        printf( " %7d" , np -> ncall );
     } else {
@@ -87,12 +96,20 @@ gprofheader()
 {
 
     if ( bflag ) {
 {
 
     if ( bflag ) {
-       printblurb( "callg.blurb" );
+       printblurb( CALLG_BLURB );
     }
     printf( "\ngranularity: each sample hit covers %d byte(s)" ,
            (long) scale * sizeof(UNIT) );
     }
     printf( "\ngranularity: each sample hit covers %d byte(s)" ,
            (long) scale * sizeof(UNIT) );
-    printf( " for %.2f%% of %.2f seconds\n\n" ,
-           100.0/printtime , printtime / HZ );
+    if ( printtime > 0.0 ) {
+       printf( " for %.2f%% of %.2f seconds\n\n" ,
+               100.0/printtime , printtime / hz );
+    } else {
+       printf( " no time propagated\n\n" );
+           /*
+            *  this doesn't hurt, since all the numerators will be 0.0
+            */
+       printtime = 1.0;
+    }
     printf( "%6.6s %5.5s %7.7s %11.11s %7.7s/%-7.7s     %-8.8s\n" ,
        "" , "" , "" , "" , "called" , "total" , "parents" , "" );
     printf( "%-6.6s %5.5s %7.7s %11.11s %7.7s+%-7.7s %-8.8s\t%5.5s\n" ,
     printf( "%6.6s %5.5s %7.7s %11.11s %7.7s/%-7.7s     %-8.8s\n" ,
        "" , "" , "" , "" , "called" , "total" , "parents" , "" );
     printf( "%-6.6s %5.5s %7.7s %11.11s %7.7s+%-7.7s %-8.8s\t%5.5s\n" ,
@@ -111,9 +128,9 @@ gprofline( np )
     sprintf( kirkbuffer , "[%d]" , np -> index );
     printf( "%-6.6s %5.1f %7.2f %11.2f" ,
            kirkbuffer ,
     sprintf( kirkbuffer , "[%d]" , np -> index );
     printf( "%-6.6s %5.1f %7.2f %11.2f" ,
            kirkbuffer ,
-           100 * ( np -> time + np -> childtime ) / printtime ,
-           np -> time / HZ ,
-           np -> childtime / HZ );
+           100 * ( np -> propself + np -> propchild ) / printtime ,
+           np -> propself / hz ,
+           np -> propchild / hz );
     if ( ( np -> ncall + np -> selfcalls ) != 0 ) {
        printf( " %7d" , np -> ncall );
        if ( np -> selfcalls != 0 ) {
     if ( ( np -> ncall + np -> selfcalls ) != 0 ) {
        printf( " %7d" , np -> ncall );
        if ( np -> selfcalls != 0 ) {
@@ -135,7 +152,7 @@ printgprof()
     nltype     *parentp;
 
        /*
     nltype     *parentp;
 
        /*
-        *      Now, sort by time + childtime.
+        *      Now, sort by propself + propchild.
         *      sorting both the regular function names
         *      and cycle headers.
         */
         *      sorting both the regular function names
         *      and cycle headers.
         */
@@ -163,8 +180,8 @@ printgprof()
        if ( zflag == 0 &&
             parentp -> ncall == 0 &&
             parentp -> selfcalls == 0 &&
        if ( zflag == 0 &&
             parentp -> ncall == 0 &&
             parentp -> selfcalls == 0 &&
-            parentp -> time == 0 &&
-            parentp -> childtime == 0 ) {
+            parentp -> propself == 0 &&
+            parentp -> propchild == 0 ) {
            continue;
        }
        if ( ! parentp -> printflag ) {
            continue;
        }
        if ( ! parentp -> printflag ) {
@@ -188,7 +205,7 @@ printgprof()
 }
 
     /*
 }
 
     /*
-     * sort by decreasing total time (time+childtime)
+     * sort by decreasing propagated time
      * if times are equal, but one is a cycle header,
      *         say that's first (e.g. less, i.e. -1).
      * if one's name doesn't have an underscore and the other does,
      * if times are equal, but one is a cycle header,
      *         say that's first (e.g. less, i.e. -1).
      * if one's name doesn't have an underscore and the other does,
@@ -204,8 +221,8 @@ totalcmp( npp1 , npp2 )
     register nltype    *np2 = *npp2;
     double             diff;
 
     register nltype    *np2 = *npp2;
     double             diff;
 
-    diff =    ( np1 -> time + np1 -> childtime )
-           - ( np2 -> time + np2 -> childtime );
+    diff =    ( np1 -> propself + np1 -> propchild )
+           - ( np2 -> propself + np2 -> propchild );
     if ( diff < 0.0 )
            return 1;
     if ( diff > 0.0 )
     if ( diff < 0.0 )
            return 1;
     if ( diff > 0.0 )
@@ -222,6 +239,10 @@ totalcmp( npp1 , npp2 )
        return -1;
     if ( *(np1 -> name) == '_' && *(np2 -> name) != '_' )
        return 1;
        return -1;
     if ( *(np1 -> name) == '_' && *(np2 -> name) != '_' )
        return 1;
+    if ( np1 -> ncall > np2 -> ncall )
+       return -1;
+    if ( np1 -> ncall < np2 -> ncall ) 
+       return 1;
     return strcmp( np1 -> name , np2 -> name );
 }
 
     return strcmp( np1 -> name , np2 -> name );
 }
 
@@ -261,7 +282,7 @@ printparents( childp )
                 */
            printf( "%6.6s %5.5s %7.2f %11.2f %7d/%-7d     " ,
                    "" , "" ,
                 */
            printf( "%6.6s %5.5s %7.2f %11.2f %7d/%-7d     " ,
                    "" , "" ,
-                   arcp -> arc_time / HZ , arcp -> arc_childtime / HZ ,
+                   arcp -> arc_time / hz , arcp -> arc_childtime / hz ,
                    arcp -> arc_count , cycleheadp -> ncall );
            printname( parentp );
            printf( "\n" );
                    arcp -> arc_count , cycleheadp -> ncall );
            printname( parentp );
            printf( "\n" );
@@ -294,7 +315,7 @@ printchildren( parentp )
                 */
            printf( "%6.6s %5.5s %7.2f %11.2f %7d/%-7d     " ,
                    "" , "" ,
                 */
            printf( "%6.6s %5.5s %7.2f %11.2f %7d/%-7d     " ,
                    "" , "" ,
-                   arcp -> arc_time / HZ , arcp -> arc_childtime / HZ ,
+                   arcp -> arc_time / hz , arcp -> arc_childtime / hz ,
                    arcp -> arc_count , childp -> cyclehead -> ncall );
            printname( childp );
            printf( "\n" );
                    arcp -> arc_count , childp -> cyclehead -> ncall );
            printname( childp );
            printf( "\n" );
@@ -312,6 +333,9 @@ printname( selfp )
            if ( debug & DFNDEBUG ) {
                printf( "{%d} " , selfp -> toporder );
            }
            if ( debug & DFNDEBUG ) {
                printf( "{%d} " , selfp -> toporder );
            }
+           if ( debug & PROPDEBUG ) {
+               printf( "%5.2f%% " , selfp -> propfraction );
+           }
 #      endif DEBUG
     }
     if ( selfp -> cycleno != 0 ) {
 #      endif DEBUG
     }
     if ( selfp -> cycleno != 0 ) {
@@ -417,9 +441,9 @@ printcycle( cyclep )
     sprintf( kirkbuffer , "[%d]" , cyclep -> index );
     printf( "%-6.6s %5.1f %7.2f %11.2f %7d" ,
            kirkbuffer ,
     sprintf( kirkbuffer , "[%d]" , cyclep -> index );
     printf( "%-6.6s %5.1f %7.2f %11.2f %7d" ,
            kirkbuffer ,
-           100 * ( cyclep -> time + cyclep -> childtime ) / printtime ,
-           cyclep -> time / HZ ,
-           cyclep -> childtime / HZ ,
+           100 * ( cyclep -> propself + cyclep -> propchild ) / printtime ,
+           cyclep -> propself / hz ,
+           cyclep -> propchild / hz ,
            cyclep -> ncall );
     if ( cyclep -> selfcalls != 0 ) {
        printf( "+%-7d" , cyclep -> selfcalls );
            cyclep -> ncall );
     if ( cyclep -> selfcalls != 0 ) {
        printf( "+%-7d" , cyclep -> selfcalls );
@@ -441,7 +465,7 @@ printmembers( cyclep )
     sortmembers( cyclep );
     for ( memberp = cyclep -> cnext ; memberp ; memberp = memberp -> cnext ) {
        printf( "%6.6s %5.5s %7.2f %11.2f %7d" , 
     sortmembers( cyclep );
     for ( memberp = cyclep -> cnext ; memberp ; memberp = memberp -> cnext ) {
        printf( "%6.6s %5.5s %7.2f %11.2f %7d" , 
-               "" , "" , memberp -> time / HZ , memberp -> childtime / HZ ,
+               "" , "" , memberp -> propself / hz , memberp -> propchild / hz ,
                memberp -> ncall );
        if ( memberp -> selfcalls != 0 ) {
            printf( "+%-7d" , memberp -> selfcalls );
                memberp -> ncall );
        if ( memberp -> selfcalls != 0 ) {
            printf( "+%-7d" , memberp -> selfcalls );
@@ -484,7 +508,7 @@ sortmembers( cyclep )
 }
 
     /*
 }
 
     /*
-     * major sort is on time + childtime,
+     * major sort is on propself + propchild,
      * next is sort on ncalls + selfcalls.
      */
 int
      * next is sort on ncalls + selfcalls.
      */
 int
@@ -492,8 +516,8 @@ membercmp( this , that )
     nltype     *this;
     nltype     *that;
 {
     nltype     *this;
     nltype     *that;
 {
-    double     thistime = this -> time + this -> childtime;
-    double     thattime = that -> time + that -> childtime;
+    double     thistime = this -> propself + this -> propchild;
+    double     thattime = that -> propself + that -> propchild;
     long       thiscalls = this -> ncall + this -> selfcalls;
     long       thatcalls = that -> ncall + that -> selfcalls;
 
     long       thiscalls = this -> ncall + this -> selfcalls;
     long       thatcalls = that -> ncall + that -> selfcalls;
 
@@ -517,7 +541,7 @@ membercmp( this , that )
      * - if one arc is within a cycle, it's less than.
      * - if both arcs are within a cycle, compare arc counts.
      * - if neither arc is within a cycle, compare with
      * - if one arc is within a cycle, it's less than.
      * - if both arcs are within a cycle, compare arc counts.
      * - if neither arc is within a cycle, compare with
-     *         time + childtime as major key
+     *         arc_time + arc_childtime as major key
      *         arc count as minor key
      */
 int
      *         arc count as minor key
      */
 int
@@ -602,14 +626,12 @@ arccmp( thisp , thatp )
 printblurb( blurbname )
     char       *blurbname;
 {
 printblurb( blurbname )
     char       *blurbname;
 {
-    char       pathname[ BUFSIZ ];
     FILE       *blurbfile;
     int                input;
 
     FILE       *blurbfile;
     int                input;
 
-    sprintf( pathname , "%s%s" , BLURBLIB , blurbname );
-    blurbfile = fopen( pathname , "r" );
+    blurbfile = fopen( blurbname , "r" );
     if ( blurbfile == NULL ) {
     if ( blurbfile == NULL ) {
-       perror( pathname );
+       perror( blurbname );
        return;
     }
     while ( ( input = getc( blurbfile ) ) != EOF ) {
        return;
     }
     while ( ( input = getc( blurbfile ) ) != EOF ) {