From 97fa9b77399b799457a0e59000391966367c07d4 Mon Sep 17 00:00:00 2001 From: Philippe Charnier Date: Wed, 16 Oct 2002 13:50:09 +0000 Subject: [PATCH] Remove done() which was just exit() so use of warn()/err() can be made. Abort on allocation failure instead of displaying a warning and deferencing NULL pointer after. Spelling. Add prototypes. Add list of option in synopsis section of man page, -d is not referenced because available as a compile option. It should be made a runtime option btw. --- usr.bin/gprof/amd64.c | 4 ++ usr.bin/gprof/aout.c | 42 +++++++------------ usr.bin/gprof/arcs.c | 51 +++++++++++++--------- usr.bin/gprof/dfn.c | 29 ++++++------- usr.bin/gprof/elf.c | 6 +-- usr.bin/gprof/gprof.1 | 42 +++++++++++-------- usr.bin/gprof/gprof.c | 81 ++++++++++++++--------------------- usr.bin/gprof/gprof.h | 86 ++++++++++++++++++-------------------- usr.bin/gprof/hertz.c | 5 +++ usr.bin/gprof/hp300.c | 3 ++ usr.bin/gprof/i386.c | 4 ++ usr.bin/gprof/lookup.c | 7 ++-- usr.bin/gprof/mips.c | 5 +++ usr.bin/gprof/pathnames.h | 1 + usr.bin/gprof/printgprof.c | 38 ++++++++++++----- usr.bin/gprof/printlist.c | 14 +++---- usr.bin/gprof/sparc.c | 5 +++ usr.bin/gprof/sparc64.c | 3 +- usr.bin/gprof/tahoe.c | 5 +++ usr.bin/gprof/vax.c | 5 +++ 20 files changed, 238 insertions(+), 198 deletions(-) diff --git a/usr.bin/gprof/amd64.c b/usr.bin/gprof/amd64.c index 6a474086a312..c112763eafe3 100644 --- a/usr.bin/gprof/amd64.c +++ b/usr.bin/gprof/amd64.c @@ -1,8 +1,12 @@ +#include +__FBSDID("$FreeBSD$"); + #include "gprof.h" /* * gprof -c isn't currently supported... */ +void findcall( parentp , p_lowpc , p_highpc ) nltype *parentp; unsigned long p_lowpc; diff --git a/usr.bin/gprof/aout.c b/usr.bin/gprof/aout.c index 3521359a4189..6daa80336c2c 100644 --- a/usr.bin/gprof/aout.c +++ b/usr.bin/gprof/aout.c @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)gprof.c 8.1 (Berkeley) 6/6/93"; __FBSDID("$FreeBSD$"); #include +#include #include "gprof.h" @@ -71,10 +72,8 @@ aout_getnfile(const char *filename, char ***defaultEs) int valcmp(); nfile = fopen( filename ,"r"); - if (nfile == NULL) { - perror( filename ); - done(); - } + if (nfile == NULL) + err( 1 , "%s", filename ); fread(&xbuf, 1, sizeof(xbuf), nfile); if (N_BADMAG(xbuf)) { fclose(nfile); @@ -102,19 +101,13 @@ getstrtab(FILE *nfile, const char *filename) { fseek(nfile, (long)(N_SYMOFF(xbuf) + xbuf.a_syms), 0); - if (fread(&ssiz, sizeof (ssiz), 1, nfile) == 0) { - warnx("%s: no string table (old format?)" , filename ); - done(); - } + if (fread(&ssiz, sizeof (ssiz), 1, nfile) == 0) + errx( 1 , "%s: no string table (old format?)" , filename ); strtab = calloc(ssiz, 1); - if (strtab == NULL) { - warnx("%s: no room for %d bytes of string table", filename , ssiz); - done(); - } - if (fread(strtab+sizeof(ssiz), ssiz-sizeof(ssiz), 1, nfile) != 1) { - warnx("%s: error reading string table", filename ); - done(); - } + if (strtab == NULL) + errx( 1 , "%s: no room for %ld bytes of string table", filename , ssiz); + if (fread(strtab+sizeof(ssiz), ssiz-sizeof(ssiz), 1, nfile) != 1) + errx( 1 , "%s: error reading string table" , filename ); } /* @@ -137,16 +130,13 @@ getsymtab(FILE *nfile, const char *filename) } nname++; } - if (nname == 0) { - warnx("%s: no symbols", filename ); - done(); - } + if (nname == 0) + errx( 1 , "%s: no symbols" , filename ); askfor = nname + 1; nl = (nltype *) calloc( askfor , sizeof(nltype) ); - if (nl == 0) { - warnx("no room for %d bytes of symbol table", askfor * sizeof(nltype) ); - done(); - } + if (nl == 0) + errx( 1 , "no room for %d bytes of symbol table" , + askfor * sizeof(nltype) ); /* pass2 - read symbols */ fseek(nfile, (long)N_SYMOFF(xbuf), 0); @@ -189,7 +179,7 @@ gettextspace(FILE *nfile) } textspace = (u_char *) malloc( xbuf.a_text ); if ( textspace == 0 ) { - warnx("ran out room for %d bytes of text space: can't do -c" , + warnx("no room for %lu bytes of text space: can't do -c" , xbuf.a_text ); return; } @@ -235,7 +225,7 @@ funcsymbol(struct nlist *nlistp) return TRUE; } #endif - while ( c = *name++ ) { + while ( (c = *name++) ) { if ( c == '.' ) { return FALSE; } diff --git a/usr.bin/gprof/arcs.c b/usr.bin/gprof/arcs.c index b3bdfbabf333..262e6bd9f70f 100644 --- a/usr.bin/gprof/arcs.c +++ b/usr.bin/gprof/arcs.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. */ -#ifndef lint #if 0 +#ifndef lint static char sccsid[] = "@(#)arcs.c 8.1 (Berkeley) 6/6/93"; -#endif #endif /* not lint */ +#endif + #include __FBSDID("$FreeBSD$"); @@ -52,6 +53,7 @@ int oldcycle; /* * add (or just increment) an arc */ +void addarc( parentp , childp , count ) nltype *parentp; nltype *childp; @@ -80,6 +82,8 @@ addarc( parentp , childp , count ) return; } arcp = (arctype *)calloc( 1 , sizeof *arcp ); + if (arcp == NULL) + errx( 1 , "malloc failed" ); arcp -> arc_parentp = parentp; arcp -> arc_childp = childp; arcp -> arc_count = count; @@ -105,6 +109,7 @@ addarc( parentp , childp , count ) */ nltype **topsortnlp; +int topcmp( npp1 , npp2 ) nltype **npp1; nltype **npp2; @@ -202,9 +207,8 @@ doarcs() * Sort the symbol table in reverse topological order */ topsortnlp = (nltype **) calloc( nname , sizeof(nltype *) ); - if ( topsortnlp == (nltype **) 0 ) { - fprintf( stderr , "[doarcs] ran out of memory for topo sorting\n" ); - } + if ( topsortnlp == (nltype **) 0 ) + errx( 1 , "[doarcs] ran out of memory for topo sorting" ); for ( index = 0 ; index < nname ; index += 1 ) { topsortnlp[ index ] = &nl[ index ]; } @@ -230,7 +234,7 @@ doarcs() doflags(); /* * starting from the topological bottom, - * propogate children times up to parents. + * propagate children times up to parents. */ dotime(); /* @@ -239,9 +243,8 @@ doarcs() * and cycle headers. */ timesortnlp = (nltype **) calloc( nname + ncycle , sizeof(nltype *) ); - if ( timesortnlp == (nltype **) 0 ) { - warnx("ran out of memory for sorting"); - } + if ( timesortnlp == (nltype **) 0 ) + errx( 1 , "ran out of memory for sorting" ); for ( index = 0 ; index < nname ; index++ ) { timesortnlp[index] = &nl[index]; } @@ -255,6 +258,7 @@ doarcs() return( timesortnlp ); } +void dotime() { int index; @@ -265,6 +269,7 @@ dotime() } } +void timepropagate( parentp ) nltype *parentp; { @@ -353,6 +358,7 @@ timepropagate( parentp ) } } +void cyclelink() { register nltype *nlp; @@ -362,7 +368,7 @@ cyclelink() arctype *arcp; /* - * Count the number of cycles, and initialze the cycle lists + * Count the number of cycles, and initialize the cycle lists */ ncycle = 0; for ( nlp = nl ; nlp < npe ; nlp++ ) { @@ -378,11 +384,9 @@ cyclelink() * i.e. it is origin 1, not origin 0. */ cyclenl = (nltype *) calloc( ncycle + 1 , sizeof( nltype ) ); - if ( cyclenl == 0 ) { - warnx("no room for %d bytes of cycle headers", + if ( cyclenl == 0 ) + errx( 1 , "no room for %d bytes of cycle headers" , ( ncycle + 1 ) * sizeof( nltype ) ); - done(); - } /* * now link cycles to true cycleheads, * number them, accumulate the data for the cycle @@ -447,6 +451,7 @@ cyclelink() /* * analyze cycles to determine breakup */ +bool cycleanalyze() { arctype **cyclestack; @@ -482,11 +487,9 @@ cycleanalyze() continue; done = FALSE; cyclestack = (arctype **) calloc( size + 1 , sizeof( arctype *) ); - if ( cyclestack == 0 ) { - warnx("no room for %d bytes of cycle stack", + if ( cyclestack == 0 ) + errx( 1, "no room for %d bytes of cycle stack" , ( size + 1 ) * sizeof( arctype * ) ); - return; - } # ifdef DEBUG if ( debug & BREAKCYCLE ) { printf( "[cycleanalyze] starting cycle %d of %d, size %d\n" , @@ -524,6 +527,7 @@ cycleanalyze() return( done ); } +bool descend( node , stkstart , stkp ) nltype *node; arctype **stkstart; @@ -555,8 +559,10 @@ descend( node , stkstart , stkp ) if ( ret == FALSE ) return( FALSE ); } + return( TRUE ); } +bool addcycle( stkstart , stkend ) arctype **stkstart; arctype **stkend; @@ -600,7 +606,7 @@ addcycle( stkstart , stkend ) clp = (cltype *) calloc( 1 , sizeof ( cltype ) + ( size - 1 ) * sizeof( arctype * ) ); if ( clp == 0 ) { - warnx("no room for %d bytes of subcycle storage", + warnx( "no room for %d bytes of subcycle storage" , sizeof ( cltype ) + ( size - 1 ) * sizeof( arctype * ) ); return( FALSE ); } @@ -632,6 +638,7 @@ addcycle( stkstart , stkend ) return( TRUE ); } +void compresslist() { cltype *clp; @@ -747,6 +754,7 @@ compresslist() } #ifdef DEBUG +void printsubcycle( clp ) cltype *clp; { @@ -762,6 +770,7 @@ printsubcycle( clp ) } #endif /* DEBUG */ +void cycletime() { int cycle; @@ -791,6 +800,7 @@ cycletime() * propfraction as the sum of fractional parents' propfractions * and while we're here, sum time for functions. */ +void doflags() { int index; @@ -856,7 +866,7 @@ doflags() /* * it has parents to pass time to, * but maybe someone wants to shut it up - * by puttting it on -E list. (but favor -F over -E) + * by putting it on -E list. (but favor -F over -E) */ if ( !onlist( Flist , childp -> name ) && onlist( Elist , childp -> name ) ) { @@ -885,6 +895,7 @@ doflags() * print flag of the child (cycle) appropriately. * similarly, deal with propagation fractions from parents. */ +void inheritflags( childp ) nltype *childp; { diff --git a/usr.bin/gprof/dfn.c b/usr.bin/gprof/dfn.c index 9d2a08ae265e..0e23a87a22bf 100644 --- a/usr.bin/gprof/dfn.c +++ b/usr.bin/gprof/dfn.c @@ -31,17 +31,16 @@ * SUCH DAMAGE. */ -#ifndef lint #if 0 +#ifndef lint static char sccsid[] = "@(#)dfn.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ +#endif + #include __FBSDID("$FreeBSD$"); -#include +#include #include "gprof.h" #define DFN_DEPTH 100 @@ -56,6 +55,7 @@ int dfn_depth; int dfn_counter; +void dfn_init() { @@ -66,6 +66,7 @@ dfn_init() /* * given this parent, depth first number its children. */ +void dfn( parentp ) nltype *parentp; { @@ -79,7 +80,7 @@ dfn( parentp ) } # endif /* DEBUG */ /* - * if we're already numbered, no need to look any furthur. + * if we're already numbered, no need to look any further. */ if ( dfn_numbered( parentp ) ) { return; @@ -112,15 +113,14 @@ dfn( parentp ) /* * push a parent onto the stack and mark it busy */ +void dfn_pre_visit( parentp ) nltype *parentp; { dfn_depth += 1; - if ( dfn_depth >= DFN_DEPTH ) { - fprintf( stderr , "[dfn] out of my depth (dfn_stack overflow)\n" ); - exit( 1 ); - } + if ( dfn_depth >= DFN_DEPTH ) + errx( 1 , "[dfn] out of my depth (dfn_stack overflow)" ); dfn_stack[ dfn_depth ].nlentryp = parentp; dfn_stack[ dfn_depth ].cycletop = dfn_depth; parentp -> toporder = DFN_BUSY; @@ -161,6 +161,7 @@ dfn_busy( childp ) /* * MISSING: an explanation */ +void dfn_findcycle( childp ) nltype *childp; { @@ -179,10 +180,8 @@ dfn_findcycle( childp ) break; } } - if ( cycletop <= 0 ) { - fprintf( stderr , "[dfn_findcycle] couldn't find head of cycle\n" ); - exit( 1 ); - } + if ( cycletop <= 0 ) + errx( 1 , "[dfn_findcycle] couldn't find head of cycle" ); # ifdef DEBUG if ( debug & DFNDEBUG ) { printf( "[dfn_findcycle] dfn_depth %d cycletop %d " , @@ -271,6 +270,7 @@ dfn_findcycle( childp ) * deal with self-cycles * for lint: ARGSUSED */ +void dfn_self_cycle( parentp ) nltype *parentp; { @@ -292,6 +292,7 @@ dfn_self_cycle( parentp ) * [MISSING: an explanation] * and pop it off the stack */ +void dfn_post_visit( parentp ) nltype *parentp; { diff --git a/usr.bin/gprof/elf.c b/usr.bin/gprof/elf.c index 65cc87315793..b0af431dc5a1 100644 --- a/usr.bin/gprof/elf.c +++ b/usr.bin/gprof/elf.c @@ -81,10 +81,10 @@ elf_getnfile(const char *filename, char ***defaultEs) return -1; } if (fstat(fd, &s) == -1) - err(1, "Cannot fstat %s", filename); + err(1, "cannot fstat %s", filename); if ((mapbase = mmap(0, s.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) - err(1, "Cannot mmap %s", filename); + err(1, "cannot mmap %s", filename); close(fd); base = (const char *)mapbase; @@ -111,7 +111,7 @@ elf_getnfile(const char *filename, char ***defaultEs) /* Allocate memory for them, plus a terminating entry. */ if ((nl = (nltype *)calloc(nname + 1, sizeof(nltype))) == NULL) - errx(1, "Insufficient memory for symbol table"); + errx(1, "insufficient memory for symbol table"); /* Read them in. */ npe = nl; diff --git a/usr.bin/gprof/gprof.1 b/usr.bin/gprof/gprof.1 index ac3e155731bd..72811955efab 100644 --- a/usr.bin/gprof/gprof.1 +++ b/usr.bin/gprof/gprof.1 @@ -40,7 +40,13 @@ .Nd display call graph profile data .Sh SYNOPSIS .Nm -.Op options +.Op Fl abcKlLsuz +.Op Fl C Ar count +.Op Fl e Ar name +.Op Fl E Ar name +.Op Fl f Ar name +.Op Fl F Ar name +.Op Fl k Ar fromname Ar toname .Op Ar a.out Op Ar a.out.gmon ... .Sh DESCRIPTION The @@ -91,11 +97,11 @@ Cycles are discovered, and calls into a cycle are made to share the time of the cycle. The first listing shows the functions sorted according to the time they represent -including the time of their call graph descendents. +including the time of their call graph descendants. Below each function entry is shown its (direct) call graph children, and how their times are propagated to this function. A similar display above the function shows how this function's time and the -time of its descendents is propagated to its (direct) call graph parents. +time of its descendants is propagated to its (direct) call graph parents. .Pp Cycles are also shown, with an entry for the cycle as a whole and a listing of the members of the cycle and their contributions to the @@ -107,21 +113,21 @@ similar to that provided by This listing gives the total execution times, the call counts, 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. +its descendants. .Pp Finally, an index of the function names is provided. .Pp The following options are available: -.Bl -tag -width Fl +.Bl -tag -width indent .It Fl a -Suppresses the printing of statically declared functions. +Suppress the printing of statically declared functions. If this option is given, all relevant information about the static function (e.g., time samples, calls to other functions, calls from other functions) belongs to the function loaded just before the static function in the .Pa a.out file. .It Fl b -Suppresses the printing of a description of each field in the profile. +Suppress the printing of a description of each field in the profile. .It Fl c The static call graph of the program is discovered by a heuristic that examines the text space of the object file. @@ -137,7 +143,7 @@ so using this option may cause .Nm to run for a very long time. .It Fl e Ar name -Suppresses the printing of the graph profile entry for routine +Suppress the printing of the graph profile entry for routine .Ar name and all its descendants (unless they have other ancestors that aren't suppressed). @@ -150,7 +156,7 @@ may be given with each .Fl e option. .It Fl E Ar name -Suppresses the printing of the graph profile entry for routine +Suppress the printing of the graph profile entry for routine .Ar name (and its descendants) as .Fl e , @@ -164,7 +170,7 @@ above, and also excludes the time spent in .Ar mcleanup is the default.) .It Fl f Ar name -Prints the graph profile entry of only the specified routine +Print the graph profile entry of only the specified routine .Ar name and its descendants. More than one @@ -176,7 +182,7 @@ may be given with each .Fl f option. .It Fl F Ar name -Prints the graph profile entry of only the routine +Print the graph profile entry of only the routine .Ar name and its descendants (as .Fl f , @@ -221,9 +227,9 @@ argument to be ignored, and allows for symbols in .Xr kld 4 modules to be used. .It Fl l -Suppresses the printing of the call-graph profile. +Suppress the printing of the call-graph profile. .It Fl L -Suppresses the printing of the flat profile. +Suppress the printing of the flat profile. .It Fl s A profile file .Pa gmon.sum @@ -236,7 +242,7 @@ to accumulate profile data across several runs of an .Pa a.out file. .It Fl u -Suppresses the printing of functions whose names are not visible to +Suppress the printing of functions whose names are not visible to C programs. For the ELF object format, this means names that contain the .Ql .\& @@ -249,7 +255,7 @@ All relevant information about such functions belongs to the 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 +Display routines that have zero usage (as shown by call counts and accumulated time). This is useful with the .Fl c @@ -258,11 +264,11 @@ option for discovering which routines were never called. .Sh FILES .Bl -tag -width a.out.gmon -compact .It Pa a.out -The namelist and text space. +the namelist and text space .It Pa a.out.gmon -Dynamic call graph and profile. +dynamic call graph and profile .It Pa gmon.sum -Summarized dynamic call graph and profile. +summarized dynamic call graph and profile .El .Sh SEE ALSO .Xr cc 1 , diff --git a/usr.bin/gprof/gprof.c b/usr.bin/gprof/gprof.c index 745da7641adb..f0e0bce0478f 100644 --- a/usr.bin/gprof/gprof.c +++ b/usr.bin/gprof/gprof.c @@ -37,11 +37,12 @@ static const char copyright[] = The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ -#ifndef lint #if 0 +#ifndef lint static char sccsid[] = "@(#)gprof.c 8.1 (Berkeley) 6/6/93"; -#endif #endif /* not lint */ +#endif + #include __FBSDID("$FreeBSD$"); @@ -57,6 +58,7 @@ static struct gmonhdr gmonhdr; static int lflag; static int Lflag; +int main(argc, argv) int argc; char **argv; @@ -130,15 +132,15 @@ main(argc, argv) case 'K': Kflag = TRUE; break; - case 'l': + case 'l': lflag = 1; Lflag = 0; break; - case 'L': + case 'L': Lflag = 1; lflag = 0; break; - case 's': + case 's': sflag = TRUE; break; case 'u': @@ -231,7 +233,7 @@ main(argc, argv) * print the index */ printindex(); - done(); + exit(0); } /* @@ -239,6 +241,7 @@ main(argc, argv) * an array of sampling hits within pc ranges, * and the arcs. */ +void getpfile(filename) char *filename; { @@ -276,16 +279,12 @@ openpfile(filename) int size; int rate; - if((pfile = fopen(filename, "r")) == NULL) { - perror(filename); - done(); - } + if((pfile = fopen(filename, "r")) == NULL) + err(1, "%s", filename); fread(&tmp, sizeof(struct gmonhdr), 1, pfile); if ( s_highpc != 0 && ( tmp.lpc != gmonhdr.lpc || - tmp.hpc != gmonhdr.hpc || tmp.ncnt != gmonhdr.ncnt ) ) { - warnx("%s: incompatible with first gmon file", filename); - done(); - } + tmp.hpc != gmonhdr.hpc || tmp.ncnt != gmonhdr.ncnt ) ) + errx(1, "%s: incompatible with first gmon file", filename); gmonhdr = tmp; if ( gmonhdr.version == GMONVERSION ) { rate = gmonhdr.profrate; @@ -298,12 +297,9 @@ openpfile(filename) } if (hz == 0) { hz = rate; - } else if (hz != rate) { - fprintf(stderr, - "%s: profile clock rate (%d) %s (%ld) in first gmon file\n", + } else if (hz != rate) + errx(0, "%s: profile clock rate (%d) %s (%ld) in first gmon file", filename, rate, "incompatible with clock rate", hz); - done(); - } if ( gmonhdr.histcounter_type == 0 ) { /* Historical case. The type was u_short (2 bytes in practice). */ histcounter_type = 16; @@ -334,6 +330,7 @@ openpfile(filename) return(pfile); } +void tally( rawp ) struct rawarc *rawp; { @@ -362,6 +359,7 @@ tally( rawp ) /* * dump out the gmon.sum file */ +void dumpsum( sumfile ) char *sumfile; { @@ -370,24 +368,18 @@ dumpsum( sumfile ) struct rawarc arc; FILE *sfile; - if ( ( sfile = fopen ( sumfile , "w" ) ) == NULL ) { - perror( sumfile ); - done(); - } + if ( ( sfile = fopen ( sumfile , "w" ) ) == NULL ) + err( 1 , "%s" , sumfile ); /* * dump the header; use the last header read in */ - if ( fwrite( &gmonhdr , sizeof gmonhdr , 1 , sfile ) != 1 ) { - perror( sumfile ); - done(); - } + if ( fwrite( &gmonhdr , sizeof gmonhdr , 1 , sfile ) != 1 ) + err( 1 , "%s" , sumfile ); /* * dump the samples */ - if (fwrite(samples, histcounter_size, nsamples, sfile) != nsamples) { - perror( sumfile ); - done(); - } + if (fwrite(samples, histcounter_size, nsamples, sfile) != nsamples) + err( 1 , "%s" , sumfile ); /* * dump the normalized raw arc information */ @@ -396,10 +388,8 @@ dumpsum( sumfile ) 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(); - } + if ( fwrite ( &arc , sizeof arc , 1 , sfile ) != 1 ) + err( 1 , "%s" , sumfile ); # ifdef DEBUG if ( debug & SAMPLEDEBUG ) { printf( "[dumpsum] frompc 0x%lx selfpc 0x%lx count %ld\n" , @@ -428,6 +418,7 @@ valcmp(v1, v2) return EQUALTO; } +void readsamples(pfile) FILE *pfile; { @@ -436,10 +427,8 @@ readsamples(pfile) if (samples == 0) { samples = (double *) calloc(nsamples, sizeof(double)); - if (samples == 0) { - warnx("no room for %d sample pc's", nsamples); - done(); - } + if (samples == 0) + errx(0, "no room for %d sample pc's", nsamples); } for (i = 0; i < nsamples; i++) { fread(&sample, histcounter_size, 1, pfile); @@ -474,10 +463,8 @@ readsamples(pfile) err(1, "unsupported histogram counter type %d", histcounter_type); } } - if (i != nsamples) { - warnx("unexpected EOF after reading %d/%d samples", --i , nsamples ); - done(); - } + if (i != nsamples) + errx(1, "unexpected EOF after reading %d/%d samples", --i , nsamples ); } /* @@ -512,6 +499,7 @@ readsamples(pfile) * only one sample for every four bytes of text space and never * have any overlap (the two end cases, above). */ +void asgnsamples() { register int j; @@ -601,6 +589,7 @@ max(a, b) * if it turns out that the entry point is in one bucket and the code * for a routine is in the next bucket. */ +void alignentries() { register struct nl *nlp; @@ -624,9 +613,3 @@ alignentries() } } } - -done() -{ - - exit(0); -} diff --git a/usr.bin/gprof/gprof.h b/usr.bin/gprof/gprof.h index 7214abff5c41..e6d1f4620756 100644 --- a/usr.bin/gprof/gprof.h +++ b/usr.bin/gprof/gprof.h @@ -131,7 +131,7 @@ typedef struct arcstruct arctype; /* * The symbol table; * for each external in the specified file we gather - * its address, the number of calls and compute its share of cpu time. + * its address, the number of calls and compute its share of CPU time. */ struct nl { const char *name; /* the name */ @@ -268,43 +268,43 @@ struct stringlist *ktolist; /* * function declarations */ -/* - addarc(); -*/ +void addarc(nltype *, nltype *, long); +bool addcycle(arctype **, arctype **); +void addlist(struct stringlist *, char *); +void alignentries(void); int aout_getnfile(const char *, char ***); int arccmp(); arctype *arclookup(); -/* - asgnsamples(); - printblurb(); - cyclelink(); - dfn(); -*/ +void asgnsamples(void); +void compresslist(void); +bool cycleanalyze(void); +void cyclelink(void); +void cycletime(void); +bool descend(nltype *, arctype **, arctype **); +void dfn(nltype *); bool dfn_busy(); -/* - dfn_findcycle(); -*/ +void dfn_findcycle(nltype *); +void dfn_init(void); bool dfn_numbered(); -/* - dfn_post_visit(); - dfn_pre_visit(); - dfn_self_cycle(); -*/ +void dfn_post_visit(nltype *); +void dfn_pre_visit(nltype *); +void dfn_self_cycle(nltype *); nltype **doarcs(); -/* - done(); -*/ +void doflags(void); +void dotime(void); +void dumpsum(char *); int elf_getnfile(const char *, char ***); /* findcalls(); - flatprofheader(); - flatprofline(); */ +void flatprofheader(void); +void flatprofline(nltype *); +void getpfile(char *); /* - getpfile(); gprofheader(); gprofline(); */ +void inheritflags(nltype *); int kernel_getnfile(const char *, char ***); /* main(); @@ -313,33 +313,29 @@ unsigned long max(); int membercmp(); unsigned long min(); nltype *nllookup(); +bool onlist(struct stringlist *, const char *); FILE *openpfile(); long operandlength(); operandenum operandmode(); char *operandname(); -/* - printchildren(); - printcycle(); - printgprof(); - printmembers(); - printname(); - printparents(); - printprof(); - readsamples(); -*/ +void printblurb(char *); +void printchildren(nltype *); +void printcycle(nltype *); +void printgprof(nltype **); +void printindex(void); +void printmembers(nltype *); +void printname(nltype *); +void printparents(nltype *); +void printprof(void); +void printsubcycle(cltype *); +void readsamples(FILE *); unsigned long reladdr(); -/* - sortchildren(); - sortmembers(); - sortparents(); - tally(); - timecmp(); - topcmp(); -*/ +void sortchildren(nltype *); +void sortmembers(nltype *); +void sortparents(nltype *); +void tally(struct rawarc *); +void timepropagate(nltype *); int totalcmp(); -/* - valcmp(); -*/ #define LESSTHAN -1 #define EQUALTO 0 diff --git a/usr.bin/gprof/hertz.c b/usr.bin/gprof/hertz.c index 41b455f6e1e7..7420cd3a9ca3 100644 --- a/usr.bin/gprof/hertz.c +++ b/usr.bin/gprof/hertz.c @@ -31,9 +31,14 @@ * SUCH DAMAGE. */ +#if 0 #ifndef lint static char sccsid[] = "@(#)hertz.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ +#endif + +#include +__FBSDID("$FreeBSD$"); #include diff --git a/usr.bin/gprof/hp300.c b/usr.bin/gprof/hp300.c index 6a474086a312..c35cd63a5f2e 100644 --- a/usr.bin/gprof/hp300.c +++ b/usr.bin/gprof/hp300.c @@ -1,3 +1,6 @@ +#include +__FBSDID("$FreeBSD$"); + #include "gprof.h" /* diff --git a/usr.bin/gprof/i386.c b/usr.bin/gprof/i386.c index 6a474086a312..c112763eafe3 100644 --- a/usr.bin/gprof/i386.c +++ b/usr.bin/gprof/i386.c @@ -1,8 +1,12 @@ +#include +__FBSDID("$FreeBSD$"); + #include "gprof.h" /* * gprof -c isn't currently supported... */ +void findcall( parentp , p_lowpc , p_highpc ) nltype *parentp; unsigned long p_lowpc; diff --git a/usr.bin/gprof/lookup.c b/usr.bin/gprof/lookup.c index 3c5f2b02cd01..f51da9829f74 100644 --- a/usr.bin/gprof/lookup.c +++ b/usr.bin/gprof/lookup.c @@ -31,13 +31,12 @@ * SUCH DAMAGE. */ -#ifndef lint #if 0 +#ifndef lint static char sccsid[] = "@(#)lookup.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ +#endif + #include __FBSDID("$FreeBSD$"); diff --git a/usr.bin/gprof/mips.c b/usr.bin/gprof/mips.c index 295d64ecffed..b68a2e0b3759 100644 --- a/usr.bin/gprof/mips.c +++ b/usr.bin/gprof/mips.c @@ -37,9 +37,14 @@ * From: sparc.c 5.1 (Berkeley) 7/7/92 */ +#if 0 #ifndef lint static char sccsid[] = "@(#)mips.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ +#endif + +#include +__FBSDID("$FreeBSD$"); #include "gprof.h" diff --git a/usr.bin/gprof/pathnames.h b/usr.bin/gprof/pathnames.h index ea554c61adfa..0dcd78c6af47 100644 --- a/usr.bin/gprof/pathnames.h +++ b/usr.bin/gprof/pathnames.h @@ -31,6 +31,7 @@ * SUCH DAMAGE. * * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 + * $FreeBSD$ */ #define _PATH_FLAT_BLURB "/usr/share/misc/gprof.flat" diff --git a/usr.bin/gprof/printgprof.c b/usr.bin/gprof/printgprof.c index 2440c8c030b4..de1fe49d52e2 100644 --- a/usr.bin/gprof/printgprof.c +++ b/usr.bin/gprof/printgprof.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. */ -#ifndef lint #if 0 +#ifndef lint static char sccsid[] = "@(#)printgprof.c 8.1 (Berkeley) 6/6/93"; -#endif #endif /* not lint */ +#endif + #include __FBSDID("$FreeBSD$"); @@ -43,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include "gprof.h" #include "pathnames.h" +void printprof() { register nltype *np; @@ -56,9 +58,8 @@ printprof() * Sort the symbol table in by time */ sortednlp = (nltype **) calloc( nname , sizeof(nltype *) ); - if ( sortednlp == (nltype **) 0 ) { - fprintf( stderr , "[printprof] ran out of memory for time sorting\n" ); - } + if ( sortednlp == (nltype **) 0 ) + errx( 1 , "[printprof] ran out of memory for time sorting" ); for ( index = 0 ; index < nname ; index += 1 ) { sortednlp[ index ] = &nl[ index ]; } @@ -71,6 +72,7 @@ printprof() free( sortednlp ); } +int timecmp( npp1 , npp2 ) nltype **npp1, **npp2; { @@ -93,6 +95,7 @@ timecmp( npp1 , npp2 ) /* * header for flatprofline */ +void flatprofheader() { @@ -107,7 +110,7 @@ flatprofheader() } else { printf( " no time accumulated\n\n" ); /* - * this doesn't hurt sinc eall the numerators will be zero. + * this doesn't hurt since all the numerators will be zero. */ totime = 1.0; } @@ -120,6 +123,7 @@ flatprofheader() "name" ); } +void flatprofline( np ) register nltype *np; { @@ -154,6 +158,7 @@ flatprofline( np ) printf( "\n" ); } +void gprofheader() { @@ -182,6 +187,7 @@ gprofheader() printf( "\n" ); } +void gprofline( np ) register nltype *np; { @@ -207,6 +213,7 @@ gprofline( np ) printf( "\n" ); } +void printgprof(timesortnlp) nltype **timesortnlp; { @@ -289,6 +296,7 @@ totalcmp( npp1 , npp2 ) return strcmp( np1 -> name , np2 -> name ); } +void printparents( childp ) nltype *childp; { @@ -333,6 +341,7 @@ printparents( childp ) } } +void printchildren( parentp ) nltype *parentp; { @@ -366,6 +375,7 @@ printchildren( parentp ) } } +void printname( selfp ) nltype *selfp; { @@ -393,6 +403,7 @@ printname( selfp ) } } +void sortchildren( parentp ) nltype *parentp; { @@ -433,6 +444,7 @@ sortchildren( parentp ) parentp -> children = sorted.arc_childlist; } +void sortparents( childp ) nltype *childp; { @@ -476,6 +488,7 @@ sortparents( childp ) /* * print a cycle header */ +void printcycle( cyclep ) nltype *cyclep; { @@ -500,6 +513,7 @@ printcycle( cyclep ) /* * print the members of a cycle */ +void printmembers( cyclep ) nltype *cyclep; { @@ -524,6 +538,7 @@ printmembers( cyclep ) /* * sort members of a cycle */ +void sortmembers( cyclep ) nltype *cyclep; { @@ -666,6 +681,7 @@ arccmp( thisp , thatp ) } } +void printblurb( blurbname ) char *blurbname; { @@ -674,7 +690,7 @@ printblurb( blurbname ) blurbfile = fopen( blurbname , "r" ); if ( blurbfile == NULL ) { - perror( blurbname ); + warn( "%s" , blurbname ); return; } while ( ( input = getc( blurbfile ) ) != EOF ) { @@ -690,6 +706,7 @@ namecmp( npp1 , npp2 ) return( strcmp( (*npp1) -> name , (*npp2) -> name ) ); } +void printindex() { nltype **namesortnlp; @@ -698,13 +715,12 @@ printindex() char peterbuffer[ BUFSIZ ]; /* - * Now, sort regular function name alphbetically + * Now, sort regular function name alphabetically * to create an index. */ namesortnlp = (nltype **) calloc( nname + ncycle , sizeof(nltype *) ); - if ( namesortnlp == (nltype **) 0 ) { - warnx("ran out of memory for sorting"); - } + if ( namesortnlp == (nltype **) 0 ) + errx( 1 , "ran out of memory for sorting"); for ( index = 0 , nnames = 0 ; index < nname ; index++ ) { if ( zflag == 0 && nl[index].ncall == 0 && nl[index].time == 0 ) continue; diff --git a/usr.bin/gprof/printlist.c b/usr.bin/gprof/printlist.c index 74be0e49c08b..c5ecdf7d1633 100644 --- a/usr.bin/gprof/printlist.c +++ b/usr.bin/gprof/printlist.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. */ -#ifndef lint #if 0 +#ifndef lint static char sccsid[] = "@(#)printlist.c 8.1 (Berkeley) 6/6/93"; -#endif #endif /* not lint */ +#endif + #include __FBSDID("$FreeBSD$"); @@ -61,6 +62,7 @@ struct stringlist *elist = &ehead; struct stringlist Ehead = { 0 , 0 }; struct stringlist *Elist = &Ehead; +void addlist( listp , funcname ) struct stringlist *listp; char *funcname; @@ -68,10 +70,8 @@ addlist( listp , funcname ) struct stringlist *slp; slp = (struct stringlist *) malloc( sizeof(struct stringlist)); - if ( slp == (struct stringlist *) 0 ) { - warnx("ran out room for printlist"); - done(); - } + if ( slp == (struct stringlist *) 0 ) + errx( 1 , "no room for printlist"); slp -> next = listp -> next; slp -> string = funcname; listp -> next = slp; @@ -80,7 +80,7 @@ addlist( listp , funcname ) bool onlist( listp , funcname ) struct stringlist *listp; - char *funcname; + const char *funcname; { struct stringlist *slp; diff --git a/usr.bin/gprof/sparc.c b/usr.bin/gprof/sparc.c index 513a5253bfc8..553071c33b9e 100644 --- a/usr.bin/gprof/sparc.c +++ b/usr.bin/gprof/sparc.c @@ -35,9 +35,14 @@ * SUCH DAMAGE. */ +#if 0 #ifndef lint static char sccsid[] = "@(#)sparc.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ +#endif + +#include +__FBSDID("$FreeBSD$"); #include "gprof.h" diff --git a/usr.bin/gprof/sparc64.c b/usr.bin/gprof/sparc64.c index 9742225a94f8..c35cd63a5f2e 100644 --- a/usr.bin/gprof/sparc64.c +++ b/usr.bin/gprof/sparc64.c @@ -1,4 +1,5 @@ -/* $FreeBSD$ */ +#include +__FBSDID("$FreeBSD$"); #include "gprof.h" diff --git a/usr.bin/gprof/tahoe.c b/usr.bin/gprof/tahoe.c index 839ee298bc76..7a235ac0badb 100644 --- a/usr.bin/gprof/tahoe.c +++ b/usr.bin/gprof/tahoe.c @@ -31,9 +31,14 @@ * SUCH DAMAGE. */ +#if 0 #ifndef lint static char sccsid[] = "@(#)tahoe.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ +#endif + +#include +__FBSDID("$FreeBSD$"); #include "gprof.h" diff --git a/usr.bin/gprof/vax.c b/usr.bin/gprof/vax.c index 03e3495d3114..30838b5cf853 100644 --- a/usr.bin/gprof/vax.c +++ b/usr.bin/gprof/vax.c @@ -31,9 +31,14 @@ * SUCH DAMAGE. */ +#if 0 #ifndef lint static char sccsid[] = "@(#)vax.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ +#endif + +#include +__FBSDID("$FreeBSD$"); #include "gprof.h"