* M Makefile.in: Add -g to CFLAGS.
[external/binutils.git] / gprof / gprof.h
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that: (1) source distributions retain this entire copyright
7  * notice and comment, and (2) distributions including binaries display
8  * the following acknowledgement:  ``This product includes software
9  * developed by the University of California, Berkeley and its contributors''
10  * in the documentation or other materials provided with the distribution
11  * and in all advertising materials mentioning features or use of this
12  * software. Neither the name of the University nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  *      @(#)gprof.h     5.9 (Berkeley) 6/1/90
20  */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "gmon.h"
25
26 #ifdef  MACHINE_H
27 #       include MACHINE_H
28 #else
29 #       if vax
30 #          include "vax.h"
31 #       endif
32 #       if sun
33 #               include "sun.h"
34 #       endif
35 #       if tahoe
36 #               include "tahoe.h"
37 #       endif
38 #endif
39
40
41     /*
42      *  who am i, for error messages.
43      */
44 char    *whoami;
45
46     /*
47      * booleans
48      */
49 typedef int     bool;
50 #define FALSE   0
51 #define TRUE    1
52
53     /*
54      *  ticks per second
55      */
56 long    hz;
57
58 typedef unsigned short UNIT;            /* unit of profiling */
59 char    *a_outname;
60 #define A_OUTNAME               "a.out"
61
62 char    *gmonname;
63 #define GMONNAME                "gmon.out"
64 #define GMONSUM                 "gmon.sum"
65
66 extern int bsd_style_output;
67 extern int discard_underscores;
68
69     /*
70      *  a constructed arc,
71      *      with pointers to the namelist entry of the parent and the child,
72      *      a count of how many times this arc was traversed,
73      *      and pointers to the next parent of this child and
74      *          the next child of this parent.
75      */
76 struct arcstruct {
77     struct nl           *arc_parentp;   /* pointer to parent's nl entry */
78     struct nl           *arc_childp;    /* pointer to child's nl entry */
79     long                arc_count;      /* how calls from parent to child */
80     double              arc_time;       /* time inherited along arc */
81     double              arc_childtime;  /* childtime inherited along arc */
82     struct arcstruct    *arc_parentlist; /* parents-of-this-child list */
83     struct arcstruct    *arc_childlist; /* children-of-this-parent list */
84 };
85 typedef struct arcstruct        arctype;
86
87     /*
88      * The symbol table;
89      * for each external in the specified file we gather
90      * its address, the number of calls and compute its share of cpu time.
91      */
92 struct nl {
93     CONST char          *name;          /* the name */
94     unsigned long       value;          /* the pc entry point */
95     unsigned long       svalue;         /* entry point aligned to histograms */
96     double              time;           /* ticks in this routine */
97     double              childtime;      /* cumulative ticks in children */
98     long                ncall;          /* how many times called */
99     long                selfcalls;      /* how many calls to self */
100     double              propfraction;   /* what % of time propagates */
101     double              propself;       /* how much self time propagates */
102     double              propchild;      /* how much child time propagates */
103     bool                printflag;      /* should this be printed? */
104     int                 index;          /* index in the graph list */
105     int                 toporder;       /* graph call chain top-sort order */
106     int                 cycleno;        /* internal number of cycle on */
107     struct nl           *cyclehead;     /* pointer to head of cycle */
108     struct nl           *cnext;         /* pointer to next member of cycle */
109     arctype             *parents;       /* list of caller arcs */
110     arctype             *children;      /* list of callee arcs */
111 };
112 typedef struct nl       nltype;
113
114 nltype  *nl;                    /* the whole namelist */
115 nltype  *npe;                   /* the virtual end of the namelist */
116 int     nname;                  /* the number of function names */
117
118     /*
119      *  flag which marks a nl entry as topologically ``busy''
120      *  flag which marks a nl entry as topologically ``not_numbered''
121      */
122 #define DFN_BUSY        -1
123 #define DFN_NAN         0
124
125     /* 
126      *  namelist entries for cycle headers.
127      *  the number of discovered cycles.
128      */
129 nltype  *cyclenl;               /* cycle header namelist */
130 int     ncycle;                 /* number of cycles discovered */
131
132     /*
133      * The header on the gmon.out file.
134      * gmon.out consists of one of these headers,
135      * and then an array of ncnt samples
136      * representing the discretized program counter values.
137      *  this should be a struct phdr, but since everything is done
138      *  as UNITs, this is in UNITs too.
139      */
140 struct hdr {
141     UNIT        *lowpc;
142     UNIT        *highpc;
143     int ncnt;
144 };
145
146 struct hdr      h;
147
148 int     debug;
149
150     /*
151      * Each discretized pc sample has
152      * a count of the number of samples in its range
153      */
154 UNIT    *samples;
155
156 unsigned long   s_lowpc;        /* lowpc from the profile file */
157 unsigned long   s_highpc;       /* highpc from the profile file */
158 unsigned lowpc, highpc;         /* range profiled, in UNIT's */
159 unsigned sampbytes;             /* number of bytes of samples */
160 int     nsamples;               /* number of samples */
161 double  actime;                 /* accumulated time thus far for putprofline */
162 double  totime;                 /* total time for all routines */
163 double  printtime;              /* total of time being printed */
164 double  scale;                  /* scale factor converting samples to pc
165                                    values: each sample covers scale bytes */
166 char    *strtab;                /* string table in core */
167 off_t   ssiz;                   /* size of the string table */
168 unsigned char   *textspace;             /* text space of a.out in core */
169
170     /*
171      *  option flags, from a to z.
172      */
173 bool    aflag;                          /* suppress static functions */
174 bool    bflag;                          /* blurbs, too */
175 bool    cflag;                          /* discovered call graph, too */
176 bool    dflag;                          /* debugging options */
177 bool    eflag;                          /* specific functions excluded */
178 bool    Eflag;                          /* functions excluded with time */
179 bool    fflag;                          /* specific functions requested */
180 bool    Fflag;                          /* functions requested with time */
181 bool    kflag;                          /* arcs to be deleted */
182 bool    sflag;                          /* sum multiple gmon.out files */
183 bool    zflag;                          /* zero time/called functions, too */
184
185     /*
186      *  structure for various string lists
187      */
188 struct stringlist {
189     struct stringlist   *next;
190     char                *string;
191 };
192 struct stringlist       *elist;
193 struct stringlist       *Elist;
194 struct stringlist       *flist;
195 struct stringlist       *Flist;
196 struct stringlist       *kfromlist;
197 struct stringlist       *ktolist;
198
199     /*
200      *  function declarations
201      */
202 /*
203                 addarc();
204 */
205 int             arccmp();
206 arctype         *arclookup();
207 /*
208                 asgnsamples();
209                 printblurb();
210                 cyclelink();
211                 dfn();
212 */
213 bool            dfn_busy();
214 /*
215                 dfn_findcycle();
216 */
217 bool            dfn_numbered();
218 /*
219                 dfn_post_visit();
220                 dfn_pre_visit();
221                 dfn_self_cycle();
222 */
223 nltype          **doarcs();
224 /*
225                 done();
226                 findcalls();
227                 flatprofheader();
228                 flatprofline();
229 */
230 bool            funcsymbol();
231 /*
232                 getnfile();
233                 getpfile();
234                 getstrtab();
235                 getsymtab();
236                 gettextspace();
237                 gprofheader();
238                 gprofline();
239                 main();
240 */
241 unsigned long   max();
242 int             membercmp();
243 unsigned long   min();
244 nltype          *nllookup();
245 FILE            *openpfile();
246 /*
247                 printchildren();
248                 printcycle();
249                 printgprof();
250                 printmembers();
251                 printname();
252                 printparents();
253                 printprof();
254                 readsamples();
255 */
256 int             printnameonly();
257 unsigned long   reladdr();
258 /*
259                 sortchildren();
260                 sortmembers();
261                 sortparents();
262                 tally();
263                 timecmp();
264                 topcmp();
265 */
266 int             totalcmp();
267 /*
268                 valcmp();
269 */
270
271 #define LESSTHAN        -1
272 #define EQUALTO         0
273 #define GREATERTHAN     1
274
275 #define DFNDEBUG        1
276 #define CYCLEDEBUG      2
277 #define ARCDEBUG        4
278 #define TALLYDEBUG      8
279 #define TIMEDEBUG       16
280 #define SAMPLEDEBUG     32
281 #define AOUTDEBUG       64
282 #define CALLDEBUG       128
283 #define LOOKUPDEBUG     256
284 #define PROPDEBUG       512
285 #define ANYDEBUG        1024