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