xref: /csrg-svn/usr.bin/gprof/gprof.h (revision 52648)
121965Sdist /*
221965Sdist  * Copyright (c) 1983 Regents of the University of California.
334199Sbostic  * All rights reserved.
421965Sdist  *
542683Sbostic  * %sccs.include.redist.c%
634199Sbostic  *
7*52648Smckusick  *	@(#)gprof.h	5.11 (Berkeley) 02/24/92
821965Sdist  */
94511Speter 
104511Speter #include <sys/types.h>
114511Speter #include <sys/stat.h>
124511Speter #include <a.out.h>
1340604Sbostic #include <stdio.h>
1440604Sbostic #include "gmon.h"
154511Speter 
1611799Speter #if vax
1711799Speter #   include "vax.h"
1811799Speter #endif
1911799Speter #if sun
2025709Ssam #   include "sun.h"
2111799Speter #endif
2225709Ssam #if tahoe
2325709Ssam #   include "tahoe.h"
2425709Ssam #endif
2548699Sdonn #if hp300
2648699Sdonn #   include "hp300.h"
2748699Sdonn #endif
2848699Sdonn #if i386
2948699Sdonn #   include "i386.h"
3048699Sdonn #endif
3111799Speter 
3211799Speter 
334511Speter     /*
347129Speter      *	who am i, for error messages.
357129Speter      */
367129Speter char	*whoami;
377129Speter 
387129Speter     /*
397174Speter      * booleans
407174Speter      */
417174Speter typedef int	bool;
427174Speter #define	FALSE	0
437174Speter #define	TRUE	1
447174Speter 
457174Speter     /*
464511Speter      *	ticks per second
474511Speter      */
4810250Speter long	hz;
494511Speter 
5033225Sbostic typedef	u_short UNIT;		/* unit of profiling */
514511Speter char	*a_outname;
524511Speter #define	A_OUTNAME		"a.out"
534511Speter 
544560Speter char	*gmonname;
554560Speter #define	GMONNAME		"gmon.out"
564867Smckusic #define	GMONSUM			"gmon.sum"
5733225Sbostic 
584873Smckusic     /*
594511Speter      *	a constructed arc,
604511Speter      *	    with pointers to the namelist entry of the parent and the child,
614511Speter      *	    a count of how many times this arc was traversed,
624511Speter      *	    and pointers to the next parent of this child and
634511Speter      *		the next child of this parent.
644511Speter      */
654511Speter struct arcstruct {
664511Speter     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
674511Speter     struct nl		*arc_childp;	/* pointer to child's nl entry */
68*52648Smckusick     long		arc_count;	/* num calls from parent to child */
694511Speter     double		arc_time;	/* time inherited along arc */
704511Speter     double		arc_childtime;	/* childtime inherited along arc */
714511Speter     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
724511Speter     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
73*52648Smckusick     struct arcstruct	*arc_next;	/* list of arcs on cycle */
74*52648Smckusick     unsigned short	arc_cyclecnt;	/* num cycles involved in */
75*52648Smckusick     unsigned short	arc_flags;	/* see below */
764511Speter };
774511Speter typedef struct arcstruct	arctype;
784511Speter 
797129Speter     /*
80*52648Smckusick      * arc flags
81*52648Smckusick      */
82*52648Smckusick #define	DEADARC	0x01	/* time should not propagate across the arc */
83*52648Smckusick #define	ONLIST	0x02	/* arc is on list of arcs in cycles */
84*52648Smckusick 
85*52648Smckusick     /*
867129Speter      * The symbol table;
877129Speter      * for each external in the specified file we gather
887129Speter      * its address, the number of calls and compute its share of cpu time.
897129Speter      */
904511Speter struct nl {
917129Speter     char		*name;		/* the name */
927129Speter     unsigned long	value;		/* the pc entry point */
9311799Speter     unsigned long	svalue;		/* entry point aligned to histograms */
947129Speter     double		time;		/* ticks in this routine */
957129Speter     double		childtime;	/* cumulative ticks in children */
967129Speter     long		ncall;		/* how many times called */
97*52648Smckusick     long		npropcall;	/* times called by live arcs */
987129Speter     long		selfcalls;	/* how many calls to self */
997224Speter     double		propfraction;	/* what % of time propagates */
1007224Speter     double		propself;	/* how much self time propagates */
1017224Speter     double		propchild;	/* how much child time propagates */
102*52648Smckusick     short		printflag;	/* should this be printed? */
103*52648Smckusick     short		flags;		/* see below */
1047129Speter     int			index;		/* index in the graph list */
1057129Speter     int			toporder;	/* graph call chain top-sort order */
1067129Speter     int			cycleno;	/* internal number of cycle on */
107*52648Smckusick     int			parentcnt;	/* number of live parent arcs */
1087129Speter     struct nl		*cyclehead;	/* pointer to head of cycle */
1097129Speter     struct nl		*cnext;		/* pointer to next member of cycle */
1107129Speter     arctype		*parents;	/* list of caller arcs */
1117129Speter     arctype		*children;	/* list of callee arcs */
1124511Speter };
1134511Speter typedef struct nl	nltype;
1144511Speter 
1154511Speter nltype	*nl;			/* the whole namelist */
1164511Speter nltype	*npe;			/* the virtual end of the namelist */
1177129Speter int	nname;			/* the number of function names */
1184511Speter 
119*52648Smckusick #define	HASCYCLEXIT	0x08	/* node has arc exiting from cycle */
120*52648Smckusick #define	CYCLEHEAD	0x10	/* node marked as head of a cycle */
121*52648Smckusick #define	VISITED		0x20	/* node visited during a cycle */
122*52648Smckusick 
1234511Speter     /*
124*52648Smckusick      * The cycle list.
125*52648Smckusick      * for each subcycle within an identified cycle, we gather
126*52648Smckusick      * its size and the list of included arcs.
127*52648Smckusick      */
128*52648Smckusick struct cl {
129*52648Smckusick     int		size;		/* length of cycle */
130*52648Smckusick     struct cl	*next;		/* next member of list */
131*52648Smckusick     arctype	*list[1];	/* list of arcs in cycle */
132*52648Smckusick     /* actually longer */
133*52648Smckusick };
134*52648Smckusick typedef struct cl cltype;
135*52648Smckusick 
136*52648Smckusick arctype	*archead;		/* the head of arcs in current cycle list */
137*52648Smckusick cltype	*cyclehead;		/* the head of the list */
138*52648Smckusick int	cyclecnt;		/* the number of cycles found */
139*52648Smckusick #define	CYCLEMAX	100	/* maximum cycles before cutting one of them */
140*52648Smckusick 
141*52648Smckusick     /*
1424511Speter      *	flag which marks a nl entry as topologically ``busy''
14310284Speter      *	flag which marks a nl entry as topologically ``not_numbered''
1444511Speter      */
1454511Speter #define	DFN_BUSY	-1
14610284Speter #define	DFN_NAN		0
1474511Speter 
1484511Speter     /*
1497129Speter      *	namelist entries for cycle headers.
1507129Speter      *	the number of discovered cycles.
1514511Speter      */
1527129Speter nltype	*cyclenl;		/* cycle header namelist */
1537129Speter int	ncycle;			/* number of cycles discovered */
1544511Speter 
1557129Speter     /*
1567129Speter      * The header on the gmon.out file.
1577129Speter      * gmon.out consists of one of these headers,
1587129Speter      * and then an array of ncnt samples
1597129Speter      * representing the discretized program counter values.
1607129Speter      *	this should be a struct phdr, but since everything is done
1617129Speter      *	as UNITs, this is in UNITs too.
1627129Speter      */
1634511Speter struct hdr {
1647129Speter     UNIT	*lowpc;
1657129Speter     UNIT	*highpc;
1667129Speter     int	ncnt;
1674511Speter };
1684511Speter 
1694511Speter struct hdr	h;
1704511Speter 
1714511Speter int	debug;
1724511Speter 
1737129Speter     /*
1747129Speter      * Each discretized pc sample has
1757129Speter      * a count of the number of samples in its range
1767129Speter      */
17733225Sbostic UNIT	*samples;
1784511Speter 
1794751Speter unsigned long	s_lowpc;	/* lowpc from the profile file */
1804751Speter unsigned long	s_highpc;	/* highpc from the profile file */
1814751Speter unsigned lowpc, highpc;		/* range profiled, in UNIT's */
1824511Speter unsigned sampbytes;		/* number of bytes of samples */
1834511Speter int	nsamples;		/* number of samples */
1844511Speter double	actime;			/* accumulated time thus far for putprofline */
1854511Speter double	totime;			/* total time for all routines */
1867174Speter double	printtime;		/* total of time being printed */
1874511Speter double	scale;			/* scale factor converting samples to pc
1884511Speter 				   values: each sample covers scale bytes */
1894511Speter char	*strtab;		/* string table in core */
1904511Speter off_t	ssiz;			/* size of the string table */
1914511Speter struct	exec xbuf;		/* exec header of a.out */
192*52648Smckusick unsigned char	*textspace;	/* text space of a.out in core */
193*52648Smckusick int	cyclethreshold;		/* with -C, minimum cycle size to ignore */
1944511Speter 
1954855Speter     /*
1964855Speter      *	option flags, from a to z.
1974855Speter      */
1987174Speter bool	aflag;				/* suppress static functions */
1997174Speter bool	bflag;				/* blurbs, too */
2007174Speter bool	cflag;				/* discovered call graph, too */
201*52648Smckusick bool	Cflag;				/* find cut-set to eliminate cycles */
2027174Speter bool	dflag;				/* debugging options */
2037174Speter bool	eflag;				/* specific functions excluded */
2047224Speter bool	Eflag;				/* functions excluded with time */
2057174Speter bool	fflag;				/* specific functions requested */
2067224Speter bool	Fflag;				/* functions requested with time */
20730963Smckusick bool	kflag;				/* arcs to be deleted */
2087174Speter bool	sflag;				/* sum multiple gmon.out files */
2097174Speter bool	zflag;				/* zero time/called functions, too */
2104511Speter 
2114511Speter     /*
2127224Speter      *	structure for various string lists
2137224Speter      */
2147224Speter struct stringlist {
2157224Speter     struct stringlist	*next;
2167224Speter     char		*string;
2177224Speter };
2187224Speter struct stringlist	*elist;
2197224Speter struct stringlist	*Elist;
2207224Speter struct stringlist	*flist;
2217224Speter struct stringlist	*Flist;
22230963Smckusick struct stringlist	*kfromlist;
22330963Smckusick struct stringlist	*ktolist;
2247224Speter 
2257224Speter     /*
2264840Speter      *	function declarations
2274840Speter      */
22833225Sbostic /*
2294840Speter 		addarc();
23033225Sbostic */
2314840Speter int		arccmp();
2324511Speter arctype		*arclookup();
23333225Sbostic /*
2344840Speter 		asgnsamples();
2354855Speter 		printblurb();
2364840Speter 		cyclelink();
2374840Speter 		dfn();
23833225Sbostic */
2394511Speter bool		dfn_busy();
24033225Sbostic /*
2414840Speter 		dfn_findcycle();
24233225Sbostic */
2434840Speter bool		dfn_numbered();
24433225Sbostic /*
2454840Speter 		dfn_post_visit();
2464840Speter 		dfn_pre_visit();
2474840Speter 		dfn_self_cycle();
24833225Sbostic */
24916851Smckusick nltype		**doarcs();
25033225Sbostic /*
2514840Speter 		done();
2524840Speter 		findcalls();
2534840Speter 		flatprofheader();
2544840Speter 		flatprofline();
25533225Sbostic */
2564844Speter bool		funcsymbol();
25733225Sbostic /*
2584840Speter 		getnfile();
2594840Speter 		getpfile();
2604840Speter 		getstrtab();
2614840Speter 		getsymtab();
2624840Speter 		gettextspace();
2634840Speter 		gprofheader();
2644840Speter 		gprofline();
2654840Speter 		main();
26633225Sbostic */
2674840Speter unsigned long	max();
2684840Speter int		membercmp();
2694840Speter unsigned long	min();
2704840Speter nltype		*nllookup();
2714840Speter FILE		*openpfile();
2724840Speter long		operandlength();
2734840Speter operandenum	operandmode();
2744840Speter char		*operandname();
27533225Sbostic /*
2764840Speter 		printchildren();
2774840Speter 		printcycle();
2784840Speter 		printgprof();
2794840Speter 		printmembers();
2804840Speter 		printname();
2814840Speter 		printparents();
2824840Speter 		printprof();
2834840Speter 		readsamples();
28433225Sbostic */
2854840Speter unsigned long	reladdr();
28633225Sbostic /*
2874840Speter 		sortchildren();
2884840Speter 		sortmembers();
2894840Speter 		sortparents();
2904840Speter 		tally();
2914840Speter 		timecmp();
2924840Speter 		topcmp();
29333225Sbostic */
2944840Speter int		totalcmp();
29533225Sbostic /*
2964840Speter 		valcmp();
29733225Sbostic */
2984511Speter 
2994511Speter #define	LESSTHAN	-1
3004511Speter #define	EQUALTO		0
3014511Speter #define	GREATERTHAN	1
3024511Speter 
3034511Speter #define	DFNDEBUG	1
3044511Speter #define	CYCLEDEBUG	2
3054511Speter #define	ARCDEBUG	4
3064511Speter #define	TALLYDEBUG	8
3074511Speter #define	TIMEDEBUG	16
3084511Speter #define	SAMPLEDEBUG	32
3094511Speter #define	AOUTDEBUG	64
31025709Ssam #define	CALLDEBUG	128
3114722Speter #define	LOOKUPDEBUG	256
3127224Speter #define	PROPDEBUG	512
313*52648Smckusick #define	BREAKCYCLE	1024
314*52648Smckusick #define	SUBCYCLELIST	2048
315*52648Smckusick #define	ANYDEBUG	4096
316