2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)gprof.h 8.1 (Berkeley) 6/6/93
33 #include <sys/types.h>
70 * Historical scale factor in profil(2)'s algorithm for converting
71 * pc addresses to bucket numbers. This now just complicates the
72 * scaling and makes bucket:pc densities of more than 1/2 useless.
74 #define HISTORICAL_SCALE_2 2
81 size_t histcounter_size;
85 #define A_OUTNAME "a.out"
88 #define GMONSUM "gmon.sum"
92 * with pointers to the namelist entry of the parent and the child,
93 * a count of how many times this arc was traversed,
94 * and pointers to the next parent of this child and
95 * the next child of this parent.
98 struct nl *arc_parentp; /* pointer to parent's nl entry */
99 struct nl *arc_childp; /* pointer to child's nl entry */
100 long arc_count; /* num calls from parent to child */
101 double arc_time; /* time inherited along arc */
102 double arc_childtime; /* childtime inherited along arc */
103 struct arcstruct *arc_parentlist; /* parents-of-this-child list */
104 struct arcstruct *arc_childlist; /* children-of-this-parent list */
105 struct arcstruct *arc_next; /* list of arcs on cycle */
106 unsigned short arc_cyclecnt; /* num cycles involved in */
107 unsigned short arc_flags; /* see below */
109 typedef struct arcstruct arctype;
114 #define DEADARC 0x01 /* time should not propagate across the arc */
115 #define ONLIST 0x02 /* arc is on list of arcs in cycles */
119 * for each external in the specified file we gather
120 * its address, the number of calls and compute its share of CPU time.
123 const char *name; /* the name */
124 unsigned long value; /* the pc entry point */
125 unsigned long svalue; /* entry point aligned to histograms */
126 double time; /* ticks in this routine */
127 double childtime; /* cumulative ticks in children */
128 long ncall; /* how many times called */
129 long npropcall; /* times called by live arcs */
130 long selfcalls; /* how many calls to self */
131 double propfraction; /* what % of time propagates */
132 double propself; /* how much self time propagates */
133 double propchild; /* how much child time propagates */
134 short printflag; /* should this be printed? */
135 short flags; /* see below */
136 int index; /* index in the graph list */
137 int toporder; /* graph call chain top-sort order */
138 int cycleno; /* internal number of cycle on */
139 int parentcnt; /* number of live parent arcs */
140 struct nl *cyclehead; /* pointer to head of cycle */
141 struct nl *cnext; /* pointer to next member of cycle */
142 arctype *parents; /* list of caller arcs */
143 arctype *children; /* list of callee arcs */
145 typedef struct nl nltype;
147 nltype *nl; /* the whole namelist */
148 nltype *npe; /* the virtual end of the namelist */
149 int nname; /* the number of function names */
151 #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */
152 #define CYCLEHEAD 0x10 /* node marked as head of a cycle */
153 #define VISITED 0x20 /* node visited during a cycle */
157 * for each subcycle within an identified cycle, we gather
158 * its size and the list of included arcs.
161 int size; /* length of cycle */
162 struct cl *next; /* next member of list */
163 arctype *list[1]; /* list of arcs in cycle */
164 /* actually longer */
166 typedef struct cl cltype;
168 arctype *archead; /* the head of arcs in current cycle list */
169 cltype *cyclehead; /* the head of the list */
170 int cyclecnt; /* the number of cycles found */
171 #define CYCLEMAX 100 /* maximum cycles before cutting one of them */
174 * flag which marks a nl entry as topologically ``busy''
175 * flag which marks a nl entry as topologically ``not_numbered''
181 * namelist entries for cycle headers.
182 * the number of discovered cycles.
184 nltype *cyclenl; /* cycle header namelist */
185 int ncycle; /* number of cycles discovered */
188 * The header on the gmon.out file.
189 * gmon.out consists of a struct phdr (defined in gmon.h)
190 * and then an array of ncnt samples representing the
191 * discretized program counter values.
193 * Backward compatible old style header
204 * Each discretized pc sample has
205 * a count of the number of samples in its range
209 unsigned long s_lowpc; /* lowpc from the profile file */
210 unsigned long s_highpc; /* highpc from the profile file */
211 unsigned long lowpc, highpc; /* range profiled, in historical units */
212 unsigned sampbytes; /* number of bytes of samples */
213 int nsamples; /* number of samples */
214 double actime; /* accumulated time thus far for putprofline */
215 double totime; /* total time for all routines */
216 double printtime; /* total of time being printed */
217 double scale; /* scale factor converting samples to pc
218 values: each sample covers scale bytes */
219 unsigned char *textspace; /* text space of a.out in core */
220 int cyclethreshold; /* with -C, minimum cycle size to ignore */
223 * option flags, from a to z.
225 bool aflag; /* suppress static functions */
226 bool bflag; /* blurbs, too */
227 bool Cflag; /* find cut-set to eliminate cycles */
228 bool dflag; /* debugging options */
229 bool eflag; /* specific functions excluded */
230 bool Eflag; /* functions excluded with time */
231 bool fflag; /* specific functions requested */
232 bool Fflag; /* functions requested with time */
233 bool kflag; /* arcs to be deleted */
234 bool Kflag; /* use the running kernel for symbols */
235 bool sflag; /* sum multiple gmon.out files */
236 bool uflag; /* suppress symbols hidden from C */
237 bool zflag; /* zero time/called functions, too */
240 * structure for various string lists
243 struct stringlist *next;
246 struct stringlist *elist;
247 struct stringlist *Elist;
248 struct stringlist *flist;
249 struct stringlist *Flist;
250 struct stringlist *kfromlist;
251 struct stringlist *ktolist;
254 * function declarations
256 void addarc(nltype *, nltype *, long);
257 bool addcycle(arctype **, arctype **);
258 void addlist(struct stringlist *, char *);
259 void alignentries(void);
260 int aout_getnfile(const char *, char ***);
262 arctype *arclookup();
263 void asgnsamples(void);
264 void compresslist(void);
265 bool cycleanalyze(void);
266 void cyclelink(void);
267 void cycletime(void);
268 bool descend(nltype *, arctype **, arctype **);
271 void dfn_findcycle(nltype *);
274 void dfn_post_visit(nltype *);
275 void dfn_pre_visit(nltype *);
276 void dfn_self_cycle(nltype *);
280 void dumpsum(char *);
281 int elf_getnfile(const char *, char ***);
282 void flatprofheader(void);
283 void flatprofline(nltype *);
284 void getpfile(char *);
290 void inheritflags(nltype *);
291 int kernel_getnfile(const char *, char ***);
299 bool onlist(struct stringlist *, const char *);
301 long operandlength();
302 operandenum operandmode();
304 void printblurb(char *);
305 void printchildren(nltype *);
306 void printcycle(nltype *);
307 void printgprof(nltype **);
308 void printindex(void);
309 void printmembers(nltype *);
310 void printname(nltype *);
311 void printparents(nltype *);
312 void printprof(void);
313 void printsubcycle(cltype *);
314 void readsamples(FILE *);
315 unsigned long reladdr();
316 void sortchildren(nltype *);
317 void sortmembers(nltype *);
318 void sortparents(nltype *);
319 void tally(struct rawarc *);
320 void timepropagate(nltype *);
325 #define GREATERTHAN 1
332 #define SAMPLEDEBUG 32
334 #define CALLDEBUG 128
335 #define LOOKUPDEBUG 256
336 #define PROPDEBUG 512
337 #define BREAKCYCLE 1024
338 #define SUBCYCLELIST 2048
339 #define ANYDEBUG 4096