+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
#ifndef lint
- static char *sccsid = "@(#)printgprof.c 1.13 (Berkeley) %G%";
-#endif lint
+static char sccsid[] = "@(#)printgprof.c 5.5 (Berkeley) %G%";
+#endif /* not lint */
#include "gprof.h"
{
register nltype *np;
nltype **sortednlp;
- int index;
+ int index, timecmp();
- printf( "\ngranularity: each sample hit covers %d byte(s)" ,
- (long) scale * sizeof(UNIT) );
- 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;
+ printf( "\f\n" );
flatprofheader();
/*
* Sort the symbol table in by time
flatprofline( np );
}
actime = 0.0;
+ cfree( sortednlp );
}
timecmp( npp1 , npp2 )
if ( bflag ) {
printblurb( FLAT_BLURB );
}
- printf( "%5.5s %7.7s %7.7s %7.7s %-8.8s\n" ,
- "%time" , "cumsecs" , "seconds" , "calls" , "name" );
+ printf( "\ngranularity: each sample hit covers %d byte(s)" ,
+ (long) scale * sizeof(UNIT) );
+ 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;
+ }
+ printf( "%5.5s %10.10s %8.8s %8.8s %8.8s %8.8s %-8.8s\n" ,
+ "% " , "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" );
}
flatprofline( np )
return;
}
actime += np -> time;
- printf( "%5.1f %7.2f %7.2f" ,
+ printf( "%5.1f %10.2f %8.2f" ,
100 * np -> time / totime , actime / hz , np -> time / hz );
if ( np -> ncall != 0 ) {
- printf( " %7d" , np -> ncall );
+ printf( " %8d %8.2f %8.2f " , np -> ncall ,
+ 1000 * np -> time / hz / np -> ncall ,
+ 1000 * ( np -> time + np -> childtime ) / hz / np -> ncall );
} else {
- printf( " %7.7s" , "" );
+ printf( " %8.8s %8.8s %8.8s " , "" , "" , "" );
}
- printf( " %s\n" , np -> name );
+ printname( np );
+ printf( "\n" );
}
gprofheader()
printtime = 1.0;
}
printf( "%6.6s %5.5s %7.7s %11.11s %7.7s/%-7.7s %-8.8s\n" ,
- "" , "" , "" , "" , "called" , "total" , "parents" , "" );
+ "" , "" , "" , "" , "called" , "total" , "parents");
printf( "%-6.6s %5.5s %7.7s %11.11s %7.7s+%-7.7s %-8.8s\t%5.5s\n" ,
"index" , "%time" , "self" , "descendents" ,
"called" , "self" , "name" , "index" );
printf( "%6.6s %5.5s %7.7s %11.11s %7.7s/%-7.7s %-8.8s\n" ,
- "" , "" , "" , "" , "called" , "total" , "children" , "" );
+ "" , "" , "" , "" , "called" , "total" , "children");
printf( "\n" );
}
printf( "\n" );
}
-printgprof()
-{
+printgprof(timesortnlp)
nltype **timesortnlp;
+{
int index;
nltype *parentp;
/*
- * Now, sort by propself + propchild.
- * sorting both the regular function names
- * and cycle headers.
+ * Print out the structured profiling list
*/
- timesortnlp = (nltype **) calloc( nname + ncycle , sizeof(nltype *) );
- if ( timesortnlp == (nltype **) 0 ) {
- fprintf( stderr , "%s: ran out of memory for sorting\n" , whoami );
- }
- for ( index = 0 ; index < nname ; index++ ) {
- timesortnlp[index] = &nl[index];
- }
- for ( index = 1 ; index <= ncycle ; index++ ) {
- timesortnlp[nname+index-1] = &cyclenl[index];
- }
- qsort( timesortnlp , nname + ncycle , sizeof(nltype *) , totalcmp );
- for ( index = 0 ; index < nname + ncycle ; index++ ) {
- timesortnlp[ index ] -> index = index + 1;
- }
- /*
- * Now, print out the structured profiling list
- */
- printf( "\f\n" );
gprofheader();
for ( index = 0 ; index < nname + ncycle ; index ++ ) {
parentp = timesortnlp[ index ];
printf( "-----------------------------------------------\n" );
printf( "\n" );
}
+ cfree( timesortnlp );
}
/*
# endif DEBUG
}
if ( selfp -> cycleno != 0 ) {
- printf( "\t<cycle %d>" , selfp -> cycleno );
+ printf( " <cycle %d>" , selfp -> cycleno );
}
if ( selfp -> index != 0 ) {
if ( selfp -> printflag ) {
* *prevp arc before the arc you are comparing.
*/
sorted.arc_childlist = 0;
- for ( arcp = parentp -> children , detachedp = arcp -> arc_childlist ;
+ for ( (arcp = parentp -> children)&&(detachedp = arcp -> arc_childlist);
arcp ;
- arcp = detachedp , detachedp = detachedp -> arc_childlist ) {
+ (arcp = detachedp)&&(detachedp = detachedp -> arc_childlist)) {
/*
* consider *arcp as disconnected
* insert it into sorted
* *prevp arc before the arc you are comparing.
*/
sorted.arc_parentlist = 0;
- for ( arcp = childp -> parents , detachedp = arcp -> arc_parentlist ;
+ for ( (arcp = childp -> parents)&&(detachedp = arcp -> arc_parentlist);
arcp ;
- arcp = detachedp , detachedp = detachedp -> arc_parentlist ) {
+ (arcp = detachedp)&&(detachedp = detachedp -> arc_parentlist)) {
/*
* consider *arcp as disconnected
* insert it into sorted
*/
todo = cyclep -> cnext;
cyclep -> cnext = 0;
- for ( doing = todo , todo = doing -> cnext ;
+ for ( (doing = todo)&&(todo = doing -> cnext);
doing ;
- doing = todo , todo = doing -> cnext ) {
+ (doing = todo )&&(todo = doing -> cnext )){
for ( prev = cyclep ; prev -> cnext ; prev = prev -> cnext ) {
if ( membercmp( doing , prev -> cnext ) == GREATERTHAN ) {
break;
}
fclose( blurbfile );
}
+
+int
+namecmp( npp1 , npp2 )
+ nltype **npp1, **npp2;
+{
+ return( strcmp( (*npp1) -> name , (*npp2) -> name ) );
+}
+
+printindex()
+{
+ nltype **namesortnlp;
+ register nltype *nlp;
+ int index, nnames, todo, i, j;
+ char peterbuffer[ BUFSIZ ];
+
+ /*
+ * Now, sort regular function name alphbetically
+ * to create an index.
+ */
+ namesortnlp = (nltype **) calloc( nname + ncycle , sizeof(nltype *) );
+ if ( namesortnlp == (nltype **) 0 ) {
+ fprintf( stderr , "%s: ran out of memory for sorting\n" , whoami );
+ }
+ for ( index = 0 , nnames = 0 ; index < nname ; index++ ) {
+ if ( zflag == 0 && nl[index].ncall == 0 && nl[index].time == 0 )
+ continue;
+ namesortnlp[nnames++] = &nl[index];
+ }
+ qsort( namesortnlp , nnames , sizeof(nltype *) , namecmp );
+ for ( index = 1 , todo = nnames ; index <= ncycle ; index++ ) {
+ namesortnlp[todo++] = &cyclenl[index];
+ }
+ printf( "\f\nIndex by function name\n\n" );
+ index = ( todo + 2 ) / 3;
+ for ( i = 0; i < index ; i++ ) {
+ for ( j = i; j < todo ; j += index ) {
+ nlp = namesortnlp[ j ];
+ if ( nlp -> printflag ) {
+ sprintf( peterbuffer , "[%d]" , nlp -> index );
+ } else {
+ sprintf( peterbuffer , "(%d)" , nlp -> index );
+ }
+ if ( j < nnames ) {
+ printf( "%6.6s %-19.19s" , peterbuffer , nlp -> name );
+ } else {
+ printf( "%6.6s " , peterbuffer );
+ sprintf( peterbuffer , "<cycle %d>" , nlp -> cycleno );
+ printf( "%-19.19s" , peterbuffer );
+ }
+ }
+ printf( "\n" );
+ }
+ cfree( namesortnlp );
+}