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