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