|
|
1.1 root 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
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.