Commit | Line | Data |
---|---|---|
bc19d06b | 1 | /* sccsid: @(#)gprof.h 1.16 (Berkeley) %G% */ |
a8242a8d PK |
2 | |
3 | #include <stdio.h> | |
4 | #include <sys/types.h> | |
5 | #include <sys/stat.h> | |
6 | #include <a.out.h> | |
7 | #include <pagsiz.h> | |
bb9c5045 | 8 | #include "gcrt0.h" |
a8242a8d | 9 | |
ad3b82ad PK |
10 | /* |
11 | * who am i, for error messages. | |
12 | */ | |
13 | char *whoami; | |
14 | ||
7ec9eedc PK |
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 | ||
a8242a8d PK |
27 | /* |
28 | * ticks per second | |
29 | */ | |
89bcca98 | 30 | long hz; |
a8242a8d PK |
31 | |
32 | typedef short UNIT; /* unit of profiling */ | |
33 | char *a_outname; | |
34 | #define A_OUTNAME "a.out" | |
35 | ||
31f0a970 PK |
36 | char *gmonname; |
37 | #define GMONNAME "gmon.out" | |
0c0ac747 | 38 | #define GMONSUM "gmon.sum" |
83dc50ba KM |
39 | |
40 | /* | |
bc19d06b | 41 | * blurbs on the flat and graph profiles. |
83dc50ba | 42 | */ |
bc19d06b PK |
43 | #define FLAT_BLURB "/usr/lib/gprof.flat.blurb" |
44 | #define CALLG_BLURB "/usr/lib/gprof.callg.blurb" | |
a8242a8d PK |
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 | ||
ad3b82ad PK |
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 | */ | |
a8242a8d | 69 | struct nl { |
ad3b82ad PK |
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 */ | |
a441395b PK |
76 | double propfraction; /* what % of time propagates */ |
77 | double propself; /* how much self time propagates */ | |
78 | double propchild; /* how much child time propagates */ | |
7ec9eedc | 79 | bool printflag; /* should this be printed? */ |
ad3b82ad PK |
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 */ | |
a8242a8d PK |
87 | }; |
88 | typedef struct nl nltype; | |
89 | ||
90 | nltype *nl; /* the whole namelist */ | |
91 | nltype *npe; /* the virtual end of the namelist */ | |
ad3b82ad | 92 | int nname; /* the number of function names */ |
a8242a8d PK |
93 | |
94 | /* | |
95 | * flag which marks a nl entry as topologically ``busy'' | |
80ebf400 | 96 | * flag which marks a nl entry as topologically ``not_numbered'' |
a8242a8d PK |
97 | */ |
98 | #define DFN_BUSY -1 | |
80ebf400 | 99 | #define DFN_NAN 0 |
a8242a8d PK |
100 | |
101 | /* | |
ad3b82ad PK |
102 | * namelist entries for cycle headers. |
103 | * the number of discovered cycles. | |
104 | */ | |
105 | nltype *cyclenl; /* cycle header namelist */ | |
106 | int ncycle; /* number of cycles discovered */ | |
107 | ||
108 | /* | |
109 | * The header on the gmon.out file. | |
110 | * gmon.out consists of one of these headers, | |
111 | * and then an array of ncnt samples | |
112 | * representing the discretized program counter values. | |
113 | * this should be a struct phdr, but since everything is done | |
114 | * as UNITs, this is in UNITs too. | |
a8242a8d | 115 | */ |
a8242a8d | 116 | struct hdr { |
ad3b82ad PK |
117 | UNIT *lowpc; |
118 | UNIT *highpc; | |
119 | int ncnt; | |
a8242a8d PK |
120 | }; |
121 | ||
122 | struct hdr h; | |
123 | ||
124 | int debug; | |
125 | ||
ad3b82ad PK |
126 | /* |
127 | * Each discretized pc sample has | |
128 | * a count of the number of samples in its range | |
129 | */ | |
a8242a8d PK |
130 | unsigned UNIT *samples; |
131 | ||
16152db8 PK |
132 | unsigned long s_lowpc; /* lowpc from the profile file */ |
133 | unsigned long s_highpc; /* highpc from the profile file */ | |
134 | unsigned lowpc, highpc; /* range profiled, in UNIT's */ | |
a8242a8d PK |
135 | unsigned sampbytes; /* number of bytes of samples */ |
136 | int nsamples; /* number of samples */ | |
137 | double actime; /* accumulated time thus far for putprofline */ | |
138 | double totime; /* total time for all routines */ | |
7ec9eedc | 139 | double printtime; /* total of time being printed */ |
a8242a8d PK |
140 | double scale; /* scale factor converting samples to pc |
141 | values: each sample covers scale bytes */ | |
142 | char *strtab; /* string table in core */ | |
143 | off_t ssiz; /* size of the string table */ | |
144 | struct exec xbuf; /* exec header of a.out */ | |
29da1d26 | 145 | unsigned char *textspace; /* text space of a.out in core */ |
a8242a8d | 146 | |
1c0c4c82 PK |
147 | /* |
148 | * option flags, from a to z. | |
149 | */ | |
7ec9eedc PK |
150 | bool aflag; /* suppress static functions */ |
151 | bool bflag; /* blurbs, too */ | |
152 | bool cflag; /* discovered call graph, too */ | |
153 | bool dflag; /* debugging options */ | |
154 | bool eflag; /* specific functions excluded */ | |
a441395b | 155 | bool Eflag; /* functions excluded with time */ |
7ec9eedc | 156 | bool fflag; /* specific functions requested */ |
a441395b | 157 | bool Fflag; /* functions requested with time */ |
7ec9eedc PK |
158 | bool sflag; /* sum multiple gmon.out files */ |
159 | bool zflag; /* zero time/called functions, too */ | |
35e3e365 | 160 | |
a441395b PK |
161 | /* |
162 | * structure for various string lists | |
163 | */ | |
164 | struct stringlist { | |
165 | struct stringlist *next; | |
166 | char *string; | |
167 | }; | |
168 | struct stringlist *elist; | |
169 | struct stringlist *Elist; | |
170 | struct stringlist *flist; | |
171 | struct stringlist *Flist; | |
172 | ||
35e3e365 PK |
173 | /* |
174 | * register for pc relative addressing | |
175 | */ | |
176 | #define PC 0xf | |
a8242a8d | 177 | |
35e3e365 PK |
178 | enum opermodes { |
179 | literal, indexed, reg, regdef, autodec, autoinc, autoincdef, | |
180 | bytedisp, bytedispdef, worddisp, worddispdef, longdisp, longdispdef, | |
181 | immediate, absolute, byterel, bytereldef, wordrel, wordreldef, | |
182 | longrel, longreldef | |
183 | }; | |
184 | typedef enum opermodes operandenum; | |
185 | ||
186 | struct modebyte { | |
187 | unsigned int regfield:4; | |
188 | unsigned int modefield:4; | |
189 | }; | |
190 | ||
191 | /* | |
192 | * function declarations | |
193 | */ | |
194 | addarc(); | |
195 | int arccmp(); | |
a8242a8d | 196 | arctype *arclookup(); |
35e3e365 | 197 | asgnsamples(); |
1c0c4c82 | 198 | printblurb(); |
35e3e365 PK |
199 | cyclelink(); |
200 | dfn(); | |
a8242a8d | 201 | bool dfn_busy(); |
35e3e365 PK |
202 | dfn_findcycle(); |
203 | bool dfn_numbered(); | |
204 | dfn_post_visit(); | |
205 | dfn_pre_visit(); | |
206 | dfn_self_cycle(); | |
207 | doarcs(); | |
208 | done(); | |
209 | findcalls(); | |
210 | flatprofheader(); | |
211 | flatprofline(); | |
3f722622 | 212 | bool funcsymbol(); |
35e3e365 PK |
213 | getnfile(); |
214 | getpfile(); | |
215 | getstrtab(); | |
216 | getsymtab(); | |
217 | gettextspace(); | |
218 | gprofheader(); | |
219 | gprofline(); | |
220 | main(); | |
221 | unsigned long max(); | |
222 | int membercmp(); | |
223 | unsigned long min(); | |
224 | nltype *nllookup(); | |
225 | FILE *openpfile(); | |
226 | long operandlength(); | |
227 | operandenum operandmode(); | |
228 | char *operandname(); | |
229 | printchildren(); | |
230 | printcycle(); | |
231 | printgprof(); | |
232 | printmembers(); | |
233 | printname(); | |
234 | printparents(); | |
235 | printprof(); | |
236 | readsamples(); | |
237 | unsigned long reladdr(); | |
238 | sortchildren(); | |
239 | sortmembers(); | |
240 | sortparents(); | |
241 | tally(); | |
242 | timecmp(); | |
243 | topcmp(); | |
244 | int totalcmp(); | |
245 | valcmp(); | |
a8242a8d PK |
246 | |
247 | #define LESSTHAN -1 | |
248 | #define EQUALTO 0 | |
249 | #define GREATERTHAN 1 | |
250 | ||
251 | #define DFNDEBUG 1 | |
252 | #define CYCLEDEBUG 2 | |
253 | #define ARCDEBUG 4 | |
254 | #define TALLYDEBUG 8 | |
255 | #define TIMEDEBUG 16 | |
256 | #define SAMPLEDEBUG 32 | |
257 | #define AOUTDEBUG 64 | |
29da1d26 PK |
258 | #define CALLSDEBUG 128 |
259 | #define LOOKUPDEBUG 256 | |
a441395b PK |
260 | #define PROPDEBUG 512 |
261 | #define ANYDEBUG 1024 |