Merge from vendor branch SENDMAIL:
[dragonfly.git] / usr.bin / gprof / gprof.h
1 /*
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *      @(#)gprof.h     8.1 (Berkeley) 6/6/93
34  * $DragonFly: src/usr.bin/gprof/gprof.h,v 1.2 2006/07/31 12:12:08 corecode Exp $
35  */
36
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/gmon.h>
40
41 #include <stdio.h>
42 #include <stdlib.h>
43
44 #if __alpha__
45 #   include "alpha.h"
46 #endif
47 #if vax
48 #   include "vax.h"
49 #endif
50 #if sparc
51 #   include "sparc.h"
52 #endif
53 #if tahoe
54 #   include "tahoe.h"
55 #endif
56 #if hp300
57 #   include "hp300.h"
58 #endif
59 #if luna68k
60 #   include "luna68k.h"
61 #endif
62 #if i386
63 #   include "i386.h"
64 #endif
65 #if mips
66 #   include "mips.h"
67 #endif
68 #if __amd64__
69 #   include "amd64.h"
70 #endif
71
72
73     /*
74      * booleans
75      */
76 typedef int     bool;
77 #define FALSE   0
78 #define TRUE    1
79
80     /*
81      *  ticks per second
82      */
83 long    hz;
84
85 #ifdef GPROF4
86 typedef int64_t UNIT;
87 #else
88 typedef u_short UNIT;           /* unit of profiling */
89 #endif
90 #define UNITS_TO_CODE   (OFFSET_OF_CODE / sizeof(UNIT))
91
92 char    *a_outname;
93 #define A_OUTNAME               "a.out"
94
95 char    *gmonname;
96 #define GMONSUM                 "gmon.sum"
97
98     /*
99      *  a constructed arc,
100      *      with pointers to the namelist entry of the parent and the child,
101      *      a count of how many times this arc was traversed,
102      *      and pointers to the next parent of this child and
103      *          the next child of this parent.
104      */
105 struct arcstruct {
106     struct nl           *arc_parentp;   /* pointer to parent's nl entry */
107     struct nl           *arc_childp;    /* pointer to child's nl entry */
108     long                arc_count;      /* num calls from parent to child */
109     double              arc_time;       /* time inherited along arc */
110     double              arc_childtime;  /* childtime inherited along arc */
111     struct arcstruct    *arc_parentlist; /* parents-of-this-child list */
112     struct arcstruct    *arc_childlist; /* children-of-this-parent list */
113     struct arcstruct    *arc_next;      /* list of arcs on cycle */
114     unsigned short      arc_cyclecnt;   /* num cycles involved in */
115     unsigned short      arc_flags;      /* see below */
116 };
117 typedef struct arcstruct        arctype;
118
119     /*
120      * arc flags
121      */
122 #define DEADARC 0x01    /* time should not propagate across the arc */
123 #define ONLIST  0x02    /* arc is on list of arcs in cycles */
124
125     /*
126      * The symbol table;
127      * for each external in the specified file we gather
128      * its address, the number of calls and compute its share of cpu time.
129      */
130 struct nl {
131     const char          *name;          /* the name */
132     unsigned long       value;          /* the pc entry point */
133     unsigned long       svalue;         /* entry point aligned to histograms */
134     double              time;           /* ticks in this routine */
135     double              childtime;      /* cumulative ticks in children */
136     long                ncall;          /* how many times called */
137     long                npropcall;      /* times called by live arcs */
138     long                selfcalls;      /* how many calls to self */
139     double              propfraction;   /* what % of time propagates */
140     double              propself;       /* how much self time propagates */
141     double              propchild;      /* how much child time propagates */
142     short               printflag;      /* should this be printed? */
143     short               flags;          /* see below */
144     int                 index;          /* index in the graph list */
145     int                 toporder;       /* graph call chain top-sort order */
146     int                 cycleno;        /* internal number of cycle on */
147     int                 parentcnt;      /* number of live parent arcs */
148     struct nl           *cyclehead;     /* pointer to head of cycle */
149     struct nl           *cnext;         /* pointer to next member of cycle */
150     arctype             *parents;       /* list of caller arcs */
151     arctype             *children;      /* list of callee arcs */
152 };
153 typedef struct nl       nltype;
154
155 nltype  *nl;                    /* the whole namelist */
156 nltype  *npe;                   /* the virtual end of the namelist */
157 int     nname;                  /* the number of function names */
158
159 #define HASCYCLEXIT     0x08    /* node has arc exiting from cycle */
160 #define CYCLEHEAD       0x10    /* node marked as head of a cycle */
161 #define VISITED         0x20    /* node visited during a cycle */
162
163     /*
164      * The cycle list.
165      * for each subcycle within an identified cycle, we gather
166      * its size and the list of included arcs.
167      */
168 struct cl {
169     int         size;           /* length of cycle */
170     struct cl   *next;          /* next member of list */
171     arctype     *list[1];       /* list of arcs in cycle */
172     /* actually longer */
173 };
174 typedef struct cl cltype;
175
176 arctype *archead;               /* the head of arcs in current cycle list */
177 cltype  *cyclehead;             /* the head of the list */
178 int     cyclecnt;               /* the number of cycles found */
179 #define CYCLEMAX        100     /* maximum cycles before cutting one of them */
180
181     /*
182      *  flag which marks a nl entry as topologically ``busy''
183      *  flag which marks a nl entry as topologically ``not_numbered''
184      */
185 #define DFN_BUSY        -1
186 #define DFN_NAN         0
187
188     /*
189      *  namelist entries for cycle headers.
190      *  the number of discovered cycles.
191      */
192 nltype  *cyclenl;               /* cycle header namelist */
193 int     ncycle;                 /* number of cycles discovered */
194
195     /*
196      * The header on the gmon.out file.
197      * gmon.out consists of a struct phdr (defined in gmon.h)
198      * and then an array of ncnt samples representing the
199      * discretized program counter values.
200      *
201      *  Backward compatible old style header
202      */
203 struct ophdr {
204     UNIT        *lpc;
205     UNIT        *hpc;
206     int         ncnt;
207 };
208
209 int     debug;
210
211     /*
212      * Each discretized pc sample has
213      * a count of the number of samples in its range
214      */
215 UNIT    *samples;
216
217 unsigned long   s_lowpc;        /* lowpc from the profile file */
218 unsigned long   s_highpc;       /* highpc from the profile file */
219 unsigned long   lowpc, highpc;  /* range profiled, in UNIT's */
220 unsigned sampbytes;             /* number of bytes of samples */
221 int     nsamples;               /* number of samples */
222 double  actime;                 /* accumulated time thus far for putprofline */
223 double  totime;                 /* total time for all routines */
224 double  printtime;              /* total of time being printed */
225 double  scale;                  /* scale factor converting samples to pc
226                                    values: each sample covers scale bytes */
227 unsigned char   *textspace;     /* text space of a.out in core */
228 int     cyclethreshold;         /* with -C, minimum cycle size to ignore */
229
230     /*
231      *  option flags, from a to z.
232      */
233 bool    aflag;                          /* suppress static functions */
234 bool    bflag;                          /* blurbs, too */
235 bool    cflag;                          /* discovered call graph, too */
236 bool    Cflag;                          /* find cut-set to eliminate cycles */
237 bool    dflag;                          /* debugging options */
238 bool    eflag;                          /* specific functions excluded */
239 bool    Eflag;                          /* functions excluded with time */
240 bool    fflag;                          /* specific functions requested */
241 bool    Fflag;                          /* functions requested with time */
242 bool    kflag;                          /* arcs to be deleted */
243 bool    sflag;                          /* sum multiple gmon.out files */
244 bool    uflag;                          /* suppress symbols hidden from C */
245 bool    zflag;                          /* zero time/called functions, too */
246
247     /*
248      *  structure for various string lists
249      */
250 struct stringlist {
251     struct stringlist   *next;
252     char                *string;
253 };
254 struct stringlist       *elist;
255 struct stringlist       *Elist;
256 struct stringlist       *flist;
257 struct stringlist       *Flist;
258 struct stringlist       *kfromlist;
259 struct stringlist       *ktolist;
260
261     /*
262      *  function declarations
263      */
264 /*
265                 addarc();
266 */
267 int             aout_getnfile(const char *, char ***);
268 int             arccmp();
269 arctype         *arclookup();
270 /*
271                 asgnsamples();
272                 printblurb();
273                 cyclelink();
274                 dfn();
275 */
276 bool            dfn_busy();
277 /*
278                 dfn_findcycle();
279 */
280 bool            dfn_numbered();
281 /*
282                 dfn_post_visit();
283                 dfn_pre_visit();
284                 dfn_self_cycle();
285 */
286 nltype          **doarcs();
287 /*
288                 done();
289 */
290 int             elf_getnfile(const char *, char ***);
291 /*
292                 findcalls();
293                 flatprofheader();
294                 flatprofline();
295 */
296 /*
297                 getpfile();
298                 gprofheader();
299                 gprofline();
300                 main();
301 */
302 unsigned long   max();
303 int             membercmp();
304 unsigned long   min();
305 nltype          *nllookup();
306 FILE            *openpfile();
307 long            operandlength();
308 operandenum     operandmode();
309 char            *operandname();
310 /*
311                 printchildren();
312                 printcycle();
313                 printgprof();
314                 printmembers();
315                 printname();
316                 printparents();
317                 printprof();
318                 readsamples();
319 */
320 unsigned long   reladdr();
321 /*
322                 sortchildren();
323                 sortmembers();
324                 sortparents();
325                 tally();
326                 timecmp();
327                 topcmp();
328 */
329 int             totalcmp();
330 /*
331                 valcmp();
332 */
333
334 #define LESSTHAN        -1
335 #define EQUALTO         0
336 #define GREATERTHAN     1
337
338 #define DFNDEBUG        1
339 #define CYCLEDEBUG      2
340 #define ARCDEBUG        4
341 #define TALLYDEBUG      8
342 #define TIMEDEBUG       16
343 #define SAMPLEDEBUG     32
344 #define AOUTDEBUG       64
345 #define CALLDEBUG       128
346 #define LOOKUPDEBUG     256
347 #define PROPDEBUG       512
348 #define BREAKCYCLE      1024
349 #define SUBCYCLELIST    2048
350 #define ANYDEBUG        4096