xref: /csrg-svn/usr.bin/gprof/gprof.h (revision 34199)
121965Sdist /*
221965Sdist  * Copyright (c) 1983 Regents of the University of California.
3*34199Sbostic  * All rights reserved.
421965Sdist  *
5*34199Sbostic  * Redistribution and use in source and binary forms are permitted
6*34199Sbostic  * provided that this notice is preserved and that due credit is given
7*34199Sbostic  * to the University of California at Berkeley. The name of the University
8*34199Sbostic  * may not be used to endorse or promote products derived from this
9*34199Sbostic  * software without specific prior written permission. This software
10*34199Sbostic  * is provided ``as is'' without express or implied warranty.
11*34199Sbostic  *
12*34199Sbostic  *	@(#)gprof.h	5.5 (Berkeley) 05/05/88
1321965Sdist  */
144511Speter 
154511Speter #include <stdio.h>
164511Speter #include <sys/types.h>
174511Speter #include <sys/stat.h>
184511Speter #include <a.out.h>
194870Smckusic #include "gcrt0.h"
204511Speter 
2111799Speter #if vax
2211799Speter #   include "vax.h"
2311799Speter #endif
2411799Speter #if sun
2525709Ssam #   include "sun.h"
2611799Speter #endif
2725709Ssam #if tahoe
2825709Ssam #   include "tahoe.h"
2925709Ssam #endif
3011799Speter 
3111799Speter 
324511Speter     /*
337129Speter      *	who am i, for error messages.
347129Speter      */
357129Speter char	*whoami;
367129Speter 
377129Speter     /*
387174Speter      * booleans
397174Speter      */
407174Speter typedef int	bool;
417174Speter #define	FALSE	0
427174Speter #define	TRUE	1
437174Speter 
447174Speter     /*
454511Speter      *	ticks per second
464511Speter      */
4710250Speter long	hz;
484511Speter 
4933225Sbostic typedef	u_short UNIT;		/* unit of profiling */
504511Speter char	*a_outname;
514511Speter #define	A_OUTNAME		"a.out"
524511Speter 
534560Speter char	*gmonname;
544560Speter #define	GMONNAME		"gmon.out"
554867Smckusic #define	GMONSUM			"gmon.sum"
5633225Sbostic 
574873Smckusic     /*
5810286Speter      *	blurbs on the flat and graph profiles.
594873Smckusic      */
6016862Smckusick #define	FLAT_BLURB	"/usr/lib/gprof.flat"
6116862Smckusick #define	CALLG_BLURB	"/usr/lib/gprof.callg"
624511Speter 
634511Speter     /*
644511Speter      *	a constructed arc,
654511Speter      *	    with pointers to the namelist entry of the parent and the child,
664511Speter      *	    a count of how many times this arc was traversed,
674511Speter      *	    and pointers to the next parent of this child and
684511Speter      *		the next child of this parent.
694511Speter      */
704511Speter struct arcstruct {
714511Speter     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
724511Speter     struct nl		*arc_childp;	/* pointer to child's nl entry */
734511Speter     long		arc_count;	/* how calls from parent to child */
744511Speter     double		arc_time;	/* time inherited along arc */
754511Speter     double		arc_childtime;	/* childtime inherited along arc */
764511Speter     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
774511Speter     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
784511Speter };
794511Speter typedef struct arcstruct	arctype;
804511Speter 
817129Speter     /*
827129Speter      * The symbol table;
837129Speter      * for each external in the specified file we gather
847129Speter      * its address, the number of calls and compute its share of cpu time.
857129Speter      */
864511Speter struct nl {
877129Speter     char		*name;		/* the name */
887129Speter     unsigned long	value;		/* the pc entry point */
8911799Speter     unsigned long	svalue;		/* entry point aligned to histograms */
907129Speter     double		time;		/* ticks in this routine */
917129Speter     double		childtime;	/* cumulative ticks in children */
927129Speter     long		ncall;		/* how many times called */
937129Speter     long		selfcalls;	/* how many calls to self */
947224Speter     double		propfraction;	/* what % of time propagates */
957224Speter     double		propself;	/* how much self time propagates */
967224Speter     double		propchild;	/* how much child time propagates */
977174Speter     bool		printflag;	/* should this be printed? */
987129Speter     int			index;		/* index in the graph list */
997129Speter     int			toporder;	/* graph call chain top-sort order */
1007129Speter     int			cycleno;	/* internal number of cycle on */
1017129Speter     struct nl		*cyclehead;	/* pointer to head of cycle */
1027129Speter     struct nl		*cnext;		/* pointer to next member of cycle */
1037129Speter     arctype		*parents;	/* list of caller arcs */
1047129Speter     arctype		*children;	/* list of callee arcs */
1054511Speter };
1064511Speter typedef struct nl	nltype;
1074511Speter 
1084511Speter nltype	*nl;			/* the whole namelist */
1094511Speter nltype	*npe;			/* the virtual end of the namelist */
1107129Speter int	nname;			/* the number of function names */
1114511Speter 
1124511Speter     /*
1134511Speter      *	flag which marks a nl entry as topologically ``busy''
11410284Speter      *	flag which marks a nl entry as topologically ``not_numbered''
1154511Speter      */
1164511Speter #define	DFN_BUSY	-1
11710284Speter #define	DFN_NAN		0
1184511Speter 
1194511Speter     /*
1207129Speter      *	namelist entries for cycle headers.
1217129Speter      *	the number of discovered cycles.
1224511Speter      */
1237129Speter nltype	*cyclenl;		/* cycle header namelist */
1247129Speter int	ncycle;			/* number of cycles discovered */
1254511Speter 
1267129Speter     /*
1277129Speter      * The header on the gmon.out file.
1287129Speter      * gmon.out consists of one of these headers,
1297129Speter      * and then an array of ncnt samples
1307129Speter      * representing the discretized program counter values.
1317129Speter      *	this should be a struct phdr, but since everything is done
1327129Speter      *	as UNITs, this is in UNITs too.
1337129Speter      */
1344511Speter struct hdr {
1357129Speter     UNIT	*lowpc;
1367129Speter     UNIT	*highpc;
1377129Speter     int	ncnt;
1384511Speter };
1394511Speter 
1404511Speter struct hdr	h;
1414511Speter 
1424511Speter int	debug;
1434511Speter 
1447129Speter     /*
1457129Speter      * Each discretized pc sample has
1467129Speter      * a count of the number of samples in its range
1477129Speter      */
14833225Sbostic UNIT	*samples;
1494511Speter 
1504751Speter unsigned long	s_lowpc;	/* lowpc from the profile file */
1514751Speter unsigned long	s_highpc;	/* highpc from the profile file */
1524751Speter unsigned lowpc, highpc;		/* range profiled, in UNIT's */
1534511Speter unsigned sampbytes;		/* number of bytes of samples */
1544511Speter int	nsamples;		/* number of samples */
1554511Speter double	actime;			/* accumulated time thus far for putprofline */
1564511Speter double	totime;			/* total time for all routines */
1577174Speter double	printtime;		/* total of time being printed */
1584511Speter double	scale;			/* scale factor converting samples to pc
1594511Speter 				   values: each sample covers scale bytes */
1604511Speter char	*strtab;		/* string table in core */
1614511Speter off_t	ssiz;			/* size of the string table */
1624511Speter struct	exec xbuf;		/* exec header of a.out */
1634722Speter unsigned char	*textspace;		/* text space of a.out in core */
1644511Speter 
1654855Speter     /*
1664855Speter      *	option flags, from a to z.
1674855Speter      */
1687174Speter bool	aflag;				/* suppress static functions */
1697174Speter bool	bflag;				/* blurbs, too */
1707174Speter bool	cflag;				/* discovered call graph, too */
1717174Speter bool	dflag;				/* debugging options */
1727174Speter bool	eflag;				/* specific functions excluded */
1737224Speter bool	Eflag;				/* functions excluded with time */
1747174Speter bool	fflag;				/* specific functions requested */
1757224Speter bool	Fflag;				/* functions requested with time */
17630963Smckusick bool	kflag;				/* arcs to be deleted */
1777174Speter bool	sflag;				/* sum multiple gmon.out files */
1787174Speter bool	zflag;				/* zero time/called functions, too */
1794511Speter 
1804511Speter     /*
1817224Speter      *	structure for various string lists
1827224Speter      */
1837224Speter struct stringlist {
1847224Speter     struct stringlist	*next;
1857224Speter     char		*string;
1867224Speter };
1877224Speter struct stringlist	*elist;
1887224Speter struct stringlist	*Elist;
1897224Speter struct stringlist	*flist;
1907224Speter struct stringlist	*Flist;
19130963Smckusick struct stringlist	*kfromlist;
19230963Smckusick struct stringlist	*ktolist;
1937224Speter 
1947224Speter     /*
1954840Speter      *	function declarations
1964840Speter      */
19733225Sbostic /*
1984840Speter 		addarc();
19933225Sbostic */
2004840Speter int		arccmp();
2014511Speter arctype		*arclookup();
20233225Sbostic /*
2034840Speter 		asgnsamples();
2044855Speter 		printblurb();
2054840Speter 		cyclelink();
2064840Speter 		dfn();
20733225Sbostic */
2084511Speter bool		dfn_busy();
20933225Sbostic /*
2104840Speter 		dfn_findcycle();
21133225Sbostic */
2124840Speter bool		dfn_numbered();
21333225Sbostic /*
2144840Speter 		dfn_post_visit();
2154840Speter 		dfn_pre_visit();
2164840Speter 		dfn_self_cycle();
21733225Sbostic */
21816851Smckusick nltype		**doarcs();
21933225Sbostic /*
2204840Speter 		done();
2214840Speter 		findcalls();
2224840Speter 		flatprofheader();
2234840Speter 		flatprofline();
22433225Sbostic */
2254844Speter bool		funcsymbol();
22633225Sbostic /*
2274840Speter 		getnfile();
2284840Speter 		getpfile();
2294840Speter 		getstrtab();
2304840Speter 		getsymtab();
2314840Speter 		gettextspace();
2324840Speter 		gprofheader();
2334840Speter 		gprofline();
2344840Speter 		main();
23533225Sbostic */
2364840Speter unsigned long	max();
2374840Speter int		membercmp();
2384840Speter unsigned long	min();
2394840Speter nltype		*nllookup();
2404840Speter FILE		*openpfile();
2414840Speter long		operandlength();
2424840Speter operandenum	operandmode();
2434840Speter char		*operandname();
24433225Sbostic /*
2454840Speter 		printchildren();
2464840Speter 		printcycle();
2474840Speter 		printgprof();
2484840Speter 		printmembers();
2494840Speter 		printname();
2504840Speter 		printparents();
2514840Speter 		printprof();
2524840Speter 		readsamples();
25333225Sbostic */
2544840Speter unsigned long	reladdr();
25533225Sbostic /*
2564840Speter 		sortchildren();
2574840Speter 		sortmembers();
2584840Speter 		sortparents();
2594840Speter 		tally();
2604840Speter 		timecmp();
2614840Speter 		topcmp();
26233225Sbostic */
2634840Speter int		totalcmp();
26433225Sbostic /*
2654840Speter 		valcmp();
26633225Sbostic */
2674511Speter 
2684511Speter #define	LESSTHAN	-1
2694511Speter #define	EQUALTO		0
2704511Speter #define	GREATERTHAN	1
2714511Speter 
2724511Speter #define	DFNDEBUG	1
2734511Speter #define	CYCLEDEBUG	2
2744511Speter #define	ARCDEBUG	4
2754511Speter #define	TALLYDEBUG	8
2764511Speter #define	TIMEDEBUG	16
2774511Speter #define	SAMPLEDEBUG	32
2784511Speter #define	AOUTDEBUG	64
27925709Ssam #define	CALLDEBUG	128
2804722Speter #define	LOOKUPDEBUG	256
2817224Speter #define	PROPDEBUG	512
2827224Speter #define	ANYDEBUG	1024
283