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