xref: /original-bsd/usr.bin/gprof/gprof.h (revision f6a299d4)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)gprof.h	5.12 (Berkeley) 03/02/92
8  */
9 
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <a.out.h>
13 #include <stdio.h>
14 #include "gmon.h"
15 
16 #if vax
17 #   include "vax.h"
18 #endif
19 #if sun
20 #   include "sun.h"
21 #endif
22 #if tahoe
23 #   include "tahoe.h"
24 #endif
25 #if hp300
26 #   include "hp300.h"
27 #endif
28 #if i386
29 #   include "i386.h"
30 #endif
31 
32 
33     /*
34      *	who am i, for error messages.
35      */
36 char	*whoami;
37 
38     /*
39      * booleans
40      */
41 typedef int	bool;
42 #define	FALSE	0
43 #define	TRUE	1
44 
45     /*
46      *	ticks per second
47      */
48 long	hz;
49 
50 typedef	u_short UNIT;		/* unit of profiling */
51 char	*a_outname;
52 #define	A_OUTNAME		"a.out"
53 
54 char	*gmonname;
55 #define	GMONNAME		"gmon.out"
56 #define	GMONSUM			"gmon.sum"
57 
58     /*
59      *	a constructed arc,
60      *	    with pointers to the namelist entry of the parent and the child,
61      *	    a count of how many times this arc was traversed,
62      *	    and pointers to the next parent of this child and
63      *		the next child of this parent.
64      */
65 struct arcstruct {
66     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
67     struct nl		*arc_childp;	/* pointer to child's nl entry */
68     long		arc_count;	/* num calls from parent to child */
69     double		arc_time;	/* time inherited along arc */
70     double		arc_childtime;	/* childtime inherited along arc */
71     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
72     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
73     struct arcstruct	*arc_next;	/* list of arcs on cycle */
74     unsigned short	arc_cyclecnt;	/* num cycles involved in */
75     unsigned short	arc_flags;	/* see below */
76 };
77 typedef struct arcstruct	arctype;
78 
79     /*
80      * arc flags
81      */
82 #define	DEADARC	0x01	/* time should not propagate across the arc */
83 #define	ONLIST	0x02	/* arc is on list of arcs in cycles */
84 
85     /*
86      * The symbol table;
87      * for each external in the specified file we gather
88      * its address, the number of calls and compute its share of cpu time.
89      */
90 struct nl {
91     char		*name;		/* the name */
92     unsigned long	value;		/* the pc entry point */
93     unsigned long	svalue;		/* entry point aligned to histograms */
94     double		time;		/* ticks in this routine */
95     double		childtime;	/* cumulative ticks in children */
96     long		ncall;		/* how many times called */
97     long		npropcall;	/* times called by live arcs */
98     long		selfcalls;	/* how many calls to self */
99     double		propfraction;	/* what % of time propagates */
100     double		propself;	/* how much self time propagates */
101     double		propchild;	/* how much child time propagates */
102     short		printflag;	/* should this be printed? */
103     short		flags;		/* see below */
104     int			index;		/* index in the graph list */
105     int			toporder;	/* graph call chain top-sort order */
106     int			cycleno;	/* internal number of cycle on */
107     int			parentcnt;	/* number of live parent arcs */
108     struct nl		*cyclehead;	/* pointer to head of cycle */
109     struct nl		*cnext;		/* pointer to next member of cycle */
110     arctype		*parents;	/* list of caller arcs */
111     arctype		*children;	/* list of callee arcs */
112 };
113 typedef struct nl	nltype;
114 
115 nltype	*nl;			/* the whole namelist */
116 nltype	*npe;			/* the virtual end of the namelist */
117 int	nname;			/* the number of function names */
118 
119 #define	HASCYCLEXIT	0x08	/* node has arc exiting from cycle */
120 #define	CYCLEHEAD	0x10	/* node marked as head of a cycle */
121 #define	VISITED		0x20	/* node visited during a cycle */
122 
123     /*
124      * The cycle list.
125      * for each subcycle within an identified cycle, we gather
126      * its size and the list of included arcs.
127      */
128 struct cl {
129     int		size;		/* length of cycle */
130     struct cl	*next;		/* next member of list */
131     arctype	*list[1];	/* list of arcs in cycle */
132     /* actually longer */
133 };
134 typedef struct cl cltype;
135 
136 arctype	*archead;		/* the head of arcs in current cycle list */
137 cltype	*cyclehead;		/* the head of the list */
138 int	cyclecnt;		/* the number of cycles found */
139 #define	CYCLEMAX	100	/* maximum cycles before cutting one of them */
140 
141     /*
142      *	flag which marks a nl entry as topologically ``busy''
143      *	flag which marks a nl entry as topologically ``not_numbered''
144      */
145 #define	DFN_BUSY	-1
146 #define	DFN_NAN		0
147 
148     /*
149      *	namelist entries for cycle headers.
150      *	the number of discovered cycles.
151      */
152 nltype	*cyclenl;		/* cycle header namelist */
153 int	ncycle;			/* number of cycles discovered */
154 
155     /*
156      * The header on the gmon.out file.
157      * gmon.out consists of a struct phdr (defined in gmon.h)
158      * and then an array of ncnt samples representing the
159      * discretized program counter values.
160      *
161      *	Backward compatible old style header
162      */
163 struct ophdr {
164     UNIT	*lpc;
165     UNIT	*hpc;
166     int		ncnt;
167 };
168 
169 int	debug;
170 
171     /*
172      * Each discretized pc sample has
173      * a count of the number of samples in its range
174      */
175 UNIT	*samples;
176 
177 unsigned long	s_lowpc;	/* lowpc from the profile file */
178 unsigned long	s_highpc;	/* highpc from the profile file */
179 unsigned lowpc, highpc;		/* range profiled, in UNIT's */
180 unsigned sampbytes;		/* number of bytes of samples */
181 int	nsamples;		/* number of samples */
182 double	actime;			/* accumulated time thus far for putprofline */
183 double	totime;			/* total time for all routines */
184 double	printtime;		/* total of time being printed */
185 double	scale;			/* scale factor converting samples to pc
186 				   values: each sample covers scale bytes */
187 char	*strtab;		/* string table in core */
188 off_t	ssiz;			/* size of the string table */
189 struct	exec xbuf;		/* exec header of a.out */
190 unsigned char	*textspace;	/* text space of a.out in core */
191 int	cyclethreshold;		/* with -C, minimum cycle size to ignore */
192 
193     /*
194      *	option flags, from a to z.
195      */
196 bool	aflag;				/* suppress static functions */
197 bool	bflag;				/* blurbs, too */
198 bool	cflag;				/* discovered call graph, too */
199 bool	Cflag;				/* find cut-set to eliminate cycles */
200 bool	dflag;				/* debugging options */
201 bool	eflag;				/* specific functions excluded */
202 bool	Eflag;				/* functions excluded with time */
203 bool	fflag;				/* specific functions requested */
204 bool	Fflag;				/* functions requested with time */
205 bool	kflag;				/* arcs to be deleted */
206 bool	sflag;				/* sum multiple gmon.out files */
207 bool	zflag;				/* zero time/called functions, too */
208 
209     /*
210      *	structure for various string lists
211      */
212 struct stringlist {
213     struct stringlist	*next;
214     char		*string;
215 };
216 struct stringlist	*elist;
217 struct stringlist	*Elist;
218 struct stringlist	*flist;
219 struct stringlist	*Flist;
220 struct stringlist	*kfromlist;
221 struct stringlist	*ktolist;
222 
223     /*
224      *	function declarations
225      */
226 /*
227 		addarc();
228 */
229 int		arccmp();
230 arctype		*arclookup();
231 /*
232 		asgnsamples();
233 		printblurb();
234 		cyclelink();
235 		dfn();
236 */
237 bool		dfn_busy();
238 /*
239 		dfn_findcycle();
240 */
241 bool		dfn_numbered();
242 /*
243 		dfn_post_visit();
244 		dfn_pre_visit();
245 		dfn_self_cycle();
246 */
247 nltype		**doarcs();
248 /*
249 		done();
250 		findcalls();
251 		flatprofheader();
252 		flatprofline();
253 */
254 bool		funcsymbol();
255 /*
256 		getnfile();
257 		getpfile();
258 		getstrtab();
259 		getsymtab();
260 		gettextspace();
261 		gprofheader();
262 		gprofline();
263 		main();
264 */
265 unsigned long	max();
266 int		membercmp();
267 unsigned long	min();
268 nltype		*nllookup();
269 FILE		*openpfile();
270 long		operandlength();
271 operandenum	operandmode();
272 char		*operandname();
273 /*
274 		printchildren();
275 		printcycle();
276 		printgprof();
277 		printmembers();
278 		printname();
279 		printparents();
280 		printprof();
281 		readsamples();
282 */
283 unsigned long	reladdr();
284 /*
285 		sortchildren();
286 		sortmembers();
287 		sortparents();
288 		tally();
289 		timecmp();
290 		topcmp();
291 */
292 int		totalcmp();
293 /*
294 		valcmp();
295 */
296 
297 #define	LESSTHAN	-1
298 #define	EQUALTO		0
299 #define	GREATERTHAN	1
300 
301 #define	DFNDEBUG	1
302 #define	CYCLEDEBUG	2
303 #define	ARCDEBUG	4
304 #define	TALLYDEBUG	8
305 #define	TIMEDEBUG	16
306 #define	SAMPLEDEBUG	32
307 #define	AOUTDEBUG	64
308 #define	CALLDEBUG	128
309 #define	LOOKUPDEBUG	256
310 #define	PROPDEBUG	512
311 #define	BREAKCYCLE	1024
312 #define	SUBCYCLELIST	2048
313 #define	ANYDEBUG	4096
314