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>
67 * Historical scale factor in profil(2)'s algorithm for converting
68 * pc addresses to bucket numbers. This now just complicates the
69 * scaling and makes bucket:pc densities of more than 1/2 useless.
71 #define HISTORICAL_SCALE_2 2
78 size_t histcounter_size;
82 #define A_OUTNAME "a.out"
85 #define GMONSUM "gmon.sum"
89 * with pointers to the namelist entry of the parent and the child,
90 * a count of how many times this arc was traversed,
91 * and pointers to the next parent of this child and
92 * the next child of this parent.
95 struct nl *arc_parentp; /* pointer to parent's nl entry */
96 struct nl *arc_childp; /* pointer to child's nl entry */
97 long arc_count; /* num calls from parent to child */
98 double arc_time; /* time inherited along arc */
99 double arc_childtime; /* childtime inherited along arc */
100 struct arcstruct *arc_parentlist; /* parents-of-this-child list */
101 struct arcstruct *arc_childlist; /* children-of-this-parent list */
102 struct arcstruct *arc_next; /* list of arcs on cycle */
103 unsigned short arc_cyclecnt; /* num cycles involved in */
104 unsigned short arc_flags; /* see below */
106 typedef struct arcstruct arctype;
111 #define DEADARC 0x01 /* time should not propagate across the arc */
112 #define ONLIST 0x02 /* arc is on list of arcs in cycles */
116 * for each external in the specified file we gather
117 * its address, the number of calls and compute its share of CPU time.
120 const char *name; /* the name */
121 unsigned long value; /* the pc entry point */
122 unsigned long svalue; /* entry point aligned to histograms */
123 double time; /* ticks in this routine */
124 double childtime; /* cumulative ticks in children */
125 long ncall; /* how many times called */
126 long npropcall; /* times called by live arcs */
127 long selfcalls; /* how many calls to self */
128 double propfraction; /* what % of time propagates */
129 double propself; /* how much self time propagates */
130 double propchild; /* how much child time propagates */
131 short printflag; /* should this be printed? */
132 short flags; /* see below */
133 int index; /* index in the graph list */
134 int toporder; /* graph call chain top-sort order */
135 int cycleno; /* internal number of cycle on */
136 int parentcnt; /* number of live parent arcs */
137 struct nl *cyclehead; /* pointer to head of cycle */
138 struct nl *cnext; /* pointer to next member of cycle */
139 arctype *parents; /* list of caller arcs */
140 arctype *children; /* list of callee arcs */
142 typedef struct nl nltype;
144 nltype *nl; /* the whole namelist */
145 nltype *npe; /* the virtual end of the namelist */
146 int nname; /* the number of function names */
148 #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */
149 #define CYCLEHEAD 0x10 /* node marked as head of a cycle */
150 #define VISITED 0x20 /* node visited during a cycle */
154 * for each subcycle within an identified cycle, we gather
155 * its size and the list of included arcs.
158 int size; /* length of cycle */
159 struct cl *next; /* next member of list */
160 arctype *list[1]; /* list of arcs in cycle */
161 /* actually longer */
163 typedef struct cl cltype;
165 arctype *archead; /* the head of arcs in current cycle list */
166 cltype *cyclehead; /* the head of the list */
167 int cyclecnt; /* the number of cycles found */
168 #define CYCLEMAX 100 /* maximum cycles before cutting one of them */
171 * flag which marks a nl entry as topologically ``busy''
172 * flag which marks a nl entry as topologically ``not_numbered''
178 * namelist entries for cycle headers.
179 * the number of discovered cycles.
181 nltype *cyclenl; /* cycle header namelist */
182 int ncycle; /* number of cycles discovered */
185 * The header on the gmon.out file.
186 * gmon.out consists of a struct phdr (defined in gmon.h)
187 * and then an array of ncnt samples representing the
188 * discretized program counter values.
190 * Backward compatible old style header
201 * Each discretized pc sample has
202 * a count of the number of samples in its range
206 unsigned long s_lowpc; /* lowpc from the profile file */
207 unsigned long s_highpc; /* highpc from the profile file */
208 unsigned long lowpc, highpc; /* range profiled, in historical units */
209 unsigned sampbytes; /* number of bytes of samples */
210 int nsamples; /* number of samples */
211 double actime; /* accumulated time thus far for putprofline */
212 double totime; /* total time for all routines */
213 double printtime; /* total of time being printed */
214 double scale; /* scale factor converting samples to pc
215 values: each sample covers scale bytes */
216 unsigned char *textspace; /* text space of a.out in core */
217 int cyclethreshold; /* with -C, minimum cycle size to ignore */
220 * option flags, from a to z.
222 bool aflag; /* suppress static functions */
223 bool bflag; /* blurbs, too */
224 bool Cflag; /* find cut-set to eliminate cycles */
225 bool dflag; /* debugging options */
226 bool eflag; /* specific functions excluded */
227 bool Eflag; /* functions excluded with time */
228 bool fflag; /* specific functions requested */
229 bool Fflag; /* functions requested with time */
230 bool kflag; /* arcs to be deleted */
231 bool Kflag; /* use the running kernel for symbols */
232 bool sflag; /* sum multiple gmon.out files */
233 bool uflag; /* suppress symbols hidden from C */
234 bool zflag; /* zero time/called functions, too */
237 * structure for various string lists
240 struct stringlist *next;
243 struct stringlist *elist;
244 struct stringlist *Elist;
245 struct stringlist *flist;
246 struct stringlist *Flist;
247 struct stringlist *kfromlist;
248 struct stringlist *ktolist;
251 * function declarations
253 void addarc(nltype *, nltype *, long);
254 bool addcycle(arctype **, arctype **);
255 void addlist(struct stringlist *, char *);
256 void alignentries(void);
257 int aout_getnfile(const char *, char ***);
258 int arccmp(arctype *, arctype *);
259 arctype *arclookup(nltype *, nltype *);
260 void asgnsamples(void);
261 void compresslist(void);
262 bool cycleanalyze(void);
263 void cyclelink(void);
264 void cycletime(void);
265 bool descend(nltype *, arctype **, arctype **);
267 bool dfn_busy(nltype *);
268 void dfn_findcycle(nltype *);
270 bool dfn_numbered(nltype *);
271 void dfn_post_visit(nltype *);
272 void dfn_pre_visit(nltype *);
273 void dfn_self_cycle(nltype *);
274 nltype **doarcs(void);
277 void dumpsum(const char *);
278 int elf_getnfile(const char *, char ***);
279 void flatprofheader(void);
280 void flatprofline(nltype *);
281 void getpfile(char *);
282 void gprofheader(void);
283 void gprofline(register nltype *);
285 void inheritflags(nltype *);
286 int kernel_getnfile(const char *, char ***);
290 unsigned long max(unsigned long, unsigned long);
291 int membercmp(nltype *, nltype *);
292 unsigned long min(unsigned long, unsigned long);
293 nltype *nllookup(unsigned long);
294 bool onlist(struct stringlist *, const char *);
295 FILE *openpfile(char *);
296 void printblurb(const char *);
297 void printchildren(nltype *);
298 void printcycle(nltype *);
299 void printgprof(nltype **);
300 void printindex(void);
301 void printmembers(nltype *);
302 void printname(nltype *);
303 void printparents(nltype *);
304 void printprof(void);
305 void printsubcycle(cltype *);
306 void readsamples(FILE *);
307 void sortchildren(nltype *);
308 void sortmembers(nltype *);
309 void sortparents(nltype *);
310 void tally(struct rawarc *);
311 void timepropagate(nltype *);
312 int totalcmp(const void *, const void *);
316 #define GREATERTHAN 1
323 #define SAMPLEDEBUG 32
325 #define CALLDEBUG 128
326 #define LOOKUPDEBUG 256
327 #define PROPDEBUG 512
328 #define BREAKCYCLE 1024
329 #define SUBCYCLELIST 2048
330 #define ANYDEBUG 4096