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