gprof.h revision 1.11
1/*	$OpenBSD: gprof.h,v 1.11 2004/07/20 18:20:55 marc Exp $	*/
2/*	$NetBSD: gprof.h,v 1.13 1996/04/01 21:54:06 mark Exp $	*/
3
4/*
5 * Copyright (c) 1983, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 *	@(#)gprof.h	8.1 (Berkeley) 6/6/93
33 */
34
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <sys/gmon.h>
38
39#include <a.out.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <err.h>
43
44#include "machine.h"
45
46    /*
47     * booleans
48     */
49typedef int	bool;
50#define	FALSE	0
51#define	TRUE	1
52
53    /*
54     *	ticks per second
55     */
56long	hz;
57
58typedef	u_short UNIT;		/* unit of profiling */
59char	*a_outname;
60#define	A_OUTNAME		"a.out"
61
62char	*gmonname;
63#define	GMONNAME		"gmon.out"
64#define	GMONSUM			"gmon.sum"
65
66    /*
67     *	a constructed arc,
68     *	    with pointers to the namelist entry of the parent and the child,
69     *	    a count of how many times this arc was traversed,
70     *	    and pointers to the next parent of this child and
71     *		the next child of this parent.
72     */
73struct arcstruct {
74    struct nl		*arc_parentp;	/* pointer to parent's nl entry */
75    struct nl		*arc_childp;	/* pointer to child's nl entry */
76    long		arc_count;	/* num calls from parent to child */
77    double		arc_time;	/* time inherited along arc */
78    double		arc_childtime;	/* childtime inherited along arc */
79    struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
80    struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
81    struct arcstruct	*arc_next;	/* list of arcs on cycle */
82    unsigned short	arc_cyclecnt;	/* num cycles involved in */
83    unsigned short	arc_flags;	/* see below */
84};
85typedef struct arcstruct	arctype;
86
87    /*
88     * arc flags
89     */
90#define	DEADARC	0x01	/* time should not propagate across the arc */
91#define	ONLIST	0x02	/* arc is on list of arcs in cycles */
92
93    /*
94     * The symbol table;
95     * for each external in the specified file we gather
96     * its address, the number of calls and compute its share of cpu time.
97     */
98struct nl {
99    const char		*name;		/* the name */
100    unsigned long	value;		/* the pc entry point */
101    unsigned long	svalue;		/* entry point aligned to histograms */
102    double		time;		/* ticks in this routine */
103    double		childtime;	/* cumulative ticks in children */
104    long		ncall;		/* how many times called */
105    long		npropcall;	/* times called by live arcs */
106    long		selfcalls;	/* how many calls to self */
107    double		propfraction;	/* what % of time propagates */
108    double		propself;	/* how much self time propagates */
109    double		propchild;	/* how much child time propagates */
110    short		printflag;	/* should this be printed? */
111    short		flags;		/* see below */
112    int			index;		/* index in the graph list */
113    int			toporder;	/* graph call chain top-sort order */
114    int			cycleno;	/* internal number of cycle on */
115    int			parentcnt;	/* number of live parent arcs */
116    struct nl		*cyclehead;	/* pointer to head of cycle */
117    struct nl		*cnext;		/* pointer to next member of cycle */
118    arctype		*parents;	/* list of caller arcs */
119    arctype		*children;	/* list of callee arcs */
120};
121typedef struct nl	nltype;
122
123nltype	*nl;			/* the whole namelist */
124nltype	*npe;			/* the virtual end of the namelist */
125int	nname;			/* the number of function names */
126
127#define	HASCYCLEXIT	0x08	/* node has arc exiting from cycle */
128#define	CYCLEHEAD	0x10	/* node marked as head of a cycle */
129#define	VISITED		0x20	/* node visited during a cycle */
130
131    /*
132     * The cycle list.
133     * for each subcycle within an identified cycle, we gather
134     * its size and the list of included arcs.
135     */
136struct cl {
137    int		size;		/* length of cycle */
138    struct cl	*next;		/* next member of list */
139    arctype	*list[1];	/* list of arcs in cycle */
140    /* actually longer */
141};
142typedef struct cl cltype;
143
144arctype	*archead;		/* the head of arcs in current cycle list */
145cltype	*cyclehead;		/* the head of the list */
146int	cyclecnt;		/* the number of cycles found */
147#define	CYCLEMAX	100	/* maximum cycles before cutting one of them */
148
149    /*
150     *	flag which marks a nl entry as topologically ``busy''
151     *	flag which marks a nl entry as topologically ``not_numbered''
152     */
153#define	DFN_BUSY	-1
154#define	DFN_NAN		0
155
156    /*
157     *	namelist entries for cycle headers.
158     *	the number of discovered cycles.
159     */
160nltype	*cyclenl;		/* cycle header namelist */
161int	ncycle;			/* number of cycles discovered */
162
163    /*
164     * The header on the gmon.out file.
165     * gmon.out consists of a struct phdr (defined in gmon.h)
166     * and then an array of ncnt samples representing the
167     * discretized program counter values.
168     *
169     *	Backward compatible old style header
170     */
171struct ophdr {
172    UNIT	*lpc;
173    UNIT	*hpc;
174    int		ncnt;
175};
176
177int	debug;
178
179    /*
180     * Each discretized pc sample has
181     * a count of the number of samples in its range
182     */
183UNIT	*samples;
184
185unsigned long	s_lowpc;	/* lowpc from the profile file */
186unsigned long	s_highpc;	/* highpc from the profile file */
187unsigned long	lowpc, highpc;	/* range profiled, in UNIT's */
188unsigned sampbytes;		/* number of bytes of samples */
189int	nsamples;		/* number of samples */
190double	actime;			/* accumulated time thus far for putprofline */
191double	totime;			/* total time for all routines */
192double	printtime;		/* total of time being printed */
193double	scale;			/* scale factor converting samples to pc
194				   values: each sample covers scale bytes */
195unsigned char	*textspace;	/* text space of a.out in core */
196int	cyclethreshold;		/* with -C, minimum cycle size to ignore */
197
198    /*
199     *	option flags, from a to z.
200     */
201bool	aflag;				/* suppress static functions */
202bool	bflag;				/* blurbs, too */
203bool	cflag;				/* discovered call graph, too */
204bool	Cflag;				/* find cut-set to eliminate cycles */
205bool	dflag;				/* debugging options */
206bool	eflag;				/* specific functions excluded */
207bool	Eflag;				/* functions excluded with time */
208bool	fflag;				/* specific functions requested */
209bool	Fflag;				/* functions requested with time */
210bool	kflag;				/* arcs to be deleted */
211bool	sflag;				/* sum multiple gmon.out files */
212bool	zflag;				/* zero time/called functions, too */
213
214    /*
215     *	structure for various string lists
216     */
217struct stringlist {
218    struct stringlist	*next;
219    char		*string;
220};
221struct stringlist	*elist;
222struct stringlist	*Elist;
223struct stringlist	*flist;
224struct stringlist	*Flist;
225struct stringlist	*kfromlist;
226struct stringlist	*ktolist;
227
228    /*
229     *	function declarations
230     */
231void		addarc();
232int		addcycle(arctype **, arctype **);
233void		addlist(struct stringlist *listp, char *funcname);
234int		arccmp();
235arctype		*arclookup();
236void		asgnsamples();
237void		alignentries();
238void		printblurb();
239int		cycleanalyze(void);
240void		cyclelink(void);
241void		cycletime(void);
242void		compresslist(void);
243int		descend(nltype *node, arctype **stkstart, arctype **stkp);
244void		dfn();
245bool		dfn_busy();
246void		dfn_findcycle();
247void		dfn_init();
248bool		dfn_numbered();
249void		dfn_post_visit();
250void		dfn_pre_visit();
251void		dfn_self_cycle();
252nltype		**doarcs();
253void		doflags(void);
254void		dotime(void);
255void		dumpsum();
256void		findcall(nltype *, u_long, u_long);
257void		flatprofheader();
258void		flatprofline();
259int		getnfile(const char *, char ***);
260void		getpfile();
261void		gprofheader();
262void		gprofline();
263int		hertz();
264void		inheritflags(nltype *childp);
265unsigned long	max();
266int		membercmp();
267unsigned long	min();
268nltype		*nllookup();
269bool		onlist();
270FILE		*openpfile();
271long		operandlength();
272operandenum	operandmode();
273char		*operandname();
274void		printchildren();
275void		printcycle();
276void		printgprof();
277void		printindex();
278void		printmembers();
279void		printname();
280void		printparents();
281void		printprof();
282void		readsamples(FILE *);
283unsigned long	reladdr();
284void		sortchildren();
285void		sortmembers();
286void		sortparents();
287void		tally();
288int		timecmp();
289void		timepropagate(nltype *);
290int		topcmp();
291int		totalcmp();
292
293#define	LESSTHAN	-1
294#define	EQUALTO		0
295#define	GREATERTHAN	1
296
297#define	DFNDEBUG	1
298#define	CYCLEDEBUG	2
299#define	ARCDEBUG	4
300#define	TALLYDEBUG	8
301#define	TIMEDEBUG	16
302#define	SAMPLEDEBUG	32
303#define	AOUTDEBUG	64
304#define	ELFDEBUG	AOUTDEBUG
305#define	CALLDEBUG	128
306#define	LOOKUPDEBUG	256
307#define	PROPDEBUG	512
308#define	BREAKCYCLE	1024
309#define	SUBCYCLELIST	2048
310#define	ANYDEBUG	4096
311