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