Annotation of src/usr.bin/gprof/gprof.h, Revision 1.2
1.2 ! deraadt 1: /* $NetBSD: gprof.h,v 1.13 1996/04/01 21:54:06 mark Exp $ */
1.1 deraadt 2:
3: /*
4: * Copyright (c) 1983, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: *
35: * @(#)gprof.h 8.1 (Berkeley) 6/6/93
36: */
37:
38: #include <sys/types.h>
39: #include <sys/stat.h>
40: #include <sys/gmon.h>
41:
42: #include <a.out.h>
43: #include <stdio.h>
44: #include <stdlib.h>
45:
46: #if alpha
47: # include "alpha.h"
1.2 ! deraadt 48: #endif
! 49: #if arm32
! 50: # include "arm32.h"
1.1 deraadt 51: #endif
52: #if i386
53: # include "i386.h"
54: #endif
55: #if m68k
56: # include "m68k.h"
57: #endif
58: #if mips
59: # include "mips.h"
60: #endif
61: #if ns32k
62: # include "ns32k.h"
63: #endif
64: #if pmax
65: # include "pmax.h"
66: #endif
67: #if sparc
68: # include "sparc.h"
69: #endif
70: #if tahoe
71: # include "tahoe.h"
72: #endif
73: #if vax
74: # include "vax.h"
75: #endif
76:
77:
78: /*
79: * who am i, for error messages.
80: */
81: char *whoami;
82:
83: /*
84: * booleans
85: */
86: typedef int bool;
87: #define FALSE 0
88: #define TRUE 1
89:
90: /*
91: * ticks per second
92: */
93: long hz;
94:
95: typedef u_short UNIT; /* unit of profiling */
96: char *a_outname;
97: #define A_OUTNAME "a.out"
98:
99: char *gmonname;
100: #define GMONNAME "gmon.out"
101: #define GMONSUM "gmon.sum"
102:
103: /*
104: * a constructed arc,
105: * with pointers to the namelist entry of the parent and the child,
106: * a count of how many times this arc was traversed,
107: * and pointers to the next parent of this child and
108: * the next child of this parent.
109: */
110: struct arcstruct {
111: struct nl *arc_parentp; /* pointer to parent's nl entry */
112: struct nl *arc_childp; /* pointer to child's nl entry */
113: long arc_count; /* num calls from parent to child */
114: double arc_time; /* time inherited along arc */
115: double arc_childtime; /* childtime inherited along arc */
116: struct arcstruct *arc_parentlist; /* parents-of-this-child list */
117: struct arcstruct *arc_childlist; /* children-of-this-parent list */
118: struct arcstruct *arc_next; /* list of arcs on cycle */
119: unsigned short arc_cyclecnt; /* num cycles involved in */
120: unsigned short arc_flags; /* see below */
121: };
122: typedef struct arcstruct arctype;
123:
124: /*
125: * arc flags
126: */
127: #define DEADARC 0x01 /* time should not propagate across the arc */
128: #define ONLIST 0x02 /* arc is on list of arcs in cycles */
129:
130: /*
131: * The symbol table;
132: * for each external in the specified file we gather
133: * its address, the number of calls and compute its share of cpu time.
134: */
135: struct nl {
136: char *name; /* the name */
137: unsigned long value; /* the pc entry point */
138: unsigned long svalue; /* entry point aligned to histograms */
139: double time; /* ticks in this routine */
140: double childtime; /* cumulative ticks in children */
141: long ncall; /* how many times called */
142: long npropcall; /* times called by live arcs */
143: long selfcalls; /* how many calls to self */
144: double propfraction; /* what % of time propagates */
145: double propself; /* how much self time propagates */
146: double propchild; /* how much child time propagates */
147: short printflag; /* should this be printed? */
148: short flags; /* see below */
149: int index; /* index in the graph list */
150: int toporder; /* graph call chain top-sort order */
151: int cycleno; /* internal number of cycle on */
152: int parentcnt; /* number of live parent arcs */
153: struct nl *cyclehead; /* pointer to head of cycle */
154: struct nl *cnext; /* pointer to next member of cycle */
155: arctype *parents; /* list of caller arcs */
156: arctype *children; /* list of callee arcs */
157: };
158: typedef struct nl nltype;
159:
160: nltype *nl; /* the whole namelist */
161: nltype *npe; /* the virtual end of the namelist */
162: int nname; /* the number of function names */
163:
164: #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */
165: #define CYCLEHEAD 0x10 /* node marked as head of a cycle */
166: #define VISITED 0x20 /* node visited during a cycle */
167:
168: /*
169: * The cycle list.
170: * for each subcycle within an identified cycle, we gather
171: * its size and the list of included arcs.
172: */
173: struct cl {
174: int size; /* length of cycle */
175: struct cl *next; /* next member of list */
176: arctype *list[1]; /* list of arcs in cycle */
177: /* actually longer */
178: };
179: typedef struct cl cltype;
180:
181: arctype *archead; /* the head of arcs in current cycle list */
182: cltype *cyclehead; /* the head of the list */
183: int cyclecnt; /* the number of cycles found */
184: #define CYCLEMAX 100 /* maximum cycles before cutting one of them */
185:
186: /*
187: * flag which marks a nl entry as topologically ``busy''
188: * flag which marks a nl entry as topologically ``not_numbered''
189: */
190: #define DFN_BUSY -1
191: #define DFN_NAN 0
192:
193: /*
194: * namelist entries for cycle headers.
195: * the number of discovered cycles.
196: */
197: nltype *cyclenl; /* cycle header namelist */
198: int ncycle; /* number of cycles discovered */
199:
200: /*
201: * The header on the gmon.out file.
202: * gmon.out consists of a struct phdr (defined in gmon.h)
203: * and then an array of ncnt samples representing the
204: * discretized program counter values.
205: *
206: * Backward compatible old style header
207: */
208: struct ophdr {
209: UNIT *lpc;
210: UNIT *hpc;
211: int ncnt;
212: };
213:
214: int debug;
215:
216: /*
217: * Each discretized pc sample has
218: * a count of the number of samples in its range
219: */
220: UNIT *samples;
221:
222: unsigned long s_lowpc; /* lowpc from the profile file */
223: unsigned long s_highpc; /* highpc from the profile file */
224: unsigned lowpc, highpc; /* range profiled, in UNIT's */
225: unsigned sampbytes; /* number of bytes of samples */
226: int nsamples; /* number of samples */
227: double actime; /* accumulated time thus far for putprofline */
228: double totime; /* total time for all routines */
229: double printtime; /* total of time being printed */
230: double scale; /* scale factor converting samples to pc
231: values: each sample covers scale bytes */
232: char *strtab; /* string table in core */
233: long ssiz; /* size of the string table */
234: struct exec xbuf; /* exec header of a.out */
235: unsigned char *textspace; /* text space of a.out in core */
236: int cyclethreshold; /* with -C, minimum cycle size to ignore */
237:
238: /*
239: * option flags, from a to z.
240: */
241: bool aflag; /* suppress static functions */
242: bool bflag; /* blurbs, too */
243: bool cflag; /* discovered call graph, too */
244: bool Cflag; /* find cut-set to eliminate cycles */
245: bool dflag; /* debugging options */
246: bool eflag; /* specific functions excluded */
247: bool Eflag; /* functions excluded with time */
248: bool fflag; /* specific functions requested */
249: bool Fflag; /* functions requested with time */
250: bool kflag; /* arcs to be deleted */
251: bool sflag; /* sum multiple gmon.out files */
252: bool zflag; /* zero time/called functions, too */
253:
254: /*
255: * structure for various string lists
256: */
257: struct stringlist {
258: struct stringlist *next;
259: char *string;
260: };
261: struct stringlist *elist;
262: struct stringlist *Elist;
263: struct stringlist *flist;
264: struct stringlist *Flist;
265: struct stringlist *kfromlist;
266: struct stringlist *ktolist;
267:
268: /*
269: * function declarations
270: */
271: /*
272: addarc();
273: */
274: int arccmp();
275: arctype *arclookup();
276: /*
277: asgnsamples();
278: printblurb();
279: cyclelink();
280: dfn();
281: */
282: bool dfn_busy();
283: /*
284: dfn_findcycle();
285: */
286: bool dfn_numbered();
287: /*
288: dfn_post_visit();
289: dfn_pre_visit();
290: dfn_self_cycle();
291: */
292: nltype **doarcs();
293: /*
294: done();
295: findcalls();
296: flatprofheader();
297: flatprofline();
298: */
299: bool funcsymbol();
300: /*
301: getnfile();
302: getpfile();
303: getstrtab();
304: getsymtab();
305: gettextspace();
306: gprofheader();
307: gprofline();
308: main();
309: */
310: unsigned long max();
311: int membercmp();
312: unsigned long min();
313: nltype *nllookup();
314: FILE *openpfile();
315: long operandlength();
316: operandenum operandmode();
317: char *operandname();
318: /*
319: printchildren();
320: printcycle();
321: printgprof();
322: printmembers();
323: printname();
324: printparents();
325: printprof();
326: readsamples();
327: */
328: unsigned long reladdr();
329: /*
330: sortchildren();
331: sortmembers();
332: sortparents();
333: tally();
334: timecmp();
335: topcmp();
336: */
337: int totalcmp();
338: /*
339: valcmp();
340: */
341:
342: #define LESSTHAN -1
343: #define EQUALTO 0
344: #define GREATERTHAN 1
345:
346: #define DFNDEBUG 1
347: #define CYCLEDEBUG 2
348: #define ARCDEBUG 4
349: #define TALLYDEBUG 8
350: #define TIMEDEBUG 16
351: #define SAMPLEDEBUG 32
352: #define AOUTDEBUG 64
353: #define CALLDEBUG 128
354: #define LOOKUPDEBUG 256
355: #define PROPDEBUG 512
356: #define BREAKCYCLE 1024
357: #define SUBCYCLELIST 2048
358: #define ANYDEBUG 4096