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
87 EXTERN size_t histcounter_size;
88 EXTERN int histcounter_type;
90 EXTERN char *a_outname;
91 #define A_OUTNAME "a.out"
93 EXTERN char *gmonname;
94 #define GMONSUM "gmon.sum"
98 * with pointers to the namelist entry of the parent and the child,
99 * a count of how many times this arc was traversed,
100 * and pointers to the next parent of this child and
101 * the next child of this parent.
104 struct nl *arc_parentp; /* pointer to parent's nl entry */
105 struct nl *arc_childp; /* pointer to child's nl entry */
106 long arc_count; /* num calls from parent to child */
107 double arc_time; /* time inherited along arc */
108 double arc_childtime; /* childtime inherited along arc */
109 struct arcstruct *arc_parentlist; /* parents-of-this-child list */
110 struct arcstruct *arc_childlist; /* children-of-this-parent list */
111 struct arcstruct *arc_next; /* list of arcs on cycle */
112 unsigned short arc_cyclecnt; /* num cycles involved in */
113 unsigned short arc_flags; /* see below */
115 typedef struct arcstruct arctype;
120 #define DEADARC 0x01 /* time should not propagate across the arc */
121 #define ONLIST 0x02 /* arc is on list of arcs in cycles */
125 * for each external in the specified file we gather
126 * its address, the number of calls and compute its share of CPU time.
129 const char *name; /* the name */
130 unsigned long value; /* the pc entry point */
131 unsigned long svalue; /* entry point aligned to histograms */
132 double time; /* ticks in this routine */
133 double childtime; /* cumulative ticks in children */
134 long ncall; /* how many times called */
135 long npropcall; /* times called by live arcs */
136 long selfcalls; /* how many calls to self */
137 double propfraction; /* what % of time propagates */
138 double propself; /* how much self time propagates */
139 double propchild; /* how much child time propagates */
140 short printflag; /* should this be printed? */
141 short flags; /* see below */
142 int index; /* index in the graph list */
143 int toporder; /* graph call chain top-sort order */
144 int cycleno; /* internal number of cycle on */
145 int parentcnt; /* number of live parent arcs */
146 struct nl *cyclehead; /* pointer to head of cycle */
147 struct nl *cnext; /* pointer to next member of cycle */
148 arctype *parents; /* list of caller arcs */
149 arctype *children; /* list of callee arcs */
151 typedef struct nl nltype;
153 EXTERN nltype *nl; /* the whole namelist */
154 EXTERN nltype *npe; /* the virtual end of the namelist */
155 EXTERN int nname; /* the number of function names */
157 #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */
158 #define CYCLEHEAD 0x10 /* node marked as head of a cycle */
159 #define VISITED 0x20 /* node visited during a cycle */
163 * for each subcycle within an identified cycle, we gather
164 * its size and the list of included arcs.
167 int size; /* length of cycle */
168 struct cl *next; /* next member of list */
169 arctype *list[1]; /* list of arcs in cycle */
170 /* actually longer */
172 typedef struct cl cltype;
174 EXTERN arctype *archead; /* the head of arcs in current cycle list */
175 EXTERN cltype *cyclehead; /* the head of the list */
176 EXTERN int cyclecnt; /* the number of cycles found */
177 #define CYCLEMAX 100 /* maximum cycles before cutting one of them */
180 * flag which marks a nl entry as topologically ``busy''
181 * flag which marks a nl entry as topologically ``not_numbered''
187 * namelist entries for cycle headers.
188 * the number of discovered cycles.
190 EXTERN nltype *cyclenl; /* cycle header namelist */
191 EXTERN int ncycle; /* number of cycles discovered */
194 * The header on the gmon.out file.
195 * gmon.out consists of a struct phdr (defined in gmon.h)
196 * and then an array of ncnt samples representing the
197 * discretized program counter values.
199 * Backward compatible old style header
210 * Each discretized pc sample has
211 * a count of the number of samples in its range
213 EXTERN double *samples;
215 EXTERN unsigned long s_lowpc; /* lowpc from the profile file */
216 EXTERN unsigned long s_highpc; /* highpc from the profile file */
217 /* range profiled, in historical units */
218 EXTERN unsigned long lowpc, highpc;
219 EXTERN unsigned sampbytes; /* number of bytes of samples */
220 EXTERN int nsamples; /* number of samples */
221 /* accumulated time thus far for putprofline */
222 EXTERN double actime;
223 EXTERN double totime; /* total time for all routines */
224 EXTERN double printtime; /* total of time being printed */
225 EXTERN double scale; /* scale factor converting samples to pc
226 values: each sample covers scale bytes */
227 EXTERN unsigned char *textspace; /* text space of a.out in core */
228 /* with -C, minimum cycle size to ignore */
229 EXTERN int cyclethreshold;
232 * option flags, from a to z.
234 EXTERN bool aflag; /* suppress static functions */
235 EXTERN bool bflag; /* blurbs, too */
236 EXTERN bool Cflag; /* find cut-set to eliminate cycles */
237 EXTERN bool dflag; /* debugging options */
238 EXTERN bool eflag; /* specific functions excluded */
239 EXTERN bool Eflag; /* functions excluded with time */
240 EXTERN bool fflag; /* specific functions requested */
241 EXTERN bool Fflag; /* functions requested with time */
242 EXTERN bool kflag; /* arcs to be deleted */
243 EXTERN bool Kflag; /* use the running kernel for symbols */
244 EXTERN bool sflag; /* sum multiple gmon.out files */
245 EXTERN bool uflag; /* suppress symbols hidden from C */
246 EXTERN bool zflag; /* zero time/called functions, too */
249 * structure for various string lists
252 struct stringlist *next;
255 extern struct stringlist *elist;
256 extern struct stringlist *Elist;
257 extern struct stringlist *flist;
258 extern struct stringlist *Flist;
259 extern struct stringlist *kfromlist;
260 extern struct stringlist *ktolist;
263 * function declarations
265 void addarc(nltype *, nltype *, long);
266 bool addcycle(arctype **, arctype **);
267 void addlist(struct stringlist *, char *);
268 void alignentries(void);
270 int aout_getnfile(const char *, char ***);
272 int arccmp(arctype *, arctype *);
273 arctype *arclookup(nltype *, nltype *);
274 void asgnsamples(void);
275 void compresslist(void);
276 bool cycleanalyze(void);
277 void cyclelink(void);
278 void cycletime(void);
279 bool descend(nltype *, arctype **, arctype **);
281 bool dfn_busy(nltype *);
282 void dfn_findcycle(nltype *);
284 bool dfn_numbered(nltype *);
285 void dfn_post_visit(nltype *);
286 void dfn_pre_visit(nltype *);
287 void dfn_self_cycle(nltype *);
288 nltype **doarcs(void);
291 void dumpsum(const char *);
292 int elf_getnfile(const char *, char ***);
293 void flatprofheader(void);
294 void flatprofline(nltype *);
295 void getpfile(char *);
296 void gprofheader(void);
297 void gprofline(register nltype *);
299 void inheritflags(nltype *);
300 int kernel_getnfile(const char *, char ***);
304 unsigned long max(unsigned long, unsigned long);
305 int membercmp(nltype *, nltype *);
306 unsigned long min(unsigned long, unsigned long);
307 nltype *nllookup(unsigned long);
308 bool onlist(struct stringlist *, const char *);
309 FILE *openpfile(char *);
310 void printblurb(const char *);
311 void printchildren(nltype *);
312 void printcycle(nltype *);
313 void printgprof(nltype **);
314 void printindex(void);
315 void printmembers(nltype *);
316 void printname(nltype *);
317 void printparents(nltype *);
318 void printprof(void);
319 void printsubcycle(cltype *);
320 void readsamples(FILE *);
321 void sortchildren(nltype *);
322 void sortmembers(nltype *);
323 void sortparents(nltype *);
324 void tally(struct rawarc *);
325 void timepropagate(nltype *);
326 int totalcmp(const void *, const void *);
330 #define GREATERTHAN 1
337 #define SAMPLEDEBUG 32
339 #define CALLDEBUG 128
340 #define LOOKUPDEBUG 256
341 #define PROPDEBUG 512
342 #define BREAKCYCLE 1024
343 #define SUBCYCLELIST 2048
344 #define ANYDEBUG 4096