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