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