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