diff options
author | bde <bde@FreeBSD.org> | 2002-03-06 09:47:36 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 2002-03-06 09:47:36 +0000 |
commit | 8de8391e81f5d358ab05e1b726e30fb59a1706fb (patch) | |
tree | 3a23420ba9009cdae28cee5a62bd11968db28fde /usr.bin/gprof | |
parent | 77922c96033bd5bc20628ac399b83499bf13ca95 (diff) | |
download | FreeBSD-src-8de8391e81f5d358ab05e1b726e30fb59a1706fb.zip FreeBSD-src-8de8391e81f5d358ab05e1b726e30fb59a1706fb.tar.gz |
Fixed some misspellings of 2 as sizeof(UNIT) so that they won't break
things when sizeof(UNIT) becomes a runtime parameter. The relevant 2
is the one in profil(2)'s scaling of pc's to bucket numbers:
bucket = (pc - offset) / 2 * profil_scale / 65536
gprof(1) must duplicate this scaling, bug for bug compatibly, so it
must first do an integer division by 2 although this mainly makes
scales larger than 65536 useless. sizeof(UNIT) was already wrong in
gprof4, but there were no problems because the fake profil scale is a
multiple of 2.
There are also some rounding bugs in the scaling, but these are only
problems if profil(2) is used directly to create unusual (and not
useful) scales.
Diffstat (limited to 'usr.bin/gprof')
-rw-r--r-- | usr.bin/gprof/gprof.c | 20 | ||||
-rw-r--r-- | usr.bin/gprof/gprof.h | 8 | ||||
-rw-r--r-- | usr.bin/gprof/printgprof.c | 4 |
3 files changed, 19 insertions, 13 deletions
diff --git a/usr.bin/gprof/gprof.c b/usr.bin/gprof/gprof.c index 1d43fe6..8d529cb 100644 --- a/usr.bin/gprof/gprof.c +++ b/usr.bin/gprof/gprof.c @@ -48,8 +48,6 @@ static const char rcsid[] = #include <err.h> #include "gprof.h" -#define UNITS_TO_CODE (OFFSET_OF_CODE / sizeof(UNIT)) - static int valcmp(const void *, const void *); @@ -306,8 +304,8 @@ openpfile(filename) } s_lowpc = (unsigned long) gmonhdr.lpc; s_highpc = (unsigned long) gmonhdr.hpc; - lowpc = (unsigned long)gmonhdr.lpc / sizeof(UNIT); - highpc = (unsigned long)gmonhdr.hpc / sizeof(UNIT); + lowpc = (unsigned long)gmonhdr.lpc / HISTORICAL_SCALE_2; + highpc = (unsigned long)gmonhdr.hpc / HISTORICAL_SCALE_2; sampbytes = gmonhdr.ncnt - size; nsamples = sampbytes / sizeof (UNIT); # ifdef DEBUG @@ -525,8 +523,8 @@ asgnsamples() # ifdef DEBUG if (debug & SAMPLEDEBUG) { printf("[asgnsamples] (0x%lx->0x%lx-0x%lx) %s gets %f ticks %lu overlap\n", - nl[j].value/sizeof(UNIT), svalue0, svalue1, - nl[j].name, + nl[j].value / HISTORICAL_SCALE_2, + svalue0, svalue1, nl[j].name, overlap * time / scale, overlap); } # endif DEBUG @@ -573,17 +571,19 @@ alignentries() unsigned long bucket_of_code; for (nlp = nl; nlp < npe; nlp++) { - nlp -> svalue = nlp -> value / sizeof(UNIT); + nlp -> svalue = nlp -> value / HISTORICAL_SCALE_2; bucket_of_entry = (nlp->svalue - lowpc) / scale; - bucket_of_code = (nlp->svalue + UNITS_TO_CODE - lowpc) / scale; + bucket_of_code = (nlp->svalue + OFFSET_OF_CODE / HISTORICAL_SCALE_2 - + lowpc) / scale; if (bucket_of_entry < bucket_of_code) { # ifdef DEBUG if (debug & SAMPLEDEBUG) { printf("[alignentries] pushing svalue 0x%lx to 0x%lx\n", - nlp->svalue, nlp->svalue + UNITS_TO_CODE); + nlp->svalue, + nlp->svalue + OFFSET_OF_CODE / HISTORICAL_SCALE_2); } # endif DEBUG - nlp->svalue += UNITS_TO_CODE; + nlp->svalue += OFFSET_OF_CODE / HISTORICAL_SCALE_2; } } } diff --git a/usr.bin/gprof/gprof.h b/usr.bin/gprof/gprof.h index 4d2b949..c37c00e 100644 --- a/usr.bin/gprof/gprof.h +++ b/usr.bin/gprof/gprof.h @@ -78,6 +78,13 @@ typedef int bool; #define TRUE 1 /* + * Historical scale factor in profil(2)'s algorithm for converting + * pc addresses to bucket numbers. This now just complicates the + * scaling and makes bucket:pc densities of more than 1/2 useless. + */ +#define HISTORICAL_SCALE_2 2 + + /* * ticks per second */ long hz; @@ -87,7 +94,6 @@ typedef int64_t UNIT; #else typedef u_short UNIT; /* unit of profiling */ #endif -#define UNITS_TO_CODE (OFFSET_OF_CODE / sizeof(UNIT)) char *a_outname; #define A_OUTNAME "a.out" diff --git a/usr.bin/gprof/printgprof.c b/usr.bin/gprof/printgprof.c index 945ff8d..80698cf 100644 --- a/usr.bin/gprof/printgprof.c +++ b/usr.bin/gprof/printgprof.c @@ -100,7 +100,7 @@ flatprofheader() printblurb( _PATH_FLAT_BLURB ); } printf( "\ngranularity: each sample hit covers %g byte(s)" , - scale * sizeof(UNIT) ); + scale * HISTORICAL_SCALE_2 ); if ( totime > 0.0 ) { printf( " for %.2f%% of %.2f seconds\n\n" , 100.0/totime , totime / hz ); @@ -161,7 +161,7 @@ gprofheader() printblurb( _PATH_CALLG_BLURB ); } printf( "\ngranularity: each sample hit covers %g byte(s)" , - scale * sizeof(UNIT) ); + scale * HISTORICAL_SCALE_2 ); if ( printtime > 0.0 ) { printf( " for %.2f%% of %.2f seconds\n\n" , 100.0/printtime , printtime / hz ); |