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