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