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