xref: /csrg-svn/usr.bin/gprof/gprof.h (revision 33225)
121965Sdist /*
221965Sdist  * Copyright (c) 1983 Regents of the University of California.
321965Sdist  * All rights reserved.  The Berkeley software License Agreement
421965Sdist  * specifies the terms and conditions for redistribution.
521965Sdist  *
6*33225Sbostic  *	@(#)gprof.h	5.4 (Berkeley) 01/02/88
721965Sdist  */
84511Speter 
94511Speter #include <stdio.h>
104511Speter #include <sys/types.h>
114511Speter #include <sys/stat.h>
124511Speter #include <a.out.h>
134870Smckusic #include "gcrt0.h"
144511Speter 
1511799Speter #if vax
1611799Speter #   include "vax.h"
1711799Speter #endif
1811799Speter #if sun
1925709Ssam #   include "sun.h"
2011799Speter #endif
2125709Ssam #if tahoe
2225709Ssam #   include "tahoe.h"
2325709Ssam #endif
2411799Speter 
2511799Speter 
264511Speter     /*
277129Speter      *	who am i, for error messages.
287129Speter      */
297129Speter char	*whoami;
307129Speter 
317129Speter     /*
327174Speter      * booleans
337174Speter      */
347174Speter typedef int	bool;
357174Speter #define	FALSE	0
367174Speter #define	TRUE	1
377174Speter 
387174Speter     /*
394511Speter      *	ticks per second
404511Speter      */
4110250Speter long	hz;
424511Speter 
43*33225Sbostic typedef	u_short UNIT;		/* unit of profiling */
444511Speter char	*a_outname;
454511Speter #define	A_OUTNAME		"a.out"
464511Speter 
474560Speter char	*gmonname;
484560Speter #define	GMONNAME		"gmon.out"
494867Smckusic #define	GMONSUM			"gmon.sum"
50*33225Sbostic 
514873Smckusic     /*
5210286Speter      *	blurbs on the flat and graph profiles.
534873Smckusic      */
5416862Smckusick #define	FLAT_BLURB	"/usr/lib/gprof.flat"
5516862Smckusick #define	CALLG_BLURB	"/usr/lib/gprof.callg"
564511Speter 
574511Speter     /*
584511Speter      *	a constructed arc,
594511Speter      *	    with pointers to the namelist entry of the parent and the child,
604511Speter      *	    a count of how many times this arc was traversed,
614511Speter      *	    and pointers to the next parent of this child and
624511Speter      *		the next child of this parent.
634511Speter      */
644511Speter struct arcstruct {
654511Speter     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
664511Speter     struct nl		*arc_childp;	/* pointer to child's nl entry */
674511Speter     long		arc_count;	/* how calls from parent to child */
684511Speter     double		arc_time;	/* time inherited along arc */
694511Speter     double		arc_childtime;	/* childtime inherited along arc */
704511Speter     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
714511Speter     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
724511Speter };
734511Speter typedef struct arcstruct	arctype;
744511Speter 
757129Speter     /*
767129Speter      * The symbol table;
777129Speter      * for each external in the specified file we gather
787129Speter      * its address, the number of calls and compute its share of cpu time.
797129Speter      */
804511Speter struct nl {
817129Speter     char		*name;		/* the name */
827129Speter     unsigned long	value;		/* the pc entry point */
8311799Speter     unsigned long	svalue;		/* entry point aligned to histograms */
847129Speter     double		time;		/* ticks in this routine */
857129Speter     double		childtime;	/* cumulative ticks in children */
867129Speter     long		ncall;		/* how many times called */
877129Speter     long		selfcalls;	/* how many calls to self */
887224Speter     double		propfraction;	/* what % of time propagates */
897224Speter     double		propself;	/* how much self time propagates */
907224Speter     double		propchild;	/* how much child time propagates */
917174Speter     bool		printflag;	/* should this be printed? */
927129Speter     int			index;		/* index in the graph list */
937129Speter     int			toporder;	/* graph call chain top-sort order */
947129Speter     int			cycleno;	/* internal number of cycle on */
957129Speter     struct nl		*cyclehead;	/* pointer to head of cycle */
967129Speter     struct nl		*cnext;		/* pointer to next member of cycle */
977129Speter     arctype		*parents;	/* list of caller arcs */
987129Speter     arctype		*children;	/* list of callee arcs */
994511Speter };
1004511Speter typedef struct nl	nltype;
1014511Speter 
1024511Speter nltype	*nl;			/* the whole namelist */
1034511Speter nltype	*npe;			/* the virtual end of the namelist */
1047129Speter int	nname;			/* the number of function names */
1054511Speter 
1064511Speter     /*
1074511Speter      *	flag which marks a nl entry as topologically ``busy''
10810284Speter      *	flag which marks a nl entry as topologically ``not_numbered''
1094511Speter      */
1104511Speter #define	DFN_BUSY	-1
11110284Speter #define	DFN_NAN		0
1124511Speter 
1134511Speter     /*
1147129Speter      *	namelist entries for cycle headers.
1157129Speter      *	the number of discovered cycles.
1164511Speter      */
1177129Speter nltype	*cyclenl;		/* cycle header namelist */
1187129Speter int	ncycle;			/* number of cycles discovered */
1194511Speter 
1207129Speter     /*
1217129Speter      * The header on the gmon.out file.
1227129Speter      * gmon.out consists of one of these headers,
1237129Speter      * and then an array of ncnt samples
1247129Speter      * representing the discretized program counter values.
1257129Speter      *	this should be a struct phdr, but since everything is done
1267129Speter      *	as UNITs, this is in UNITs too.
1277129Speter      */
1284511Speter struct hdr {
1297129Speter     UNIT	*lowpc;
1307129Speter     UNIT	*highpc;
1317129Speter     int	ncnt;
1324511Speter };
1334511Speter 
1344511Speter struct hdr	h;
1354511Speter 
1364511Speter int	debug;
1374511Speter 
1387129Speter     /*
1397129Speter      * Each discretized pc sample has
1407129Speter      * a count of the number of samples in its range
1417129Speter      */
142*33225Sbostic UNIT	*samples;
1434511Speter 
1444751Speter unsigned long	s_lowpc;	/* lowpc from the profile file */
1454751Speter unsigned long	s_highpc;	/* highpc from the profile file */
1464751Speter unsigned lowpc, highpc;		/* range profiled, in UNIT's */
1474511Speter unsigned sampbytes;		/* number of bytes of samples */
1484511Speter int	nsamples;		/* number of samples */
1494511Speter double	actime;			/* accumulated time thus far for putprofline */
1504511Speter double	totime;			/* total time for all routines */
1517174Speter double	printtime;		/* total of time being printed */
1524511Speter double	scale;			/* scale factor converting samples to pc
1534511Speter 				   values: each sample covers scale bytes */
1544511Speter char	*strtab;		/* string table in core */
1554511Speter off_t	ssiz;			/* size of the string table */
1564511Speter struct	exec xbuf;		/* exec header of a.out */
1574722Speter unsigned char	*textspace;		/* text space of a.out in core */
1584511Speter 
1594855Speter     /*
1604855Speter      *	option flags, from a to z.
1614855Speter      */
1627174Speter bool	aflag;				/* suppress static functions */
1637174Speter bool	bflag;				/* blurbs, too */
1647174Speter bool	cflag;				/* discovered call graph, too */
1657174Speter bool	dflag;				/* debugging options */
1667174Speter bool	eflag;				/* specific functions excluded */
1677224Speter bool	Eflag;				/* functions excluded with time */
1687174Speter bool	fflag;				/* specific functions requested */
1697224Speter bool	Fflag;				/* functions requested with time */
17030963Smckusick bool	kflag;				/* arcs to be deleted */
1717174Speter bool	sflag;				/* sum multiple gmon.out files */
1727174Speter bool	zflag;				/* zero time/called functions, too */
1734511Speter 
1744511Speter     /*
1757224Speter      *	structure for various string lists
1767224Speter      */
1777224Speter struct stringlist {
1787224Speter     struct stringlist	*next;
1797224Speter     char		*string;
1807224Speter };
1817224Speter struct stringlist	*elist;
1827224Speter struct stringlist	*Elist;
1837224Speter struct stringlist	*flist;
1847224Speter struct stringlist	*Flist;
18530963Smckusick struct stringlist	*kfromlist;
18630963Smckusick struct stringlist	*ktolist;
1877224Speter 
1887224Speter     /*
1894840Speter      *	function declarations
1904840Speter      */
191*33225Sbostic /*
1924840Speter 		addarc();
193*33225Sbostic */
1944840Speter int		arccmp();
1954511Speter arctype		*arclookup();
196*33225Sbostic /*
1974840Speter 		asgnsamples();
1984855Speter 		printblurb();
1994840Speter 		cyclelink();
2004840Speter 		dfn();
201*33225Sbostic */
2024511Speter bool		dfn_busy();
203*33225Sbostic /*
2044840Speter 		dfn_findcycle();
205*33225Sbostic */
2064840Speter bool		dfn_numbered();
207*33225Sbostic /*
2084840Speter 		dfn_post_visit();
2094840Speter 		dfn_pre_visit();
2104840Speter 		dfn_self_cycle();
211*33225Sbostic */
21216851Smckusick nltype		**doarcs();
213*33225Sbostic /*
2144840Speter 		done();
2154840Speter 		findcalls();
2164840Speter 		flatprofheader();
2174840Speter 		flatprofline();
218*33225Sbostic */
2194844Speter bool		funcsymbol();
220*33225Sbostic /*
2214840Speter 		getnfile();
2224840Speter 		getpfile();
2234840Speter 		getstrtab();
2244840Speter 		getsymtab();
2254840Speter 		gettextspace();
2264840Speter 		gprofheader();
2274840Speter 		gprofline();
2284840Speter 		main();
229*33225Sbostic */
2304840Speter unsigned long	max();
2314840Speter int		membercmp();
2324840Speter unsigned long	min();
2334840Speter nltype		*nllookup();
2344840Speter FILE		*openpfile();
2354840Speter long		operandlength();
2364840Speter operandenum	operandmode();
2374840Speter char		*operandname();
238*33225Sbostic /*
2394840Speter 		printchildren();
2404840Speter 		printcycle();
2414840Speter 		printgprof();
2424840Speter 		printmembers();
2434840Speter 		printname();
2444840Speter 		printparents();
2454840Speter 		printprof();
2464840Speter 		readsamples();
247*33225Sbostic */
2484840Speter unsigned long	reladdr();
249*33225Sbostic /*
2504840Speter 		sortchildren();
2514840Speter 		sortmembers();
2524840Speter 		sortparents();
2534840Speter 		tally();
2544840Speter 		timecmp();
2554840Speter 		topcmp();
256*33225Sbostic */
2574840Speter int		totalcmp();
258*33225Sbostic /*
2594840Speter 		valcmp();
260*33225Sbostic */
2614511Speter 
2624511Speter #define	LESSTHAN	-1
2634511Speter #define	EQUALTO		0
2644511Speter #define	GREATERTHAN	1
2654511Speter 
2664511Speter #define	DFNDEBUG	1
2674511Speter #define	CYCLEDEBUG	2
2684511Speter #define	ARCDEBUG	4
2694511Speter #define	TALLYDEBUG	8
2704511Speter #define	TIMEDEBUG	16
2714511Speter #define	SAMPLEDEBUG	32
2724511Speter #define	AOUTDEBUG	64
27325709Ssam #define	CALLDEBUG	128
2744722Speter #define	LOOKUPDEBUG	256
2757224Speter #define	PROPDEBUG	512
2767224Speter #define	ANYDEBUG	1024
277