⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printgprof.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 1983, 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)printgprof.c	8.1 (Berkeley) 6/6/93";#endif /* not lint */#include "gprof.h"#include "pathnames.h"printprof(){    register nltype	*np;    nltype		**sortednlp;    int			index, timecmp();    actime = 0.0;    printf( "\f\n" );    flatprofheader();	/*	 *	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" );    }    for ( index = 0 ; index < nname ; index += 1 ) {	sortednlp[ index ] = &nl[ index ];    }    qsort( sortednlp , nname , sizeof(nltype *) , timecmp );    for ( index = 0 ; index < nname ; index += 1 ) {	np = sortednlp[ index ];	flatprofline( np );    }    actime = 0.0;    free( sortednlp );}timecmp( npp1 , npp2 )    nltype **npp1, **npp2;{    double	timediff;    long	calldiff;    timediff = (*npp2) -> time - (*npp1) -> time;    if ( timediff > 0.0 )	return 1 ;    if ( timediff < 0.0 )	return -1;    calldiff = (*npp2) -> ncall - (*npp1) -> ncall;    if ( calldiff > 0 )	return 1;    if ( calldiff < 0 )	return -1;    return( strcmp( (*npp1) -> name , (*npp2) -> name ) );}    /*     *	header for flatprofline     */flatprofheader(){        if ( bflag ) {	printblurb( _PATH_FLAT_BLURB );    }    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 )    register nltype	*np;{    if ( zflag == 0 && np -> ncall == 0 && np -> time == 0 ) {	return;    }    actime += np -> time;    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 );    } else {	printf( " %8.8s %8.8s %8.8s  " , "" , "" , "" );    }    printname( np );    printf( "\n" );}gprofheader(){    if ( bflag ) {	printblurb( _PATH_CALLG_BLURB );    }    printf( "\ngranularity: each sample hit covers %d byte(s)" ,	    (long) scale * sizeof(UNIT) );    if ( printtime > 0.0 ) {	printf( " for %.2f%% of %.2f seconds\n\n" ,		100.0/printtime , printtime / hz );    } else {	printf( " no time propagated\n\n" );	    /*	     *	this doesn't hurt, since all the numerators will be 0.0	     */	printtime = 1.0;    }    printf( "%6.6s %5.5s %7.7s %11.11s %7.7s/%-7.7s     %-8.8s\n" ,	"" , "" , "" , "" , "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");    printf( "\n" );}gprofline( np )    register nltype	*np;{    char	kirkbuffer[ BUFSIZ ];    sprintf( kirkbuffer , "[%d]" , np -> index );    printf( "%-6.6s %5.1f %7.2f %11.2f" ,	    kirkbuffer ,	    100 * ( np -> propself + np -> propchild ) / printtime ,	    np -> propself / hz ,	    np -> propchild / hz );    if ( ( np -> ncall + np -> selfcalls ) != 0 ) {	printf( " %7d" , np -> npropcall );	if ( np -> selfcalls != 0 ) {	    printf( "+%-7d " , np -> selfcalls );	} else {	    printf( " %7.7s " , "" );	}    } else {	printf( " %7.7s %7.7s " , "" , "" );    }    printname( np );    printf( "\n" );}printgprof(timesortnlp)    nltype	**timesortnlp;{    int		index;    nltype	*parentp;	/*	 *	Print out the structured profiling list	 */    gprofheader();    for ( index = 0 ; index < nname + ncycle ; index ++ ) {	parentp = timesortnlp[ index ];	if ( zflag == 0 &&	     parentp -> ncall == 0 &&	     parentp -> selfcalls == 0 &&	     parentp -> propself == 0 &&	     parentp -> propchild == 0 ) {	    continue;	}	if ( ! parentp -> printflag ) {	    continue;	}	if ( parentp -> name == 0 && parentp -> cycleno != 0 ) {		/*		 *	cycle header		 */	    printcycle( parentp );	    printmembers( parentp );	} else {	    printparents( parentp );	    gprofline( parentp );	    printchildren( parentp );	}	printf( "\n" );	printf( "-----------------------------------------------\n" );	printf( "\n" );    }    free( timesortnlp );}    /*     *	sort by decreasing propagated time     *	if times are equal, but one is a cycle header,     *		say that's first (e.g. less, i.e. -1).     *	if one's name doesn't have an underscore and the other does,     *		say the one is first.     *	all else being equal, sort by names.     */inttotalcmp( npp1 , npp2 )    nltype	**npp1;    nltype	**npp2;{    register nltype	*np1 = *npp1;    register nltype	*np2 = *npp2;    double		diff;    diff =    ( np1 -> propself + np1 -> propchild )	    - ( np2 -> propself + np2 -> propchild );    if ( diff < 0.0 )	    return 1;    if ( diff > 0.0 )	    return -1;    if ( np1 -> name == 0 && np1 -> cycleno != 0 ) 	return -1;    if ( np2 -> name == 0 && np2 -> cycleno != 0 )	return 1;    if ( np1 -> name == 0 )	return -1;    if ( np2 -> name == 0 )	return 1;    if ( *(np1 -> name) != '_' && *(np2 -> name) == '_' )	return -1;    if ( *(np1 -> name) == '_' && *(np2 -> name) != '_' )	return 1;    if ( np1 -> ncall > np2 -> ncall )	return -1;    if ( np1 -> ncall < np2 -> ncall ) 	return 1;    return strcmp( np1 -> name , np2 -> name );}printparents( childp )    nltype	*childp;{    nltype	*parentp;    arctype	*arcp;    nltype	*cycleheadp;    if ( childp -> cyclehead != 0 ) {	cycleheadp = childp -> cyclehead;    } else {	cycleheadp = childp;    }    if ( childp -> parents == 0 ) {	printf( "%6.6s %5.5s %7.7s %11.11s %7.7s %7.7s     <spontaneous>\n" ,		"" , "" , "" , "" , "" , "" );	return;    }    sortparents( childp );    for ( arcp = childp -> parents ; arcp ; arcp = arcp -> arc_parentlist ) {	parentp = arcp -> arc_parentp;	if ( childp == parentp || ( arcp -> arc_flags & DEADARC ) ||	     ( childp->cycleno != 0 && parentp->cycleno == childp->cycleno ) ) {		/*		 *	selfcall or call among siblings		 */	    printf( "%6.6s %5.5s %7.7s %11.11s %7d %7.7s     " ,		    "" , "" , "" , "" ,		    arcp -> arc_count , "" );	    printname( parentp );	    printf( "\n" );	} else {		/*		 *	regular parent of child		 */	    printf( "%6.6s %5.5s %7.2f %11.2f %7d/%-7d     " ,		    "" , "" ,		    arcp -> arc_time / hz , arcp -> arc_childtime / hz ,		    arcp -> arc_count , cycleheadp -> npropcall );	    printname( parentp );	    printf( "\n" );	}    }}printchildren( parentp )    nltype	*parentp;{    nltype	*childp;    arctype	*arcp;    sortchildren( parentp );    arcp = parentp -> children;    for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) {	childp = arcp -> arc_childp;	if ( childp == parentp || ( arcp -> arc_flags & DEADARC ) ||	    ( childp->cycleno != 0 && childp->cycleno == parentp->cycleno ) ) {		/*		 *	self call or call to sibling		 */	    printf( "%6.6s %5.5s %7.7s %11.11s %7d %7.7s     " ,		    "" , "" , "" , "" , arcp -> arc_count , "" );	    printname( childp );	    printf( "\n" );	} else {		/*		 *	regular child of parent		 */	    printf( "%6.6s %5.5s %7.2f %11.2f %7d/%-7d     " ,		    "" , "" ,		    arcp -> arc_time / hz , arcp -> arc_childtime / hz ,		    arcp -> arc_count , childp -> cyclehead -> npropcall );	    printname( childp );	    printf( "\n" );	}    }}printname( selfp )    nltype	*selfp;{    if ( selfp -> name != 0 ) {	printf( "%s" , selfp -> name );#	ifdef DEBUG	    if ( debug & DFNDEBUG ) {		printf( "{%d} " , selfp -> toporder );	    }	    if ( debug & PROPDEBUG ) {		printf( "%5.2f%% " , selfp -> propfraction );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -