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