xref: /freebsd/usr.bin/gprof/gprof.h (revision 3fc980b13595d56a312a2a0c752f76902a72b2f7)
19b50d902SRodney W. Grimes /*
29b50d902SRodney W. Grimes  * Copyright (c) 1983, 1993
39b50d902SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
49b50d902SRodney W. Grimes  *
59b50d902SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
69b50d902SRodney W. Grimes  * modification, are permitted provided that the following conditions
79b50d902SRodney W. Grimes  * are met:
89b50d902SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
99b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
109b50d902SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
119b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
129b50d902SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
139b50d902SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
149b50d902SRodney W. Grimes  *    must display the following acknowledgement:
159b50d902SRodney W. Grimes  *	This product includes software developed by the University of
169b50d902SRodney W. Grimes  *	California, Berkeley and its contributors.
179b50d902SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
189b50d902SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
199b50d902SRodney W. Grimes  *    without specific prior written permission.
209b50d902SRodney W. Grimes  *
219b50d902SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
229b50d902SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
239b50d902SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
249b50d902SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
259b50d902SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
269b50d902SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
279b50d902SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
289b50d902SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
299b50d902SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
309b50d902SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
319b50d902SRodney W. Grimes  * SUCH DAMAGE.
329b50d902SRodney W. Grimes  *
339b50d902SRodney W. Grimes  *	@(#)gprof.h	8.1 (Berkeley) 6/6/93
345b29dc6bSPeter Wemm  * $FreeBSD$
359b50d902SRodney W. Grimes  */
369b50d902SRodney W. Grimes 
379b50d902SRodney W. Grimes #include <sys/types.h>
389b50d902SRodney W. Grimes #include <sys/stat.h>
399b50d902SRodney W. Grimes #include <sys/gmon.h>
409b50d902SRodney W. Grimes 
419b50d902SRodney W. Grimes #include <stdio.h>
429b50d902SRodney W. Grimes #include <stdlib.h>
439b50d902SRodney W. Grimes 
445b29dc6bSPeter Wemm #if __ia64__
455b29dc6bSPeter Wemm #   include "ia64.h"
465b29dc6bSPeter Wemm #endif
4713a29a8aSHidetoshi Shimokawa #if __alpha__
4813a29a8aSHidetoshi Shimokawa #   include "alpha.h"
4913a29a8aSHidetoshi Shimokawa #endif
509b50d902SRodney W. Grimes #if vax
519b50d902SRodney W. Grimes #   include "vax.h"
529b50d902SRodney W. Grimes #endif
539b50d902SRodney W. Grimes #if sparc
549b50d902SRodney W. Grimes #   include "sparc.h"
559b50d902SRodney W. Grimes #endif
569b50d902SRodney W. Grimes #if tahoe
579b50d902SRodney W. Grimes #   include "tahoe.h"
589b50d902SRodney W. Grimes #endif
599b50d902SRodney W. Grimes #if hp300
609b50d902SRodney W. Grimes #   include "hp300.h"
619b50d902SRodney W. Grimes #endif
629b50d902SRodney W. Grimes #if luna68k
639b50d902SRodney W. Grimes #   include "luna68k.h"
649b50d902SRodney W. Grimes #endif
659b50d902SRodney W. Grimes #if i386
669b50d902SRodney W. Grimes #   include "i386.h"
679b50d902SRodney W. Grimes #endif
689b50d902SRodney W. Grimes #if mips
699b50d902SRodney W. Grimes #   include "mips.h"
709b50d902SRodney W. Grimes #endif
719b50d902SRodney W. Grimes 
729b50d902SRodney W. Grimes 
739b50d902SRodney W. Grimes     /*
749b50d902SRodney W. Grimes      * booleans
759b50d902SRodney W. Grimes      */
769b50d902SRodney W. Grimes typedef int	bool;
779b50d902SRodney W. Grimes #define	FALSE	0
789b50d902SRodney W. Grimes #define	TRUE	1
799b50d902SRodney W. Grimes 
809b50d902SRodney W. Grimes     /*
819b50d902SRodney W. Grimes      *	ticks per second
829b50d902SRodney W. Grimes      */
839b50d902SRodney W. Grimes long	hz;
849b50d902SRodney W. Grimes 
85e6c645faSBruce Evans #ifdef GPROF4
86ffbce11fSBruce Evans typedef	int64_t UNIT;
87e6c645faSBruce Evans #else
889b50d902SRodney W. Grimes typedef	u_short UNIT;		/* unit of profiling */
89e6c645faSBruce Evans #endif
909b50d902SRodney W. Grimes char	*a_outname;
919b50d902SRodney W. Grimes #define	A_OUTNAME		"a.out"
929b50d902SRodney W. Grimes 
939b50d902SRodney W. Grimes char	*gmonname;
949b50d902SRodney W. Grimes #define	GMONSUM			"gmon.sum"
959b50d902SRodney W. Grimes 
969b50d902SRodney W. Grimes     /*
979b50d902SRodney W. Grimes      *	a constructed arc,
989b50d902SRodney W. Grimes      *	    with pointers to the namelist entry of the parent and the child,
999b50d902SRodney W. Grimes      *	    a count of how many times this arc was traversed,
1009b50d902SRodney W. Grimes      *	    and pointers to the next parent of this child and
1019b50d902SRodney W. Grimes      *		the next child of this parent.
1029b50d902SRodney W. Grimes      */
1039b50d902SRodney W. Grimes struct arcstruct {
1049b50d902SRodney W. Grimes     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
1059b50d902SRodney W. Grimes     struct nl		*arc_childp;	/* pointer to child's nl entry */
1069b50d902SRodney W. Grimes     long		arc_count;	/* num calls from parent to child */
1079b50d902SRodney W. Grimes     double		arc_time;	/* time inherited along arc */
1089b50d902SRodney W. Grimes     double		arc_childtime;	/* childtime inherited along arc */
1099b50d902SRodney W. Grimes     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
1109b50d902SRodney W. Grimes     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
1119b50d902SRodney W. Grimes     struct arcstruct	*arc_next;	/* list of arcs on cycle */
1129b50d902SRodney W. Grimes     unsigned short	arc_cyclecnt;	/* num cycles involved in */
1139b50d902SRodney W. Grimes     unsigned short	arc_flags;	/* see below */
1149b50d902SRodney W. Grimes };
1159b50d902SRodney W. Grimes typedef struct arcstruct	arctype;
1169b50d902SRodney W. Grimes 
1179b50d902SRodney W. Grimes     /*
1189b50d902SRodney W. Grimes      * arc flags
1199b50d902SRodney W. Grimes      */
1209b50d902SRodney W. Grimes #define	DEADARC	0x01	/* time should not propagate across the arc */
1219b50d902SRodney W. Grimes #define	ONLIST	0x02	/* arc is on list of arcs in cycles */
1229b50d902SRodney W. Grimes 
1239b50d902SRodney W. Grimes     /*
1249b50d902SRodney W. Grimes      * The symbol table;
1259b50d902SRodney W. Grimes      * for each external in the specified file we gather
1269b50d902SRodney W. Grimes      * its address, the number of calls and compute its share of cpu time.
1279b50d902SRodney W. Grimes      */
1289b50d902SRodney W. Grimes struct nl {
1295584f22bSJohn Polstra     const char		*name;		/* the name */
1309b50d902SRodney W. Grimes     unsigned long	value;		/* the pc entry point */
1319b50d902SRodney W. Grimes     unsigned long	svalue;		/* entry point aligned to histograms */
1329b50d902SRodney W. Grimes     double		time;		/* ticks in this routine */
1339b50d902SRodney W. Grimes     double		childtime;	/* cumulative ticks in children */
1349b50d902SRodney W. Grimes     long		ncall;		/* how many times called */
1359b50d902SRodney W. Grimes     long		npropcall;	/* times called by live arcs */
1369b50d902SRodney W. Grimes     long		selfcalls;	/* how many calls to self */
1379b50d902SRodney W. Grimes     double		propfraction;	/* what % of time propagates */
1389b50d902SRodney W. Grimes     double		propself;	/* how much self time propagates */
1399b50d902SRodney W. Grimes     double		propchild;	/* how much child time propagates */
1409b50d902SRodney W. Grimes     short		printflag;	/* should this be printed? */
1419b50d902SRodney W. Grimes     short		flags;		/* see below */
1429b50d902SRodney W. Grimes     int			index;		/* index in the graph list */
1439b50d902SRodney W. Grimes     int			toporder;	/* graph call chain top-sort order */
1449b50d902SRodney W. Grimes     int			cycleno;	/* internal number of cycle on */
1459b50d902SRodney W. Grimes     int			parentcnt;	/* number of live parent arcs */
1469b50d902SRodney W. Grimes     struct nl		*cyclehead;	/* pointer to head of cycle */
1479b50d902SRodney W. Grimes     struct nl		*cnext;		/* pointer to next member of cycle */
1489b50d902SRodney W. Grimes     arctype		*parents;	/* list of caller arcs */
1499b50d902SRodney W. Grimes     arctype		*children;	/* list of callee arcs */
1509b50d902SRodney W. Grimes };
1519b50d902SRodney W. Grimes typedef struct nl	nltype;
1529b50d902SRodney W. Grimes 
1539b50d902SRodney W. Grimes nltype	*nl;			/* the whole namelist */
1549b50d902SRodney W. Grimes nltype	*npe;			/* the virtual end of the namelist */
1559b50d902SRodney W. Grimes int	nname;			/* the number of function names */
1569b50d902SRodney W. Grimes 
1579b50d902SRodney W. Grimes #define	HASCYCLEXIT	0x08	/* node has arc exiting from cycle */
1589b50d902SRodney W. Grimes #define	CYCLEHEAD	0x10	/* node marked as head of a cycle */
1599b50d902SRodney W. Grimes #define	VISITED		0x20	/* node visited during a cycle */
1609b50d902SRodney W. Grimes 
1619b50d902SRodney W. Grimes     /*
1629b50d902SRodney W. Grimes      * The cycle list.
1639b50d902SRodney W. Grimes      * for each subcycle within an identified cycle, we gather
1649b50d902SRodney W. Grimes      * its size and the list of included arcs.
1659b50d902SRodney W. Grimes      */
1669b50d902SRodney W. Grimes struct cl {
1679b50d902SRodney W. Grimes     int		size;		/* length of cycle */
1689b50d902SRodney W. Grimes     struct cl	*next;		/* next member of list */
1699b50d902SRodney W. Grimes     arctype	*list[1];	/* list of arcs in cycle */
1709b50d902SRodney W. Grimes     /* actually longer */
1719b50d902SRodney W. Grimes };
1729b50d902SRodney W. Grimes typedef struct cl cltype;
1739b50d902SRodney W. Grimes 
1749b50d902SRodney W. Grimes arctype	*archead;		/* the head of arcs in current cycle list */
1759b50d902SRodney W. Grimes cltype	*cyclehead;		/* the head of the list */
1769b50d902SRodney W. Grimes int	cyclecnt;		/* the number of cycles found */
1779b50d902SRodney W. Grimes #define	CYCLEMAX	100	/* maximum cycles before cutting one of them */
1789b50d902SRodney W. Grimes 
1799b50d902SRodney W. Grimes     /*
1809b50d902SRodney W. Grimes      *	flag which marks a nl entry as topologically ``busy''
1819b50d902SRodney W. Grimes      *	flag which marks a nl entry as topologically ``not_numbered''
1829b50d902SRodney W. Grimes      */
1839b50d902SRodney W. Grimes #define	DFN_BUSY	-1
1849b50d902SRodney W. Grimes #define	DFN_NAN		0
1859b50d902SRodney W. Grimes 
1869b50d902SRodney W. Grimes     /*
1879b50d902SRodney W. Grimes      *	namelist entries for cycle headers.
1889b50d902SRodney W. Grimes      *	the number of discovered cycles.
1899b50d902SRodney W. Grimes      */
1909b50d902SRodney W. Grimes nltype	*cyclenl;		/* cycle header namelist */
1919b50d902SRodney W. Grimes int	ncycle;			/* number of cycles discovered */
1929b50d902SRodney W. Grimes 
1939b50d902SRodney W. Grimes     /*
1949b50d902SRodney W. Grimes      * The header on the gmon.out file.
1959b50d902SRodney W. Grimes      * gmon.out consists of a struct phdr (defined in gmon.h)
1969b50d902SRodney W. Grimes      * and then an array of ncnt samples representing the
1979b50d902SRodney W. Grimes      * discretized program counter values.
1989b50d902SRodney W. Grimes      *
1999b50d902SRodney W. Grimes      *	Backward compatible old style header
2009b50d902SRodney W. Grimes      */
2019b50d902SRodney W. Grimes struct ophdr {
2029b50d902SRodney W. Grimes     UNIT	*lpc;
2039b50d902SRodney W. Grimes     UNIT	*hpc;
2049b50d902SRodney W. Grimes     int		ncnt;
2059b50d902SRodney W. Grimes };
2069b50d902SRodney W. Grimes 
2079b50d902SRodney W. Grimes int	debug;
2089b50d902SRodney W. Grimes 
2099b50d902SRodney W. Grimes     /*
2109b50d902SRodney W. Grimes      * Each discretized pc sample has
2119b50d902SRodney W. Grimes      * a count of the number of samples in its range
2129b50d902SRodney W. Grimes      */
2139b50d902SRodney W. Grimes UNIT	*samples;
2149b50d902SRodney W. Grimes 
2159b50d902SRodney W. Grimes unsigned long	s_lowpc;	/* lowpc from the profile file */
2169b50d902SRodney W. Grimes unsigned long	s_highpc;	/* highpc from the profile file */
21713a29a8aSHidetoshi Shimokawa unsigned long	lowpc, highpc;	/* range profiled, in UNIT's */
2189b50d902SRodney W. Grimes unsigned sampbytes;		/* number of bytes of samples */
2199b50d902SRodney W. Grimes int	nsamples;		/* number of samples */
2209b50d902SRodney W. Grimes double	actime;			/* accumulated time thus far for putprofline */
2219b50d902SRodney W. Grimes double	totime;			/* total time for all routines */
2229b50d902SRodney W. Grimes double	printtime;		/* total of time being printed */
2239b50d902SRodney W. Grimes double	scale;			/* scale factor converting samples to pc
2249b50d902SRodney W. Grimes 				   values: each sample covers scale bytes */
2259b50d902SRodney W. Grimes unsigned char	*textspace;	/* text space of a.out in core */
2269b50d902SRodney W. Grimes int	cyclethreshold;		/* with -C, minimum cycle size to ignore */
2279b50d902SRodney W. Grimes 
2289b50d902SRodney W. Grimes     /*
2299b50d902SRodney W. Grimes      *	option flags, from a to z.
2309b50d902SRodney W. Grimes      */
2319b50d902SRodney W. Grimes bool	aflag;				/* suppress static functions */
2329b50d902SRodney W. Grimes bool	bflag;				/* blurbs, too */
2339b50d902SRodney W. Grimes bool	cflag;				/* discovered call graph, too */
2349b50d902SRodney W. Grimes bool	Cflag;				/* find cut-set to eliminate cycles */
2359b50d902SRodney W. Grimes bool	dflag;				/* debugging options */
2369b50d902SRodney W. Grimes bool	eflag;				/* specific functions excluded */
2379b50d902SRodney W. Grimes bool	Eflag;				/* functions excluded with time */
2389b50d902SRodney W. Grimes bool	fflag;				/* specific functions requested */
2399b50d902SRodney W. Grimes bool	Fflag;				/* functions requested with time */
2409b50d902SRodney W. Grimes bool	kflag;				/* arcs to be deleted */
2413fc980b1SBrian Feldman bool	Kflag;				/* use the running kernel for symbols */
2429b50d902SRodney W. Grimes bool	sflag;				/* sum multiple gmon.out files */
2435584f22bSJohn Polstra bool	uflag;				/* suppress symbols hidden from C */
2449b50d902SRodney W. Grimes bool	zflag;				/* zero time/called functions, too */
2459b50d902SRodney W. Grimes 
2469b50d902SRodney W. Grimes     /*
2479b50d902SRodney W. Grimes      *	structure for various string lists
2489b50d902SRodney W. Grimes      */
2499b50d902SRodney W. Grimes struct stringlist {
2509b50d902SRodney W. Grimes     struct stringlist	*next;
2519b50d902SRodney W. Grimes     char		*string;
2529b50d902SRodney W. Grimes };
2539b50d902SRodney W. Grimes struct stringlist	*elist;
2549b50d902SRodney W. Grimes struct stringlist	*Elist;
2559b50d902SRodney W. Grimes struct stringlist	*flist;
2569b50d902SRodney W. Grimes struct stringlist	*Flist;
2579b50d902SRodney W. Grimes struct stringlist	*kfromlist;
2589b50d902SRodney W. Grimes struct stringlist	*ktolist;
2599b50d902SRodney W. Grimes 
2609b50d902SRodney W. Grimes     /*
2619b50d902SRodney W. Grimes      *	function declarations
2629b50d902SRodney W. Grimes      */
2639b50d902SRodney W. Grimes /*
2649b50d902SRodney W. Grimes 		addarc();
2659b50d902SRodney W. Grimes */
2665584f22bSJohn Polstra int		aout_getnfile(const char *, char ***);
2679b50d902SRodney W. Grimes int		arccmp();
2689b50d902SRodney W. Grimes arctype		*arclookup();
2699b50d902SRodney W. Grimes /*
2709b50d902SRodney W. Grimes 		asgnsamples();
2719b50d902SRodney W. Grimes 		printblurb();
2729b50d902SRodney W. Grimes 		cyclelink();
2739b50d902SRodney W. Grimes 		dfn();
2749b50d902SRodney W. Grimes */
2759b50d902SRodney W. Grimes bool		dfn_busy();
2769b50d902SRodney W. Grimes /*
2779b50d902SRodney W. Grimes 		dfn_findcycle();
2789b50d902SRodney W. Grimes */
2799b50d902SRodney W. Grimes bool		dfn_numbered();
2809b50d902SRodney W. Grimes /*
2819b50d902SRodney W. Grimes 		dfn_post_visit();
2829b50d902SRodney W. Grimes 		dfn_pre_visit();
2839b50d902SRodney W. Grimes 		dfn_self_cycle();
2849b50d902SRodney W. Grimes */
2859b50d902SRodney W. Grimes nltype		**doarcs();
2869b50d902SRodney W. Grimes /*
2879b50d902SRodney W. Grimes 		done();
2885584f22bSJohn Polstra */
2895584f22bSJohn Polstra int		elf_getnfile(const char *, char ***);
2905584f22bSJohn Polstra /*
2919b50d902SRodney W. Grimes 		findcalls();
2929b50d902SRodney W. Grimes 		flatprofheader();
2939b50d902SRodney W. Grimes 		flatprofline();
2949b50d902SRodney W. Grimes */
2959b50d902SRodney W. Grimes /*
2969b50d902SRodney W. Grimes 		getpfile();
2979b50d902SRodney W. Grimes 		gprofheader();
2989b50d902SRodney W. Grimes 		gprofline();
2993fc980b1SBrian Feldman */
3003fc980b1SBrian Feldman int		kernel_getnfile(const char *, char ***);
3013fc980b1SBrian Feldman /*
3029b50d902SRodney W. Grimes 		main();
3039b50d902SRodney W. Grimes */
3049b50d902SRodney W. Grimes unsigned long	max();
3059b50d902SRodney W. Grimes int		membercmp();
3069b50d902SRodney W. Grimes unsigned long	min();
3079b50d902SRodney W. Grimes nltype		*nllookup();
3089b50d902SRodney W. Grimes FILE		*openpfile();
3099b50d902SRodney W. Grimes long		operandlength();
3109b50d902SRodney W. Grimes operandenum	operandmode();
3119b50d902SRodney W. Grimes char		*operandname();
3129b50d902SRodney W. Grimes /*
3139b50d902SRodney W. Grimes 		printchildren();
3149b50d902SRodney W. Grimes 		printcycle();
3159b50d902SRodney W. Grimes 		printgprof();
3169b50d902SRodney W. Grimes 		printmembers();
3179b50d902SRodney W. Grimes 		printname();
3189b50d902SRodney W. Grimes 		printparents();
3199b50d902SRodney W. Grimes 		printprof();
3209b50d902SRodney W. Grimes 		readsamples();
3219b50d902SRodney W. Grimes */
3229b50d902SRodney W. Grimes unsigned long	reladdr();
3239b50d902SRodney W. Grimes /*
3249b50d902SRodney W. Grimes 		sortchildren();
3259b50d902SRodney W. Grimes 		sortmembers();
3269b50d902SRodney W. Grimes 		sortparents();
3279b50d902SRodney W. Grimes 		tally();
3289b50d902SRodney W. Grimes 		timecmp();
3299b50d902SRodney W. Grimes 		topcmp();
3309b50d902SRodney W. Grimes */
3319b50d902SRodney W. Grimes int		totalcmp();
3329b50d902SRodney W. Grimes /*
3339b50d902SRodney W. Grimes 		valcmp();
3349b50d902SRodney W. Grimes */
3359b50d902SRodney W. Grimes 
3369b50d902SRodney W. Grimes #define	LESSTHAN	-1
3379b50d902SRodney W. Grimes #define	EQUALTO		0
3389b50d902SRodney W. Grimes #define	GREATERTHAN	1
3399b50d902SRodney W. Grimes 
3409b50d902SRodney W. Grimes #define	DFNDEBUG	1
3419b50d902SRodney W. Grimes #define	CYCLEDEBUG	2
3429b50d902SRodney W. Grimes #define	ARCDEBUG	4
3439b50d902SRodney W. Grimes #define	TALLYDEBUG	8
3449b50d902SRodney W. Grimes #define	TIMEDEBUG	16
3459b50d902SRodney W. Grimes #define	SAMPLEDEBUG	32
3469b50d902SRodney W. Grimes #define	AOUTDEBUG	64
3479b50d902SRodney W. Grimes #define	CALLDEBUG	128
3489b50d902SRodney W. Grimes #define	LOOKUPDEBUG	256
3499b50d902SRodney W. Grimes #define	PROPDEBUG	512
3509b50d902SRodney W. Grimes #define	BREAKCYCLE	1024
3519b50d902SRodney W. Grimes #define	SUBCYCLELIST	2048
3529b50d902SRodney W. Grimes #define	ANYDEBUG	4096
353