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