xref: /csrg-svn/usr.bin/gprof/gprof.h (revision 40604)
121965Sdist /*
221965Sdist  * Copyright (c) 1983 Regents of the University of California.
334199Sbostic  * All rights reserved.
421965Sdist  *
534199Sbostic  * Redistribution and use in source and binary forms are permitted
634881Sbostic  * provided that the above copyright notice and this paragraph are
734881Sbostic  * duplicated in all such forms and that any documentation,
834881Sbostic  * advertising materials, and other materials related to such
934881Sbostic  * distribution and use acknowledge that the software was developed
1034881Sbostic  * by the University of California, Berkeley.  The name of the
1134881Sbostic  * University may not be used to endorse or promote products derived
1234881Sbostic  * from this software without specific prior written permission.
1334881Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434881Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534881Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1634199Sbostic  *
17*40604Sbostic  *	@(#)gprof.h	5.8 (Berkeley) 03/23/90
1821965Sdist  */
194511Speter 
204511Speter #include <sys/types.h>
214511Speter #include <sys/stat.h>
224511Speter #include <a.out.h>
23*40604Sbostic #include <stdio.h>
24*40604Sbostic #include "gmon.h"
254511Speter 
2611799Speter #if vax
2711799Speter #   include "vax.h"
2811799Speter #endif
2911799Speter #if sun
3025709Ssam #   include "sun.h"
3111799Speter #endif
3225709Ssam #if tahoe
3325709Ssam #   include "tahoe.h"
3425709Ssam #endif
3511799Speter 
3611799Speter 
374511Speter     /*
387129Speter      *	who am i, for error messages.
397129Speter      */
407129Speter char	*whoami;
417129Speter 
427129Speter     /*
437174Speter      * booleans
447174Speter      */
457174Speter typedef int	bool;
467174Speter #define	FALSE	0
477174Speter #define	TRUE	1
487174Speter 
497174Speter     /*
504511Speter      *	ticks per second
514511Speter      */
5210250Speter long	hz;
534511Speter 
5433225Sbostic typedef	u_short UNIT;		/* unit of profiling */
554511Speter char	*a_outname;
564511Speter #define	A_OUTNAME		"a.out"
574511Speter 
584560Speter char	*gmonname;
594560Speter #define	GMONNAME		"gmon.out"
604867Smckusic #define	GMONSUM			"gmon.sum"
6133225Sbostic 
624873Smckusic     /*
634511Speter      *	a constructed arc,
644511Speter      *	    with pointers to the namelist entry of the parent and the child,
654511Speter      *	    a count of how many times this arc was traversed,
664511Speter      *	    and pointers to the next parent of this child and
674511Speter      *		the next child of this parent.
684511Speter      */
694511Speter struct arcstruct {
704511Speter     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
714511Speter     struct nl		*arc_childp;	/* pointer to child's nl entry */
724511Speter     long		arc_count;	/* how calls from parent to child */
734511Speter     double		arc_time;	/* time inherited along arc */
744511Speter     double		arc_childtime;	/* childtime inherited along arc */
754511Speter     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
764511Speter     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
774511Speter };
784511Speter typedef struct arcstruct	arctype;
794511Speter 
807129Speter     /*
817129Speter      * The symbol table;
827129Speter      * for each external in the specified file we gather
837129Speter      * its address, the number of calls and compute its share of cpu time.
847129Speter      */
854511Speter struct nl {
867129Speter     char		*name;		/* the name */
877129Speter     unsigned long	value;		/* the pc entry point */
8811799Speter     unsigned long	svalue;		/* entry point aligned to histograms */
897129Speter     double		time;		/* ticks in this routine */
907129Speter     double		childtime;	/* cumulative ticks in children */
917129Speter     long		ncall;		/* how many times called */
927129Speter     long		selfcalls;	/* how many calls to self */
937224Speter     double		propfraction;	/* what % of time propagates */
947224Speter     double		propself;	/* how much self time propagates */
957224Speter     double		propchild;	/* how much child time propagates */
967174Speter     bool		printflag;	/* should this be printed? */
977129Speter     int			index;		/* index in the graph list */
987129Speter     int			toporder;	/* graph call chain top-sort order */
997129Speter     int			cycleno;	/* internal number of cycle on */
1007129Speter     struct nl		*cyclehead;	/* pointer to head of cycle */
1017129Speter     struct nl		*cnext;		/* pointer to next member of cycle */
1027129Speter     arctype		*parents;	/* list of caller arcs */
1037129Speter     arctype		*children;	/* list of callee arcs */
1044511Speter };
1054511Speter typedef struct nl	nltype;
1064511Speter 
1074511Speter nltype	*nl;			/* the whole namelist */
1084511Speter nltype	*npe;			/* the virtual end of the namelist */
1097129Speter int	nname;			/* the number of function names */
1104511Speter 
1114511Speter     /*
1124511Speter      *	flag which marks a nl entry as topologically ``busy''
11310284Speter      *	flag which marks a nl entry as topologically ``not_numbered''
1144511Speter      */
1154511Speter #define	DFN_BUSY	-1
11610284Speter #define	DFN_NAN		0
1174511Speter 
1184511Speter     /*
1197129Speter      *	namelist entries for cycle headers.
1207129Speter      *	the number of discovered cycles.
1214511Speter      */
1227129Speter nltype	*cyclenl;		/* cycle header namelist */
1237129Speter int	ncycle;			/* number of cycles discovered */
1244511Speter 
1257129Speter     /*
1267129Speter      * The header on the gmon.out file.
1277129Speter      * gmon.out consists of one of these headers,
1287129Speter      * and then an array of ncnt samples
1297129Speter      * representing the discretized program counter values.
1307129Speter      *	this should be a struct phdr, but since everything is done
1317129Speter      *	as UNITs, this is in UNITs too.
1327129Speter      */
1334511Speter struct hdr {
1347129Speter     UNIT	*lowpc;
1357129Speter     UNIT	*highpc;
1367129Speter     int	ncnt;
1374511Speter };
1384511Speter 
1394511Speter struct hdr	h;
1404511Speter 
1414511Speter int	debug;
1424511Speter 
1437129Speter     /*
1447129Speter      * Each discretized pc sample has
1457129Speter      * a count of the number of samples in its range
1467129Speter      */
14733225Sbostic UNIT	*samples;
1484511Speter 
1494751Speter unsigned long	s_lowpc;	/* lowpc from the profile file */
1504751Speter unsigned long	s_highpc;	/* highpc from the profile file */
1514751Speter unsigned lowpc, highpc;		/* range profiled, in UNIT's */
1524511Speter unsigned sampbytes;		/* number of bytes of samples */
1534511Speter int	nsamples;		/* number of samples */
1544511Speter double	actime;			/* accumulated time thus far for putprofline */
1554511Speter double	totime;			/* total time for all routines */
1567174Speter double	printtime;		/* total of time being printed */
1574511Speter double	scale;			/* scale factor converting samples to pc
1584511Speter 				   values: each sample covers scale bytes */
1594511Speter char	*strtab;		/* string table in core */
1604511Speter off_t	ssiz;			/* size of the string table */
1614511Speter struct	exec xbuf;		/* exec header of a.out */
1624722Speter unsigned char	*textspace;		/* text space of a.out in core */
1634511Speter 
1644855Speter     /*
1654855Speter      *	option flags, from a to z.
1664855Speter      */
1677174Speter bool	aflag;				/* suppress static functions */
1687174Speter bool	bflag;				/* blurbs, too */
1697174Speter bool	cflag;				/* discovered call graph, too */
1707174Speter bool	dflag;				/* debugging options */
1717174Speter bool	eflag;				/* specific functions excluded */
1727224Speter bool	Eflag;				/* functions excluded with time */
1737174Speter bool	fflag;				/* specific functions requested */
1747224Speter bool	Fflag;				/* functions requested with time */
17530963Smckusick bool	kflag;				/* arcs to be deleted */
1767174Speter bool	sflag;				/* sum multiple gmon.out files */
1777174Speter bool	zflag;				/* zero time/called functions, too */
1784511Speter 
1794511Speter     /*
1807224Speter      *	structure for various string lists
1817224Speter      */
1827224Speter struct stringlist {
1837224Speter     struct stringlist	*next;
1847224Speter     char		*string;
1857224Speter };
1867224Speter struct stringlist	*elist;
1877224Speter struct stringlist	*Elist;
1887224Speter struct stringlist	*flist;
1897224Speter struct stringlist	*Flist;
19030963Smckusick struct stringlist	*kfromlist;
19130963Smckusick struct stringlist	*ktolist;
1927224Speter 
1937224Speter     /*
1944840Speter      *	function declarations
1954840Speter      */
19633225Sbostic /*
1974840Speter 		addarc();
19833225Sbostic */
1994840Speter int		arccmp();
2004511Speter arctype		*arclookup();
20133225Sbostic /*
2024840Speter 		asgnsamples();
2034855Speter 		printblurb();
2044840Speter 		cyclelink();
2054840Speter 		dfn();
20633225Sbostic */
2074511Speter bool		dfn_busy();
20833225Sbostic /*
2094840Speter 		dfn_findcycle();
21033225Sbostic */
2114840Speter bool		dfn_numbered();
21233225Sbostic /*
2134840Speter 		dfn_post_visit();
2144840Speter 		dfn_pre_visit();
2154840Speter 		dfn_self_cycle();
21633225Sbostic */
21716851Smckusick nltype		**doarcs();
21833225Sbostic /*
2194840Speter 		done();
2204840Speter 		findcalls();
2214840Speter 		flatprofheader();
2224840Speter 		flatprofline();
22333225Sbostic */
2244844Speter bool		funcsymbol();
22533225Sbostic /*
2264840Speter 		getnfile();
2274840Speter 		getpfile();
2284840Speter 		getstrtab();
2294840Speter 		getsymtab();
2304840Speter 		gettextspace();
2314840Speter 		gprofheader();
2324840Speter 		gprofline();
2334840Speter 		main();
23433225Sbostic */
2354840Speter unsigned long	max();
2364840Speter int		membercmp();
2374840Speter unsigned long	min();
2384840Speter nltype		*nllookup();
2394840Speter FILE		*openpfile();
2404840Speter long		operandlength();
2414840Speter operandenum	operandmode();
2424840Speter char		*operandname();
24333225Sbostic /*
2444840Speter 		printchildren();
2454840Speter 		printcycle();
2464840Speter 		printgprof();
2474840Speter 		printmembers();
2484840Speter 		printname();
2494840Speter 		printparents();
2504840Speter 		printprof();
2514840Speter 		readsamples();
25233225Sbostic */
2534840Speter unsigned long	reladdr();
25433225Sbostic /*
2554840Speter 		sortchildren();
2564840Speter 		sortmembers();
2574840Speter 		sortparents();
2584840Speter 		tally();
2594840Speter 		timecmp();
2604840Speter 		topcmp();
26133225Sbostic */
2624840Speter int		totalcmp();
26333225Sbostic /*
2644840Speter 		valcmp();
26533225Sbostic */
2664511Speter 
2674511Speter #define	LESSTHAN	-1
2684511Speter #define	EQUALTO		0
2694511Speter #define	GREATERTHAN	1
2704511Speter 
2714511Speter #define	DFNDEBUG	1
2724511Speter #define	CYCLEDEBUG	2
2734511Speter #define	ARCDEBUG	4
2744511Speter #define	TALLYDEBUG	8
2754511Speter #define	TIMEDEBUG	16
2764511Speter #define	SAMPLEDEBUG	32
2774511Speter #define	AOUTDEBUG	64
27825709Ssam #define	CALLDEBUG	128
2794722Speter #define	LOOKUPDEBUG	256
2807224Speter #define	PROPDEBUG	512
2817224Speter #define	ANYDEBUG	1024
282