From 63eff9d9b845dca66ab4dc6bde9960b5edfc249a Mon Sep 17 00:00:00 2001 From: bde Date: Mon, 5 Sep 1994 16:14:54 +0000 Subject: [PATCH] New flag -u to suppress functions whose name does not begin with an underscore. Use it to avoid seeing badsw when profiling the kernel. Print times more accurately (e.g. usec in %8.0f format instead of msec in %8.2f format for averages) if hz >= 10000. This should have no effect now since profhz is only 1024. --- usr.bin/gprof/gprof.1 | 11 +++++++++-- usr.bin/gprof/gprof.c | 9 +++++++-- usr.bin/gprof/printgprof.c | 22 ++++++++++++++++------ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/usr.bin/gprof/gprof.1 b/usr.bin/gprof/gprof.1 index dfb0f21887a5..63ea8722ce58 100644 --- a/usr.bin/gprof/gprof.1 +++ b/usr.bin/gprof/gprof.1 @@ -91,8 +91,8 @@ Second, a flat profile is given, similar to that provided by .Xr prof 1 . This listing gives the total execution times, the call counts, -the time in milleseconds the call spent in the routine itself, and -the time in milleseconds the call spent in the routine itself including +the time in msec or usec the call spent in the routine itself, and +the time in msec or usec the call spent in the routine itself including its descendents. .Pp Finally, an index of the function names is provided. @@ -205,6 +205,13 @@ executions of gprof (probably also with a to accumulate profile data across several runs of an .Pa a.out file. +.It Fl u +Suppresses the printing of functions whose name does not begin with +an underscore. +All relevant information about such functions belongs to the +(non-suppressed) function with the next lowest address. +This is useful for eliminating "functions" that are just labels +inside other functions. .It Fl z Displays routines that have zero usage (as shown by call counts and accumulated time). diff --git a/usr.bin/gprof/gprof.c b/usr.bin/gprof/gprof.c index 5057e3265d37..c1d45b79066e 100644 --- a/usr.bin/gprof/gprof.c +++ b/usr.bin/gprof/gprof.c @@ -51,6 +51,7 @@ char *whoami = "gprof"; char *defaultEs[] = { "mcount" , "__mcleanup" , 0 }; static struct gmonhdr gmonhdr; +static bool uflag; main(argc, argv) int argc; @@ -125,6 +126,9 @@ main(argc, argv) case 's': sflag = TRUE; break; + case 'u': + uflag = TRUE; + break; case 'z': zflag = TRUE; break; @@ -704,8 +708,6 @@ bool funcsymbol( nlistp ) struct nlist *nlistp; { - extern char *strtab; /* string table from a.out */ - extern int aflag; /* if static functions aren't desired */ char *name, c; /* @@ -717,6 +719,7 @@ funcsymbol( nlistp ) return FALSE; } /* + * name must start with an underscore if uflag is set. * can't have any `funny' characters in name, * where `funny' includes `.', .o file names * and `$', pascal labels. @@ -724,6 +727,8 @@ funcsymbol( nlistp ) * perhaps we should just drop this code entirely... */ name = strtab + nlistp -> n_un.n_strx; + if ( uflag && *name != '_' ) + return FALSE; #ifdef sparc if ( *name == '.' ) { char *p = name + 1; diff --git a/usr.bin/gprof/printgprof.c b/usr.bin/gprof/printgprof.c index 5ede772b11a9..884c368a64d2 100644 --- a/usr.bin/gprof/printgprof.c +++ b/usr.bin/gprof/printgprof.c @@ -110,7 +110,8 @@ flatprofheader() "% " , "cumulative" , "self " , "" , "self " , "total " , "" ); printf( "%5.5s %10.10s %8.8s %8.8s %8.8s %8.8s %-8.8s\n" , "time" , "seconds " , "seconds" , "calls" , - "ms/call" , "ms/call" , "name" ); + hz >= 10000 ? "us/call" : "ms/call" , + hz >= 10000 ? "us/call" : "ms/call" , "name" ); } flatprofline( np ) @@ -121,12 +122,21 @@ flatprofline( np ) return; } actime += np -> time; - printf( "%5.1f %10.2f %8.2f" , - 100 * np -> time / totime , actime / hz , np -> time / hz ); + if (hz >= 10000) + printf( "%5.1f %10.3f %8.3f" , + 100 * np -> time / totime , actime / hz , np -> time / hz ); + else + printf( "%5.1f %10.2f %8.2f" , + 100 * np -> time / totime , actime / hz , np -> time / hz ); if ( np -> ncall != 0 ) { - printf( " %8d %8.2f %8.2f " , np -> ncall , - 1000 * np -> time / hz / np -> ncall , - 1000 * ( np -> time + np -> childtime ) / hz / np -> ncall ); + if (hz >= 10000) + printf( " %8d %8.0f %8.0f " , np -> ncall , + 1e6 * np -> time / hz / np -> ncall , + 1e6 * ( np -> time + np -> childtime ) / hz / np -> ncall ); + else + printf( " %8d %8.2f %8.2f " , np -> ncall , + 1000 * np -> time / hz / np -> ncall , + 1000 * ( np -> time + np -> childtime ) / hz / np -> ncall ); } else { printf( " %8.8s %8.8s %8.8s " , "" , "" , "" ); }