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