xref: /csrg-svn/usr.bin/gprof/gprof.h (revision 42683)
121965Sdist /*
221965Sdist  * Copyright (c) 1983 Regents of the University of California.
334199Sbostic  * All rights reserved.
421965Sdist  *
5*42683Sbostic  * %sccs.include.redist.c%
634199Sbostic  *
7*42683Sbostic  *	@(#)gprof.h	5.9 (Berkeley) 06/01/90
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
2511799Speter 
2611799Speter 
274511Speter     /*
287129Speter      *	who am i, for error messages.
297129Speter      */
307129Speter char	*whoami;
317129Speter 
327129Speter     /*
337174Speter      * booleans
347174Speter      */
357174Speter typedef int	bool;
367174Speter #define	FALSE	0
377174Speter #define	TRUE	1
387174Speter 
397174Speter     /*
404511Speter      *	ticks per second
414511Speter      */
4210250Speter long	hz;
434511Speter 
4433225Sbostic typedef	u_short UNIT;		/* unit of profiling */
454511Speter char	*a_outname;
464511Speter #define	A_OUTNAME		"a.out"
474511Speter 
484560Speter char	*gmonname;
494560Speter #define	GMONNAME		"gmon.out"
504867Smckusic #define	GMONSUM			"gmon.sum"
5133225Sbostic 
524873Smckusic     /*
534511Speter      *	a constructed arc,
544511Speter      *	    with pointers to the namelist entry of the parent and the child,
554511Speter      *	    a count of how many times this arc was traversed,
564511Speter      *	    and pointers to the next parent of this child and
574511Speter      *		the next child of this parent.
584511Speter      */
594511Speter struct arcstruct {
604511Speter     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
614511Speter     struct nl		*arc_childp;	/* pointer to child's nl entry */
624511Speter     long		arc_count;	/* how calls from parent to child */
634511Speter     double		arc_time;	/* time inherited along arc */
644511Speter     double		arc_childtime;	/* childtime inherited along arc */
654511Speter     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
664511Speter     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
674511Speter };
684511Speter typedef struct arcstruct	arctype;
694511Speter 
707129Speter     /*
717129Speter      * The symbol table;
727129Speter      * for each external in the specified file we gather
737129Speter      * its address, the number of calls and compute its share of cpu time.
747129Speter      */
754511Speter struct nl {
767129Speter     char		*name;		/* the name */
777129Speter     unsigned long	value;		/* the pc entry point */
7811799Speter     unsigned long	svalue;		/* entry point aligned to histograms */
797129Speter     double		time;		/* ticks in this routine */
807129Speter     double		childtime;	/* cumulative ticks in children */
817129Speter     long		ncall;		/* how many times called */
827129Speter     long		selfcalls;	/* how many calls to self */
837224Speter     double		propfraction;	/* what % of time propagates */
847224Speter     double		propself;	/* how much self time propagates */
857224Speter     double		propchild;	/* how much child time propagates */
867174Speter     bool		printflag;	/* should this be printed? */
877129Speter     int			index;		/* index in the graph list */
887129Speter     int			toporder;	/* graph call chain top-sort order */
897129Speter     int			cycleno;	/* internal number of cycle on */
907129Speter     struct nl		*cyclehead;	/* pointer to head of cycle */
917129Speter     struct nl		*cnext;		/* pointer to next member of cycle */
927129Speter     arctype		*parents;	/* list of caller arcs */
937129Speter     arctype		*children;	/* list of callee arcs */
944511Speter };
954511Speter typedef struct nl	nltype;
964511Speter 
974511Speter nltype	*nl;			/* the whole namelist */
984511Speter nltype	*npe;			/* the virtual end of the namelist */
997129Speter int	nname;			/* the number of function names */
1004511Speter 
1014511Speter     /*
1024511Speter      *	flag which marks a nl entry as topologically ``busy''
10310284Speter      *	flag which marks a nl entry as topologically ``not_numbered''
1044511Speter      */
1054511Speter #define	DFN_BUSY	-1
10610284Speter #define	DFN_NAN		0
1074511Speter 
1084511Speter     /*
1097129Speter      *	namelist entries for cycle headers.
1107129Speter      *	the number of discovered cycles.
1114511Speter      */
1127129Speter nltype	*cyclenl;		/* cycle header namelist */
1137129Speter int	ncycle;			/* number of cycles discovered */
1144511Speter 
1157129Speter     /*
1167129Speter      * The header on the gmon.out file.
1177129Speter      * gmon.out consists of one of these headers,
1187129Speter      * and then an array of ncnt samples
1197129Speter      * representing the discretized program counter values.
1207129Speter      *	this should be a struct phdr, but since everything is done
1217129Speter      *	as UNITs, this is in UNITs too.
1227129Speter      */
1234511Speter struct hdr {
1247129Speter     UNIT	*lowpc;
1257129Speter     UNIT	*highpc;
1267129Speter     int	ncnt;
1274511Speter };
1284511Speter 
1294511Speter struct hdr	h;
1304511Speter 
1314511Speter int	debug;
1324511Speter 
1337129Speter     /*
1347129Speter      * Each discretized pc sample has
1357129Speter      * a count of the number of samples in its range
1367129Speter      */
13733225Sbostic UNIT	*samples;
1384511Speter 
1394751Speter unsigned long	s_lowpc;	/* lowpc from the profile file */
1404751Speter unsigned long	s_highpc;	/* highpc from the profile file */
1414751Speter unsigned lowpc, highpc;		/* range profiled, in UNIT's */
1424511Speter unsigned sampbytes;		/* number of bytes of samples */
1434511Speter int	nsamples;		/* number of samples */
1444511Speter double	actime;			/* accumulated time thus far for putprofline */
1454511Speter double	totime;			/* total time for all routines */
1467174Speter double	printtime;		/* total of time being printed */
1474511Speter double	scale;			/* scale factor converting samples to pc
1484511Speter 				   values: each sample covers scale bytes */
1494511Speter char	*strtab;		/* string table in core */
1504511Speter off_t	ssiz;			/* size of the string table */
1514511Speter struct	exec xbuf;		/* exec header of a.out */
1524722Speter unsigned char	*textspace;		/* text space of a.out in core */
1534511Speter 
1544855Speter     /*
1554855Speter      *	option flags, from a to z.
1564855Speter      */
1577174Speter bool	aflag;				/* suppress static functions */
1587174Speter bool	bflag;				/* blurbs, too */
1597174Speter bool	cflag;				/* discovered call graph, too */
1607174Speter bool	dflag;				/* debugging options */
1617174Speter bool	eflag;				/* specific functions excluded */
1627224Speter bool	Eflag;				/* functions excluded with time */
1637174Speter bool	fflag;				/* specific functions requested */
1647224Speter bool	Fflag;				/* functions requested with time */
16530963Smckusick bool	kflag;				/* arcs to be deleted */
1667174Speter bool	sflag;				/* sum multiple gmon.out files */
1677174Speter bool	zflag;				/* zero time/called functions, too */
1684511Speter 
1694511Speter     /*
1707224Speter      *	structure for various string lists
1717224Speter      */
1727224Speter struct stringlist {
1737224Speter     struct stringlist	*next;
1747224Speter     char		*string;
1757224Speter };
1767224Speter struct stringlist	*elist;
1777224Speter struct stringlist	*Elist;
1787224Speter struct stringlist	*flist;
1797224Speter struct stringlist	*Flist;
18030963Smckusick struct stringlist	*kfromlist;
18130963Smckusick struct stringlist	*ktolist;
1827224Speter 
1837224Speter     /*
1844840Speter      *	function declarations
1854840Speter      */
18633225Sbostic /*
1874840Speter 		addarc();
18833225Sbostic */
1894840Speter int		arccmp();
1904511Speter arctype		*arclookup();
19133225Sbostic /*
1924840Speter 		asgnsamples();
1934855Speter 		printblurb();
1944840Speter 		cyclelink();
1954840Speter 		dfn();
19633225Sbostic */
1974511Speter bool		dfn_busy();
19833225Sbostic /*
1994840Speter 		dfn_findcycle();
20033225Sbostic */
2014840Speter bool		dfn_numbered();
20233225Sbostic /*
2034840Speter 		dfn_post_visit();
2044840Speter 		dfn_pre_visit();
2054840Speter 		dfn_self_cycle();
20633225Sbostic */
20716851Smckusick nltype		**doarcs();
20833225Sbostic /*
2094840Speter 		done();
2104840Speter 		findcalls();
2114840Speter 		flatprofheader();
2124840Speter 		flatprofline();
21333225Sbostic */
2144844Speter bool		funcsymbol();
21533225Sbostic /*
2164840Speter 		getnfile();
2174840Speter 		getpfile();
2184840Speter 		getstrtab();
2194840Speter 		getsymtab();
2204840Speter 		gettextspace();
2214840Speter 		gprofheader();
2224840Speter 		gprofline();
2234840Speter 		main();
22433225Sbostic */
2254840Speter unsigned long	max();
2264840Speter int		membercmp();
2274840Speter unsigned long	min();
2284840Speter nltype		*nllookup();
2294840Speter FILE		*openpfile();
2304840Speter long		operandlength();
2314840Speter operandenum	operandmode();
2324840Speter char		*operandname();
23333225Sbostic /*
2344840Speter 		printchildren();
2354840Speter 		printcycle();
2364840Speter 		printgprof();
2374840Speter 		printmembers();
2384840Speter 		printname();
2394840Speter 		printparents();
2404840Speter 		printprof();
2414840Speter 		readsamples();
24233225Sbostic */
2434840Speter unsigned long	reladdr();
24433225Sbostic /*
2454840Speter 		sortchildren();
2464840Speter 		sortmembers();
2474840Speter 		sortparents();
2484840Speter 		tally();
2494840Speter 		timecmp();
2504840Speter 		topcmp();
25133225Sbostic */
2524840Speter int		totalcmp();
25333225Sbostic /*
2544840Speter 		valcmp();
25533225Sbostic */
2564511Speter 
2574511Speter #define	LESSTHAN	-1
2584511Speter #define	EQUALTO		0
2594511Speter #define	GREATERTHAN	1
2604511Speter 
2614511Speter #define	DFNDEBUG	1
2624511Speter #define	CYCLEDEBUG	2
2634511Speter #define	ARCDEBUG	4
2644511Speter #define	TALLYDEBUG	8
2654511Speter #define	TIMEDEBUG	16
2664511Speter #define	SAMPLEDEBUG	32
2674511Speter #define	AOUTDEBUG	64
26825709Ssam #define	CALLDEBUG	128
2694722Speter #define	LOOKUPDEBUG	256
2707224Speter #define	PROPDEBUG	512
2717224Speter #define	ANYDEBUG	1024
272