xref: /original-bsd/usr.bin/gprof/gprof.h (revision 9de3f1a2)
1     /* sccsid:  @(#)gprof.h	1.13 (Berkeley) 06/18/82 */
2 
3 #include <stdio.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <a.out.h>
7 #include <pagsiz.h>
8 #include "gcrt0.h"
9 
10     /*
11      *	who am i, for error messages.
12      */
13 char	*whoami;
14 
15     /*
16      * booleans
17      */
18 typedef int	bool;
19 #define	FALSE	0
20 #define	TRUE	1
21 
22     /*
23      *	opcode of the `calls' instruction
24      */
25 #define	CALLS	0xfb
26 
27     /*
28      *	ticks per second
29      */
30 #define	HZ	60
31 
32 typedef	short UNIT;		/* unit of profiling */
33 char	*a_outname;
34 #define	A_OUTNAME		"a.out"
35 
36 char	*gmonname;
37 #define	GMONNAME		"gmon.out"
38 #define	GMONSUM			"gmon.sum"
39 
40     /*
41      *	the directory where the descriptions of the fields
42      *	of the profiles are kept.
43      */
44 #define	BLURBLIB		"/usr/lib/"
45 
46     /*
47      *	a constructed arc,
48      *	    with pointers to the namelist entry of the parent and the child,
49      *	    a count of how many times this arc was traversed,
50      *	    and pointers to the next parent of this child and
51      *		the next child of this parent.
52      */
53 struct arcstruct {
54     struct nl		*arc_parentp;	/* pointer to parent's nl entry */
55     struct nl		*arc_childp;	/* pointer to child's nl entry */
56     long		arc_count;	/* how calls from parent to child */
57     double		arc_time;	/* time inherited along arc */
58     double		arc_childtime;	/* childtime inherited along arc */
59     struct arcstruct	*arc_parentlist; /* parents-of-this-child list */
60     struct arcstruct	*arc_childlist;	/* children-of-this-parent list */
61 };
62 typedef struct arcstruct	arctype;
63 
64     /*
65      * The symbol table;
66      * for each external in the specified file we gather
67      * its address, the number of calls and compute its share of cpu time.
68      */
69 struct nl {
70     char		*name;		/* the name */
71     unsigned long	value;		/* the pc entry point */
72     double		time;		/* ticks in this routine */
73     double		childtime;	/* cumulative ticks in children */
74     long		ncall;		/* how many times called */
75     long		selfcalls;	/* how many calls to self */
76     double		propfraction;	/* what % of time propagates */
77     double		propself;	/* how much self time propagates */
78     double		propchild;	/* how much child time propagates */
79     bool		printflag;	/* should this be printed? */
80     int			index;		/* index in the graph list */
81     int			toporder;	/* graph call chain top-sort order */
82     int			cycleno;	/* internal number of cycle on */
83     struct nl		*cyclehead;	/* pointer to head of cycle */
84     struct nl		*cnext;		/* pointer to next member of cycle */
85     arctype		*parents;	/* list of caller arcs */
86     arctype		*children;	/* list of callee arcs */
87 };
88 typedef struct nl	nltype;
89 
90 nltype	*nl;			/* the whole namelist */
91 nltype	*npe;			/* the virtual end of the namelist */
92 int	nname;			/* the number of function names */
93 
94     /*
95      *	flag which marks a nl entry as topologically ``busy''
96      */
97 #define	DFN_BUSY	-1
98 
99     /*
100      *	namelist entries for cycle headers.
101      *	the number of discovered cycles.
102      */
103 nltype	*cyclenl;		/* cycle header namelist */
104 int	ncycle;			/* number of cycles discovered */
105 
106     /*
107      * The header on the gmon.out file.
108      * gmon.out consists of one of these headers,
109      * and then an array of ncnt samples
110      * representing the discretized program counter values.
111      *	this should be a struct phdr, but since everything is done
112      *	as UNITs, this is in UNITs too.
113      */
114 struct hdr {
115     UNIT	*lowpc;
116     UNIT	*highpc;
117     int	ncnt;
118 };
119 
120 struct hdr	h;
121 
122 int	debug;
123 
124     /*
125      * Each discretized pc sample has
126      * a count of the number of samples in its range
127      */
128 unsigned UNIT	*samples;
129 
130 unsigned long	s_lowpc;	/* lowpc from the profile file */
131 unsigned long	s_highpc;	/* highpc from the profile file */
132 unsigned lowpc, highpc;		/* range profiled, in UNIT's */
133 unsigned sampbytes;		/* number of bytes of samples */
134 int	nsamples;		/* number of samples */
135 double	actime;			/* accumulated time thus far for putprofline */
136 double	totime;			/* total time for all routines */
137 double	printtime;		/* total of time being printed */
138 double	scale;			/* scale factor converting samples to pc
139 				   values: each sample covers scale bytes */
140 char	*strtab;		/* string table in core */
141 off_t	ssiz;			/* size of the string table */
142 struct	exec xbuf;		/* exec header of a.out */
143 unsigned char	*textspace;		/* text space of a.out in core */
144 
145     /*
146      *	option flags, from a to z.
147      */
148 bool	aflag;				/* suppress static functions */
149 bool	bflag;				/* blurbs, too */
150 bool	cflag;				/* discovered call graph, too */
151 bool	dflag;				/* debugging options */
152 bool	eflag;				/* specific functions excluded */
153 bool	Eflag;				/* functions excluded with time */
154 bool	fflag;				/* specific functions requested */
155 bool	Fflag;				/* functions requested with time */
156 bool	sflag;				/* sum multiple gmon.out files */
157 bool	zflag;				/* zero time/called functions, too */
158 
159     /*
160      *	structure for various string lists
161      */
162 struct stringlist {
163     struct stringlist	*next;
164     char		*string;
165 };
166 struct stringlist	*elist;
167 struct stringlist	*Elist;
168 struct stringlist	*flist;
169 struct stringlist	*Flist;
170 
171     /*
172      *	register for pc relative addressing
173      */
174 #define	PC	0xf
175 
176 enum opermodes {
177     literal, indexed, reg, regdef, autodec, autoinc, autoincdef,
178     bytedisp, bytedispdef, worddisp, worddispdef, longdisp, longdispdef,
179     immediate, absolute, byterel, bytereldef, wordrel, wordreldef,
180     longrel, longreldef
181 };
182 typedef enum opermodes	operandenum;
183 
184 struct modebyte {
185     unsigned int	regfield:4;
186     unsigned int	modefield:4;
187 };
188 
189     /*
190      *	function declarations
191      */
192 		addarc();
193 int		arccmp();
194 arctype		*arclookup();
195 		asgnsamples();
196 		printblurb();
197 		cyclelink();
198 		dfn();
199 bool		dfn_busy();
200 		dfn_findcycle();
201 bool		dfn_numbered();
202 		dfn_post_visit();
203 		dfn_pre_visit();
204 		dfn_self_cycle();
205 		doarcs();
206 		done();
207 		findcalls();
208 		flatprofheader();
209 		flatprofline();
210 bool		funcsymbol();
211 		getnfile();
212 		getpfile();
213 		getstrtab();
214 		getsymtab();
215 		gettextspace();
216 		gprofheader();
217 		gprofline();
218 		main();
219 unsigned long	max();
220 int		membercmp();
221 unsigned long	min();
222 nltype		*nllookup();
223 FILE		*openpfile();
224 long		operandlength();
225 operandenum	operandmode();
226 char		*operandname();
227 		printchildren();
228 		printcycle();
229 		printgprof();
230 		printmembers();
231 		printname();
232 		printparents();
233 		printprof();
234 		readsamples();
235 unsigned long	reladdr();
236 		sortchildren();
237 		sortmembers();
238 		sortparents();
239 		tally();
240 		timecmp();
241 		topcmp();
242 int		totalcmp();
243 		valcmp();
244 
245 #define	LESSTHAN	-1
246 #define	EQUALTO		0
247 #define	GREATERTHAN	1
248 
249 #define	DFNDEBUG	1
250 #define	CYCLEDEBUG	2
251 #define	ARCDEBUG	4
252 #define	TALLYDEBUG	8
253 #define	TIMEDEBUG	16
254 #define	SAMPLEDEBUG	32
255 #define	AOUTDEBUG	64
256 #define	CALLSDEBUG	128
257 #define	LOOKUPDEBUG	256
258 #define	PROPDEBUG	512
259 #define	ANYDEBUG	1024
260