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