xref: /original-bsd/usr.bin/gprof/gprof.h (revision 33586e34)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)gprof.h	5.7 (Berkeley) 05/10/89
18  */
19 
20 #include <stdio.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <a.out.h>
24 #include "gcrt0.h"
25 
26 #if vax
27 #   include "vax.h"
28 #endif
29 #if sun
30 #   include "sun.h"
31 #endif
32 #if tahoe
33 #   include "tahoe.h"
34 #endif
35 
36 
37     /*
38      *	who am i, for error messages.
39      */
40 char	*whoami;
41 
42     /*
43      * booleans
44      */
45 typedef int	bool;
46 #define	FALSE	0
47 #define	TRUE	1
48 
49     /*
50      *	ticks per second
51      */
52 long	hz;
53 
54 typedef	u_short UNIT;		/* unit of profiling */
55 char	*a_outname;
56 #define	A_OUTNAME		"a.out"
57 
58 char	*gmonname;
59 #define	GMONNAME		"gmon.out"
60 #define	GMONSUM			"gmon.sum"
61 
62     /*
63      *	a constructed arc,
64      *	    with pointers to the namelist entry of the parent and the child,
65      *	    a count of how many times this arc was traversed,
66      *	    and pointers to the next parent of this child and
67      *		the next child of this parent.
68      */
69 struct arcstruct {
70     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
71     struct nl		*arc_childp;	/* pointer to child's nl entry */
72     long		arc_count;	/* how calls from parent to child */
73     double		arc_time;	/* time inherited along arc */
74     double		arc_childtime;	/* childtime inherited along arc */
75     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
76     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
77 };
78 typedef struct arcstruct	arctype;
79 
80     /*
81      * The symbol table;
82      * for each external in the specified file we gather
83      * its address, the number of calls and compute its share of cpu time.
84      */
85 struct nl {
86     char		*name;		/* the name */
87     unsigned long	value;		/* the pc entry point */
88     unsigned long	svalue;		/* entry point aligned to histograms */
89     double		time;		/* ticks in this routine */
90     double		childtime;	/* cumulative ticks in children */
91     long		ncall;		/* how many times called */
92     long		selfcalls;	/* how many calls to self */
93     double		propfraction;	/* what % of time propagates */
94     double		propself;	/* how much self time propagates */
95     double		propchild;	/* how much child time propagates */
96     bool		printflag;	/* should this be printed? */
97     int			index;		/* index in the graph list */
98     int			toporder;	/* graph call chain top-sort order */
99     int			cycleno;	/* internal number of cycle on */
100     struct nl		*cyclehead;	/* pointer to head of cycle */
101     struct nl		*cnext;		/* pointer to next member of cycle */
102     arctype		*parents;	/* list of caller arcs */
103     arctype		*children;	/* list of callee arcs */
104 };
105 typedef struct nl	nltype;
106 
107 nltype	*nl;			/* the whole namelist */
108 nltype	*npe;			/* the virtual end of the namelist */
109 int	nname;			/* the number of function names */
110 
111     /*
112      *	flag which marks a nl entry as topologically ``busy''
113      *	flag which marks a nl entry as topologically ``not_numbered''
114      */
115 #define	DFN_BUSY	-1
116 #define	DFN_NAN		0
117 
118     /*
119      *	namelist entries for cycle headers.
120      *	the number of discovered cycles.
121      */
122 nltype	*cyclenl;		/* cycle header namelist */
123 int	ncycle;			/* number of cycles discovered */
124 
125     /*
126      * The header on the gmon.out file.
127      * gmon.out consists of one of these headers,
128      * and then an array of ncnt samples
129      * representing the discretized program counter values.
130      *	this should be a struct phdr, but since everything is done
131      *	as UNITs, this is in UNITs too.
132      */
133 struct hdr {
134     UNIT	*lowpc;
135     UNIT	*highpc;
136     int	ncnt;
137 };
138 
139 struct hdr	h;
140 
141 int	debug;
142 
143     /*
144      * Each discretized pc sample has
145      * a count of the number of samples in its range
146      */
147 UNIT	*samples;
148 
149 unsigned long	s_lowpc;	/* lowpc from the profile file */
150 unsigned long	s_highpc;	/* highpc from the profile file */
151 unsigned lowpc, highpc;		/* range profiled, in UNIT's */
152 unsigned sampbytes;		/* number of bytes of samples */
153 int	nsamples;		/* number of samples */
154 double	actime;			/* accumulated time thus far for putprofline */
155 double	totime;			/* total time for all routines */
156 double	printtime;		/* total of time being printed */
157 double	scale;			/* scale factor converting samples to pc
158 				   values: each sample covers scale bytes */
159 char	*strtab;		/* string table in core */
160 off_t	ssiz;			/* size of the string table */
161 struct	exec xbuf;		/* exec header of a.out */
162 unsigned char	*textspace;		/* text space of a.out in core */
163 
164     /*
165      *	option flags, from a to z.
166      */
167 bool	aflag;				/* suppress static functions */
168 bool	bflag;				/* blurbs, too */
169 bool	cflag;				/* discovered call graph, too */
170 bool	dflag;				/* debugging options */
171 bool	eflag;				/* specific functions excluded */
172 bool	Eflag;				/* functions excluded with time */
173 bool	fflag;				/* specific functions requested */
174 bool	Fflag;				/* functions requested with time */
175 bool	kflag;				/* arcs to be deleted */
176 bool	sflag;				/* sum multiple gmon.out files */
177 bool	zflag;				/* zero time/called functions, too */
178 
179     /*
180      *	structure for various string lists
181      */
182 struct stringlist {
183     struct stringlist	*next;
184     char		*string;
185 };
186 struct stringlist	*elist;
187 struct stringlist	*Elist;
188 struct stringlist	*flist;
189 struct stringlist	*Flist;
190 struct stringlist	*kfromlist;
191 struct stringlist	*ktolist;
192 
193     /*
194      *	function declarations
195      */
196 /*
197 		addarc();
198 */
199 int		arccmp();
200 arctype		*arclookup();
201 /*
202 		asgnsamples();
203 		printblurb();
204 		cyclelink();
205 		dfn();
206 */
207 bool		dfn_busy();
208 /*
209 		dfn_findcycle();
210 */
211 bool		dfn_numbered();
212 /*
213 		dfn_post_visit();
214 		dfn_pre_visit();
215 		dfn_self_cycle();
216 */
217 nltype		**doarcs();
218 /*
219 		done();
220 		findcalls();
221 		flatprofheader();
222 		flatprofline();
223 */
224 bool		funcsymbol();
225 /*
226 		getnfile();
227 		getpfile();
228 		getstrtab();
229 		getsymtab();
230 		gettextspace();
231 		gprofheader();
232 		gprofline();
233 		main();
234 */
235 unsigned long	max();
236 int		membercmp();
237 unsigned long	min();
238 nltype		*nllookup();
239 FILE		*openpfile();
240 long		operandlength();
241 operandenum	operandmode();
242 char		*operandname();
243 /*
244 		printchildren();
245 		printcycle();
246 		printgprof();
247 		printmembers();
248 		printname();
249 		printparents();
250 		printprof();
251 		readsamples();
252 */
253 unsigned long	reladdr();
254 /*
255 		sortchildren();
256 		sortmembers();
257 		sortparents();
258 		tally();
259 		timecmp();
260 		topcmp();
261 */
262 int		totalcmp();
263 /*
264 		valcmp();
265 */
266 
267 #define	LESSTHAN	-1
268 #define	EQUALTO		0
269 #define	GREATERTHAN	1
270 
271 #define	DFNDEBUG	1
272 #define	CYCLEDEBUG	2
273 #define	ARCDEBUG	4
274 #define	TALLYDEBUG	8
275 #define	TIMEDEBUG	16
276 #define	SAMPLEDEBUG	32
277 #define	AOUTDEBUG	64
278 #define	CALLDEBUG	128
279 #define	LOOKUPDEBUG	256
280 #define	PROPDEBUG	512
281 #define	ANYDEBUG	1024
282