version 1.2, 1996/06/26 05:33:59 |
version 1.3, 2001/03/22 05:18:30 |
|
|
#include "gprof.h" |
#include "gprof.h" |
#include "pathnames.h" |
#include "pathnames.h" |
|
|
|
void |
printprof() |
printprof() |
{ |
{ |
register nltype *np; |
register nltype *np; |
nltype **sortednlp; |
nltype **sortednlp; |
int index, timecmp(); |
int index; |
|
|
actime = 0.0; |
actime = 0.0; |
printf( "\f\n" ); |
printf( "\f\n" ); |
|
|
* Sort the symbol table in by time |
* Sort the symbol table in by time |
*/ |
*/ |
sortednlp = (nltype **) calloc( nname , sizeof(nltype *) ); |
sortednlp = (nltype **) calloc( nname , sizeof(nltype *) ); |
if ( sortednlp == (nltype **) 0 ) { |
if ( sortednlp == (nltype **) 0 ) |
fprintf( stderr , "[printprof] ran out of memory for time sorting\n" ); |
warnx("[printprof] ran out of memory for time sorting"); |
} |
|
for ( index = 0 ; index < nname ; index += 1 ) { |
for ( index = 0 ; index < nname ; index += 1 ) { |
sortednlp[ index ] = &nl[ index ]; |
sortednlp[ index ] = &nl[ index ]; |
} |
} |
|
|
free( sortednlp ); |
free( sortednlp ); |
} |
} |
|
|
|
int |
timecmp( npp1 , npp2 ) |
timecmp( npp1 , npp2 ) |
nltype **npp1, **npp2; |
nltype **npp1, **npp2; |
{ |
{ |
|
|
/* |
/* |
* header for flatprofline |
* header for flatprofline |
*/ |
*/ |
|
void |
flatprofheader() |
flatprofheader() |
{ |
{ |
|
|
if ( bflag ) { |
if (bflag) |
printblurb( _PATH_FLAT_BLURB ); |
printblurb( _PATH_FLAT_BLURB ); |
} |
printf("\ngranularity: each sample hit covers %ld byte(s)", |
printf( "\ngranularity: each sample hit covers %d byte(s)" , |
(long) scale * sizeof(UNIT)); |
(long) scale * sizeof(UNIT) ); |
if (totime > 0.0) |
if ( totime > 0.0 ) { |
printf(" for %.2f%% of %.2f seconds\n\n" , 100.0/totime, totime / hz); |
printf( " for %.2f%% of %.2f seconds\n\n" , |
else { |
100.0/totime , totime / hz ); |
|
} else { |
|
printf( " no time accumulated\n\n" ); |
printf( " no time accumulated\n\n" ); |
/* |
/* |
* this doesn't hurt sinc eall the numerators will be zero. |
* this doesn't hurt sinc eall the numerators will be zero. |
*/ |
*/ |
totime = 1.0; |
totime = 1.0; |
} |
} |
printf( "%5.5s %10.10s %8.8s %8.8s %8.8s %8.8s %-8.8s\n" , |
printf("%5.5s %10.10s %8.8s %8.8s %8.8s %8.8s %-8.8s\n" , |
"% " , "cumulative" , "self " , "" , "self " , "total " , "" ); |
"% " , "cumulative" , "self " , "" , "self " , "total " , "" ); |
printf( "%5.5s %10.10s %8.8s %8.8s %8.8s %8.8s %-8.8s\n" , |
printf("%5.5s %10.10s %8.8s %8.8s %8.8s %8.8s %-8.8s\n" , |
"time" , "seconds " , "seconds" , "calls" , |
"time" , "seconds " , "seconds" , "calls" , |
"ms/call" , "ms/call" , "name" ); |
"ms/call" , "ms/call" , "name" ); |
} |
} |
|
|
|
void |
flatprofline( np ) |
flatprofline( np ) |
register nltype *np; |
register nltype *np; |
{ |
{ |
|
|
printf( "%5.1f %10.2f %8.2f" , |
printf( "%5.1f %10.2f %8.2f" , |
100 * np -> time / totime , actime / hz , np -> time / hz ); |
100 * np -> time / totime , actime / hz , np -> time / hz ); |
if ( np -> ncall != 0 ) { |
if ( np -> ncall != 0 ) { |
printf( " %8d %8.2f %8.2f " , np -> ncall , |
printf( " %8ld %8.2f %8.2f " , np -> ncall , |
1000 * np -> time / hz / np -> ncall , |
1000 * np -> time / hz / np -> ncall , |
1000 * ( np -> time + np -> childtime ) / hz / np -> ncall ); |
1000 * ( np -> time + np -> childtime ) / hz / np -> ncall ); |
} else { |
} else { |
|
|
printf( "\n" ); |
printf( "\n" ); |
} |
} |
|
|
|
void |
gprofheader() |
gprofheader() |
{ |
{ |
|
|
if ( bflag ) { |
if ( bflag ) { |
printblurb( _PATH_CALLG_BLURB ); |
printblurb( _PATH_CALLG_BLURB ); |
} |
} |
printf( "\ngranularity: each sample hit covers %d byte(s)" , |
printf( "\ngranularity: each sample hit covers %ld byte(s)" , |
(long) scale * sizeof(UNIT) ); |
(long) scale * sizeof(UNIT) ); |
if ( printtime > 0.0 ) { |
if ( printtime > 0.0 ) { |
printf( " for %.2f%% of %.2f seconds\n\n" , |
printf( " for %.2f%% of %.2f seconds\n\n" , |
|
|
printf( "\n" ); |
printf( "\n" ); |
} |
} |
|
|
|
void |
gprofline( np ) |
gprofline( np ) |
register nltype *np; |
register nltype *np; |
{ |
{ |
char kirkbuffer[ BUFSIZ ]; |
char kirkbuffer[ BUFSIZ ]; |
|
|
sprintf( kirkbuffer , "[%d]" , np -> index ); |
sprintf( kirkbuffer , "[%d]" , np -> index ); |
printf( "%-6.6s %5.1f %7.2f %11.2f" , |
printf( "%-6.6s %5.1f %7.2f %11.2f" , kirkbuffer , |
kirkbuffer , |
|
100 * ( np -> propself + np -> propchild ) / printtime , |
100 * ( np -> propself + np -> propchild ) / printtime , |
np -> propself / hz , |
np -> propself / hz , np -> propchild / hz ); |
np -> propchild / hz ); |
|
if ( ( np -> ncall + np -> selfcalls ) != 0 ) { |
if ( ( np -> ncall + np -> selfcalls ) != 0 ) { |
printf( " %7d" , np -> npropcall ); |
printf( " %7ld" , np -> npropcall ); |
if ( np -> selfcalls != 0 ) { |
if ( np -> selfcalls != 0 ) { |
printf( "+%-7d " , np -> selfcalls ); |
printf( "+%-7ld " , np -> selfcalls ); |
} else { |
} else { |
printf( " %7.7s " , "" ); |
printf( " %7.7s " , "" ); |
} |
} |
|
|
printf( "\n" ); |
printf( "\n" ); |
} |
} |
|
|
|
void |
printgprof(timesortnlp) |
printgprof(timesortnlp) |
nltype **timesortnlp; |
nltype **timesortnlp; |
{ |
{ |
|
|
return strcmp( np1 -> name , np2 -> name ); |
return strcmp( np1 -> name , np2 -> name ); |
} |
} |
|
|
|
void |
printparents( childp ) |
printparents( childp ) |
nltype *childp; |
nltype *childp; |
{ |
{ |
|
|
/* |
/* |
* selfcall or call among siblings |
* selfcall or call among siblings |
*/ |
*/ |
printf( "%6.6s %5.5s %7.7s %11.11s %7d %7.7s " , |
printf( "%6.6s %5.5s %7.7s %11.11s %7ld %7.7s " , |
"" , "" , "" , "" , |
"" , "" , "" , "" , |
arcp -> arc_count , "" ); |
arcp -> arc_count , "" ); |
printname( parentp ); |
printname( parentp ); |
|
|
/* |
/* |
* regular parent of child |
* regular parent of child |
*/ |
*/ |
printf( "%6.6s %5.5s %7.2f %11.2f %7d/%-7d " , |
printf( "%6.6s %5.5s %7.2f %11.2f %7ld/%-7ld " , |
"" , "" , |
"" , "" , |
arcp -> arc_time / hz , arcp -> arc_childtime / hz , |
arcp -> arc_time / hz , arcp -> arc_childtime / hz , |
arcp -> arc_count , cycleheadp -> npropcall ); |
arcp -> arc_count , cycleheadp -> npropcall ); |
|
|
} |
} |
} |
} |
|
|
|
void |
printchildren( parentp ) |
printchildren( parentp ) |
nltype *parentp; |
nltype *parentp; |
{ |
{ |
|
|
/* |
/* |
* self call or call to sibling |
* self call or call to sibling |
*/ |
*/ |
printf( "%6.6s %5.5s %7.7s %11.11s %7d %7.7s " , |
printf( "%6.6s %5.5s %7.7s %11.11s %7ld %7.7s " , |
"" , "" , "" , "" , arcp -> arc_count , "" ); |
"" , "" , "" , "" , arcp -> arc_count , "" ); |
printname( childp ); |
printname( childp ); |
printf( "\n" ); |
printf( "\n" ); |
|
|
/* |
/* |
* regular child of parent |
* regular child of parent |
*/ |
*/ |
printf( "%6.6s %5.5s %7.2f %11.2f %7d/%-7d " , |
printf( "%6.6s %5.5s %7.2f %11.2f %7ld/%-7ld " , |
"" , "" , |
"" , "" , |
arcp -> arc_time / hz , arcp -> arc_childtime / hz , |
arcp -> arc_time / hz , arcp -> arc_childtime / hz , |
arcp -> arc_count , childp -> cyclehead -> npropcall ); |
arcp -> arc_count , childp -> cyclehead -> npropcall ); |
|
|
} |
} |
} |
} |
|
|
|
void |
printname( selfp ) |
printname( selfp ) |
nltype *selfp; |
nltype *selfp; |
{ |
{ |
|
|
} |
} |
} |
} |
|
|
|
void |
sortchildren( parentp ) |
sortchildren( parentp ) |
nltype *parentp; |
nltype *parentp; |
{ |
{ |
|
|
* *prevp arc before the arc you are comparing. |
* *prevp arc before the arc you are comparing. |
*/ |
*/ |
sorted.arc_childlist = 0; |
sorted.arc_childlist = 0; |
for ( (arcp = parentp -> children)&&(detachedp = arcp -> arc_childlist); |
for ( arcp = parentp -> children, detachedp = arcp -> arc_childlist; |
arcp ; |
arcp ; |
(arcp = detachedp)&&(detachedp = detachedp -> arc_childlist)) { |
arcp = detachedp, detachedp = detachedp -> arc_childlist) { |
/* |
/* |
* consider *arcp as disconnected |
* consider *arcp as disconnected |
* insert it into sorted |
* insert it into sorted |
|
|
parentp -> children = sorted.arc_childlist; |
parentp -> children = sorted.arc_childlist; |
} |
} |
|
|
|
void |
sortparents( childp ) |
sortparents( childp ) |
nltype *childp; |
nltype *childp; |
{ |
{ |
|
|
* *prevp arc before the arc you are comparing. |
* *prevp arc before the arc you are comparing. |
*/ |
*/ |
sorted.arc_parentlist = 0; |
sorted.arc_parentlist = 0; |
for ( (arcp = childp -> parents)&&(detachedp = arcp -> arc_parentlist); |
for (arcp = childp->parents, detachedp = arcp->arc_parentlist; |
arcp ; |
arcp; arcp = detachedp, detachedp = detachedp->arc_parentlist) { |
(arcp = detachedp)&&(detachedp = detachedp -> arc_parentlist)) { |
|
/* |
/* |
* consider *arcp as disconnected |
* consider *arcp as disconnected |
* insert it into sorted |
* insert it into sorted |
*/ |
*/ |
for ( prevp = &sorted ; |
for (prevp = &sorted; prevp->arc_parentlist; |
prevp -> arc_parentlist ; |
prevp = prevp->arc_parentlist) |
prevp = prevp -> arc_parentlist ) { |
if (arccmp(arcp , prevp->arc_parentlist) != GREATERTHAN) |
if ( arccmp( arcp , prevp -> arc_parentlist ) != GREATERTHAN ) { |
|
break; |
break; |
} |
arcp->arc_parentlist = prevp->arc_parentlist; |
} |
prevp->arc_parentlist = arcp; |
arcp -> arc_parentlist = prevp -> arc_parentlist; |
|
prevp -> arc_parentlist = arcp; |
|
} |
} |
/* |
/* |
* reattach sorted arcs to child |
* reattach sorted arcs to child |
|
|
/* |
/* |
* print a cycle header |
* print a cycle header |
*/ |
*/ |
|
void |
printcycle( cyclep ) |
printcycle( cyclep ) |
nltype *cyclep; |
nltype *cyclep; |
{ |
{ |
char kirkbuffer[ BUFSIZ ]; |
char kirkbuffer[ BUFSIZ ]; |
|
|
sprintf( kirkbuffer , "[%d]" , cyclep -> index ); |
sprintf(kirkbuffer , "[%d]" , cyclep->index); |
printf( "%-6.6s %5.1f %7.2f %11.2f %7d" , |
printf("%-6.6s %5.1f %7.2f %11.2f %7ld", kirkbuffer, |
kirkbuffer , |
100 * (cyclep->propself + cyclep->propchild) / printtime, |
100 * ( cyclep -> propself + cyclep -> propchild ) / printtime , |
cyclep->propself / hz, cyclep->propchild / hz, cyclep->npropcall); |
cyclep -> propself / hz , |
if (cyclep -> selfcalls != 0) |
cyclep -> propchild / hz , |
printf("+%-7ld" , cyclep->selfcalls); |
cyclep -> npropcall ); |
else |
if ( cyclep -> selfcalls != 0 ) { |
printf(" %7.7s" , ""); |
printf( "+%-7d" , cyclep -> selfcalls ); |
printf(" <cycle %d as a whole>\t[%d]\n" , |
} else { |
cyclep->cycleno , cyclep->index ); |
printf( " %7.7s" , "" ); |
|
} |
|
printf( " <cycle %d as a whole>\t[%d]\n" , |
|
cyclep -> cycleno , cyclep -> index ); |
|
} |
} |
|
|
/* |
/* |
* print the members of a cycle |
* print the members of a cycle |
*/ |
*/ |
|
void |
printmembers( cyclep ) |
printmembers( cyclep ) |
nltype *cyclep; |
nltype *cyclep; |
{ |
{ |
|
|
|
|
sortmembers( cyclep ); |
sortmembers( cyclep ); |
for ( memberp = cyclep -> cnext ; memberp ; memberp = memberp -> cnext ) { |
for ( memberp = cyclep -> cnext ; memberp ; memberp = memberp -> cnext ) { |
printf( "%6.6s %5.5s %7.2f %11.2f %7d" , |
printf( "%6.6s %5.5s %7.2f %11.2f %7ld" , "", "", |
"" , "" , memberp -> propself / hz , memberp -> propchild / hz , |
memberp->propself / hz, memberp->propchild / hz, memberp->npropcall ); |
memberp -> npropcall ); |
if (memberp -> selfcalls != 0) |
if ( memberp -> selfcalls != 0 ) { |
printf("+%-7ld" , memberp -> selfcalls); |
printf( "+%-7d" , memberp -> selfcalls ); |
else |
} else { |
printf(" %7.7s", ""); |
printf( " %7.7s" , "" ); |
printf(" "); |
} |
printname(memberp); |
printf( " " ); |
printf("\n"); |
printname( memberp ); |
|
printf( "\n" ); |
|
} |
} |
} |
} |
|
|
/* |
/* |
* sort members of a cycle |
* sort members of a cycle |
*/ |
*/ |
|
void |
sortmembers( cyclep ) |
sortmembers( cyclep ) |
nltype *cyclep; |
nltype *cyclep; |
{ |
{ |
|
|
*/ |
*/ |
todo = cyclep -> cnext; |
todo = cyclep -> cnext; |
cyclep -> cnext = 0; |
cyclep -> cnext = 0; |
for ( (doing = todo)&&(todo = doing -> cnext); |
for (doing = todo, todo = doing -> cnext; |
doing ; |
doing; doing = todo, todo = doing -> cnext) { |
(doing = todo )&&(todo = doing -> cnext )){ |
for (prev = cyclep; prev -> cnext; prev = prev -> cnext) |
for ( prev = cyclep ; prev -> cnext ; prev = prev -> cnext ) { |
if (membercmp(doing, prev->cnext ) == GREATERTHAN) |
if ( membercmp( doing , prev -> cnext ) == GREATERTHAN ) { |
|
break; |
break; |
} |
|
} |
|
doing -> cnext = prev -> cnext; |
doing -> cnext = prev -> cnext; |
prev -> cnext = doing; |
prev -> cnext = doing; |
} |
} |
|
|
} |
} |
} |
} |
|
|
|
void |
printblurb( blurbname ) |
printblurb( blurbname ) |
char *blurbname; |
char *blurbname; |
{ |
{ |
|
|
|
|
blurbfile = fopen( blurbname , "r" ); |
blurbfile = fopen( blurbname , "r" ); |
if ( blurbfile == NULL ) { |
if ( blurbfile == NULL ) { |
perror( blurbname ); |
warn("fopen: %s", blurbname ); |
return; |
return; |
} |
} |
while ( ( input = getc( blurbfile ) ) != EOF ) { |
while ( ( input = getc( blurbfile ) ) != EOF ) |
putchar( input ); |
putchar( input ); |
} |
|
fclose( blurbfile ); |
fclose( blurbfile ); |
} |
} |
|
|
|
|
return( strcmp( (*npp1) -> name , (*npp2) -> name ) ); |
return( strcmp( (*npp1) -> name , (*npp2) -> name ) ); |
} |
} |
|
|
|
void |
printindex() |
printindex() |
{ |
{ |
nltype **namesortnlp; |
nltype **namesortnlp; |
|
|
* to create an index. |
* to create an index. |
*/ |
*/ |
namesortnlp = (nltype **) calloc( nname + ncycle , sizeof(nltype *) ); |
namesortnlp = (nltype **) calloc( nname + ncycle , sizeof(nltype *) ); |
if ( namesortnlp == (nltype **) 0 ) { |
if ( namesortnlp == (nltype **) 0 ) |
fprintf( stderr , "%s: ran out of memory for sorting\n" , whoami ); |
warnx("ran out of memory for sorting"); |
} |
|
for ( index = 0 , nnames = 0 ; index < nname ; index++ ) { |
for ( index = 0 , nnames = 0 ; index < nname ; index++ ) { |
if ( zflag == 0 && nl[index].ncall == 0 && nl[index].time == 0 ) |
if ( zflag == 0 && nl[index].ncall == 0 && nl[index].time == 0 ) |
continue; |
continue; |