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