fixed a bug in multi-subscript calculation
[unix-history] / usr / src / usr.bin / gprof / gprof.c
index f712729..87b8407 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-    static     char *sccsid = "@(#)gprof.c     1.13 (Berkeley) %G%";
+    static     char *sccsid = "@(#)gprof.c     1.19 (Berkeley) %G%";
 #endif lint
 
 #include "gprof.h"
 #endif lint
 
 #include "gprof.h"
@@ -93,6 +93,10 @@ main(argc, argv)
        eflag = TRUE;
        addlist( elist , *sp );
     }
        eflag = TRUE;
        addlist( elist , *sp );
     }
+       /*
+        *      how long is a clock tick?
+        */
+    hz = hertz();
        /*
         *      get information about a.out file.
         */
        /*
         *      get information about a.out file.
         */
@@ -327,10 +331,22 @@ openpfile(filename)
     h = tmp;
     s_lowpc = (unsigned long) h.lowpc;
     s_highpc = (unsigned long) h.highpc;
     h = tmp;
     s_lowpc = (unsigned long) h.lowpc;
     s_highpc = (unsigned long) h.highpc;
-    lowpc = h.lowpc - (UNIT *)0;
-    highpc = h.highpc - (UNIT *)0;
+    lowpc = (unsigned long)h.lowpc / sizeof(UNIT);
+    highpc = (unsigned long)h.highpc / sizeof(UNIT);
     sampbytes = h.ncnt - sizeof(struct hdr);
     nsamples = sampbytes / sizeof (unsigned UNIT);
     sampbytes = h.ncnt - sizeof(struct hdr);
     nsamples = sampbytes / sizeof (unsigned UNIT);
+#   ifdef DEBUG
+       if ( debug & SAMPLEDEBUG ) {
+           printf( "[openpfile] hdr.lowpc 0x%x hdr.highpc 0x%x hdr.ncnt %d\n",
+               h.lowpc , h.highpc , h.ncnt );
+           printf( "[openpfile]   s_lowpc 0x%x   s_highpc 0x%x\n" ,
+               s_lowpc , s_highpc );
+           printf( "[openpfile]     lowpc 0x%x     highpc 0x%x\n" ,
+               lowpc , highpc );
+           printf( "[openpfile] sampbytes %d nsamples %d\n" ,
+               sampbytes , nsamples );
+       }
+#   endif DEBUG
     return(pfile);
 }
 
     return(pfile);
 }
 
@@ -460,7 +476,7 @@ asgnsamples()
     /* read samples and assign to namelist symbols */
     scale = highpc - lowpc;
     scale /= nsamples;
     /* read samples and assign to namelist symbols */
     scale = highpc - lowpc;
     scale /= nsamples;
-    for (i=0; i < nsamples; i++) {
+    for (i = 0, j = 1; i < nsamples; i++) {
        ccnt = samples[i];
        if (ccnt == 0)
                continue;
        ccnt = samples[i];
        if (ccnt == 0)
                continue;
@@ -474,7 +490,7 @@ asgnsamples()
            }
 #      endif DEBUG
        totime += time;
            }
 #      endif DEBUG
        totime += time;
-       for (j=0; j<nname; j++) {
+       for (j = j - 1; j < nname; j++) {
            svalue0 = nl[j].value / sizeof(UNIT);
            svalue1 = nl[j+1].value / sizeof(UNIT);
            if (pch < svalue0)
            svalue0 = nl[j].value / sizeof(UNIT);
            svalue1 = nl[j+1].value / sizeof(UNIT);
            if (pch < svalue0)
@@ -499,10 +515,6 @@ asgnsamples()
            printf( "[asgnsamples] totime %f\n" , totime );
        }
 #   endif DEBUG
            printf( "[asgnsamples] totime %f\n" , totime );
        }
 #   endif DEBUG
-    if (totime==0.0) {
-       fprintf( stderr , "No time accumulated\n" );
-       totime=1.0;
-    }
 }
 
 
 }