📄 printgprof.c
字号:
}# endif DEBUG } if ( selfp -> cycleno != 0 ) { printf( " <cycle %d>" , selfp -> cycleno ); } if ( selfp -> index != 0 ) { if ( selfp -> printflag ) { printf( " [%d]" , selfp -> index ); } else { printf( " (%d)" , selfp -> index ); } }}sortchildren( parentp ) nltype *parentp;{ arctype *arcp; arctype *detachedp; arctype sorted; arctype *prevp; /* * unlink children from parent, * then insertion sort back on to sorted's children. * *arcp the arc you have detached and are inserting. * *detachedp the rest of the arcs to be sorted. * sorted arc list onto which you insertion sort. * *prevp arc before the arc you are comparing. */ sorted.arc_childlist = 0; for ( (arcp = parentp -> children)&&(detachedp = arcp -> arc_childlist); arcp ; (arcp = detachedp)&&(detachedp = detachedp -> arc_childlist)) { /* * consider *arcp as disconnected * insert it into sorted */ for ( prevp = &sorted ; prevp -> arc_childlist ; prevp = prevp -> arc_childlist ) { if ( arccmp( arcp , prevp -> arc_childlist ) != LESSTHAN ) { break; } } arcp -> arc_childlist = prevp -> arc_childlist; prevp -> arc_childlist = arcp; } /* * reattach sorted children to parent */ parentp -> children = sorted.arc_childlist;}sortparents( childp ) nltype *childp;{ arctype *arcp; arctype *detachedp; arctype sorted; arctype *prevp; /* * unlink parents from child, * then insertion sort back on to sorted's parents. * *arcp the arc you have detached and are inserting. * *detachedp the rest of the arcs to be sorted. * sorted arc list onto which you insertion sort. * *prevp arc before the arc you are comparing. */ sorted.arc_parentlist = 0; for ( (arcp = childp -> parents)&&(detachedp = arcp -> arc_parentlist); arcp ; (arcp = detachedp)&&(detachedp = detachedp -> arc_parentlist)) { /* * consider *arcp as disconnected * insert it into sorted */ for ( prevp = &sorted ; prevp -> arc_parentlist ; prevp = prevp -> arc_parentlist ) { if ( arccmp( arcp , prevp -> arc_parentlist ) != GREATERTHAN ) { break; } } arcp -> arc_parentlist = prevp -> arc_parentlist; prevp -> arc_parentlist = arcp; } /* * reattach sorted arcs to child */ childp -> parents = sorted.arc_parentlist;} /* * print a cycle header */printcycle( cyclep ) nltype *cyclep;{ char kirkbuffer[ BUFSIZ ]; sprintf( kirkbuffer , "[%d]" , cyclep -> index ); printf( "%-6.6s %5.1f %7.2f %11.2f %7d" , kirkbuffer , 100 * ( cyclep -> propself + cyclep -> propchild ) / printtime , cyclep -> propself / hz , cyclep -> propchild / hz , cyclep -> npropcall ); if ( cyclep -> selfcalls != 0 ) { printf( "+%-7d" , cyclep -> selfcalls ); } else { printf( " %7.7s" , "" ); } printf( " <cycle %d as a whole>\t[%d]\n" , cyclep -> cycleno , cyclep -> index );} /* * print the members of a cycle */printmembers( cyclep ) nltype *cyclep;{ nltype *memberp; sortmembers( cyclep ); for ( memberp = cyclep -> cnext ; memberp ; memberp = memberp -> cnext ) { printf( "%6.6s %5.5s %7.2f %11.2f %7d" , "" , "" , memberp -> propself / hz , memberp -> propchild / hz , memberp -> npropcall ); if ( memberp -> selfcalls != 0 ) { printf( "+%-7d" , memberp -> selfcalls ); } else { printf( " %7.7s" , "" ); } printf( " " ); printname( memberp ); printf( "\n" ); }} /* * sort members of a cycle */sortmembers( cyclep ) nltype *cyclep;{ nltype *todo; nltype *doing; nltype *prev; /* * detach cycle members from cyclehead, * and insertion sort them back on. */ todo = cyclep -> cnext; cyclep -> cnext = 0; for ( (doing = todo)&&(todo = doing -> cnext); doing ; (doing = todo )&&(todo = doing -> cnext )){ for ( prev = cyclep ; prev -> cnext ; prev = prev -> cnext ) { if ( membercmp( doing , prev -> cnext ) == GREATERTHAN ) { break; } } doing -> cnext = prev -> cnext; prev -> cnext = doing; }} /* * major sort is on propself + propchild, * next is sort on ncalls + selfcalls. */intmembercmp( this , that ) nltype *this; nltype *that;{ double thistime = this -> propself + this -> propchild; double thattime = that -> propself + that -> propchild; long thiscalls = this -> ncall + this -> selfcalls; long thatcalls = that -> ncall + that -> selfcalls; if ( thistime > thattime ) { return GREATERTHAN; } if ( thistime < thattime ) { return LESSTHAN; } if ( thiscalls > thatcalls ) { return GREATERTHAN; } if ( thiscalls < thatcalls ) { return LESSTHAN; } return EQUALTO;} /* * compare two arcs to/from the same child/parent. * - if one arc is a self arc, it's least. * - if one arc is within a cycle, it's less than. * - if both arcs are within a cycle, compare arc counts. * - if neither arc is within a cycle, compare with * arc_time + arc_childtime as major key * arc count as minor key */intarccmp( thisp , thatp ) arctype *thisp; arctype *thatp;{ nltype *thisparentp = thisp -> arc_parentp; nltype *thischildp = thisp -> arc_childp; nltype *thatparentp = thatp -> arc_parentp; nltype *thatchildp = thatp -> arc_childp; double thistime; double thattime;# ifdef DEBUG if ( debug & TIMEDEBUG ) { printf( "[arccmp] " ); printname( thisparentp ); printf( " calls " ); printname ( thischildp ); printf( " %f + %f %d/%d\n" , thisp -> arc_time , thisp -> arc_childtime , thisp -> arc_count , thischildp -> ncall ); printf( "[arccmp] " ); printname( thatparentp ); printf( " calls " ); printname( thatchildp ); printf( " %f + %f %d/%d\n" , thatp -> arc_time , thatp -> arc_childtime , thatp -> arc_count , thatchildp -> ncall ); printf( "\n" ); }# endif DEBUG if ( thisparentp == thischildp ) { /* this is a self call */ return LESSTHAN; } if ( thatparentp == thatchildp ) { /* that is a self call */ return GREATERTHAN; } if ( thisparentp -> cycleno != 0 && thischildp -> cycleno != 0 && thisparentp -> cycleno == thischildp -> cycleno ) { /* this is a call within a cycle */ if ( thatparentp -> cycleno != 0 && thatchildp -> cycleno != 0 && thatparentp -> cycleno == thatchildp -> cycleno ) { /* that is a call within the cycle, too */ if ( thisp -> arc_count < thatp -> arc_count ) { return LESSTHAN; } if ( thisp -> arc_count > thatp -> arc_count ) { return GREATERTHAN; } return EQUALTO; } else { /* that isn't a call within the cycle */ return LESSTHAN; } } else { /* this isn't a call within a cycle */ if ( thatparentp -> cycleno != 0 && thatchildp -> cycleno != 0 && thatparentp -> cycleno == thatchildp -> cycleno ) { /* that is a call within a cycle */ return GREATERTHAN; } else { /* neither is a call within a cycle */ thistime = thisp -> arc_time + thisp -> arc_childtime; thattime = thatp -> arc_time + thatp -> arc_childtime; if ( thistime < thattime ) return LESSTHAN; if ( thistime > thattime ) return GREATERTHAN; if ( thisp -> arc_count < thatp -> arc_count ) return LESSTHAN; if ( thisp -> arc_count > thatp -> arc_count ) return GREATERTHAN; return EQUALTO; } }}printblurb( blurbname ) char *blurbname;{ FILE *blurbfile; int input; blurbfile = fopen( blurbname , "r" ); if ( blurbfile == NULL ) { perror( blurbname ); return; } while ( ( input = getc( blurbfile ) ) != EOF ) { putchar( input ); } fclose( blurbfile );}intnamecmp( 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" ); } free( namesortnlp );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -