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