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.11 (Berkeley) 02/24/92 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 #if hp300 26 # include "hp300.h" 27 #endif 28 #if i386 29 # include "i386.h" 30 #endif 31 32 33 /* 34 * who am i, for error messages. 35 */ 36 char *whoami; 37 38 /* 39 * booleans 40 */ 41 typedef int bool; 42 #define FALSE 0 43 #define TRUE 1 44 45 /* 46 * ticks per second 47 */ 48 long hz; 49 50 typedef u_short UNIT; /* unit of profiling */ 51 char *a_outname; 52 #define A_OUTNAME "a.out" 53 54 char *gmonname; 55 #define GMONNAME "gmon.out" 56 #define GMONSUM "gmon.sum" 57 58 /* 59 * a constructed arc, 60 * with pointers to the namelist entry of the parent and the child, 61 * a count of how many times this arc was traversed, 62 * and pointers to the next parent of this child and 63 * the next child of this parent. 64 */ 65 struct arcstruct { 66 struct nl *arc_parentp; /* pointer to parent's nl entry */ 67 struct nl *arc_childp; /* pointer to child's nl entry */ 68 long arc_count; /* num calls from parent to child */ 69 double arc_time; /* time inherited along arc */ 70 double arc_childtime; /* childtime inherited along arc */ 71 struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 72 struct arcstruct *arc_childlist; /* children-of-this-parent list */ 73 struct arcstruct *arc_next; /* list of arcs on cycle */ 74 unsigned short arc_cyclecnt; /* num cycles involved in */ 75 unsigned short arc_flags; /* see below */ 76 }; 77 typedef struct arcstruct arctype; 78 79 /* 80 * arc flags 81 */ 82 #define DEADARC 0x01 /* time should not propagate across the arc */ 83 #define ONLIST 0x02 /* arc is on list of arcs in cycles */ 84 85 /* 86 * The symbol table; 87 * for each external in the specified file we gather 88 * its address, the number of calls and compute its share of cpu time. 89 */ 90 struct nl { 91 char *name; /* the name */ 92 unsigned long value; /* the pc entry point */ 93 unsigned long svalue; /* entry point aligned to histograms */ 94 double time; /* ticks in this routine */ 95 double childtime; /* cumulative ticks in children */ 96 long ncall; /* how many times called */ 97 long npropcall; /* times called by live arcs */ 98 long selfcalls; /* how many calls to self */ 99 double propfraction; /* what % of time propagates */ 100 double propself; /* how much self time propagates */ 101 double propchild; /* how much child time propagates */ 102 short printflag; /* should this be printed? */ 103 short flags; /* see below */ 104 int index; /* index in the graph list */ 105 int toporder; /* graph call chain top-sort order */ 106 int cycleno; /* internal number of cycle on */ 107 int parentcnt; /* number of live parent arcs */ 108 struct nl *cyclehead; /* pointer to head of cycle */ 109 struct nl *cnext; /* pointer to next member of cycle */ 110 arctype *parents; /* list of caller arcs */ 111 arctype *children; /* list of callee arcs */ 112 }; 113 typedef struct nl nltype; 114 115 nltype *nl; /* the whole namelist */ 116 nltype *npe; /* the virtual end of the namelist */ 117 int nname; /* the number of function names */ 118 119 #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 120 #define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 121 #define VISITED 0x20 /* node visited during a cycle */ 122 123 /* 124 * The cycle list. 125 * for each subcycle within an identified cycle, we gather 126 * its size and the list of included arcs. 127 */ 128 struct cl { 129 int size; /* length of cycle */ 130 struct cl *next; /* next member of list */ 131 arctype *list[1]; /* list of arcs in cycle */ 132 /* actually longer */ 133 }; 134 typedef struct cl cltype; 135 136 arctype *archead; /* the head of arcs in current cycle list */ 137 cltype *cyclehead; /* the head of the list */ 138 int cyclecnt; /* the number of cycles found */ 139 #define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 140 141 /* 142 * flag which marks a nl entry as topologically ``busy'' 143 * flag which marks a nl entry as topologically ``not_numbered'' 144 */ 145 #define DFN_BUSY -1 146 #define DFN_NAN 0 147 148 /* 149 * namelist entries for cycle headers. 150 * the number of discovered cycles. 151 */ 152 nltype *cyclenl; /* cycle header namelist */ 153 int ncycle; /* number of cycles discovered */ 154 155 /* 156 * The header on the gmon.out file. 157 * gmon.out consists of one of these headers, 158 * and then an array of ncnt samples 159 * representing the discretized program counter values. 160 * this should be a struct phdr, but since everything is done 161 * as UNITs, this is in UNITs too. 162 */ 163 struct hdr { 164 UNIT *lowpc; 165 UNIT *highpc; 166 int ncnt; 167 }; 168 169 struct hdr h; 170 171 int debug; 172 173 /* 174 * Each discretized pc sample has 175 * a count of the number of samples in its range 176 */ 177 UNIT *samples; 178 179 unsigned long s_lowpc; /* lowpc from the profile file */ 180 unsigned long s_highpc; /* highpc from the profile file */ 181 unsigned lowpc, highpc; /* range profiled, in UNIT's */ 182 unsigned sampbytes; /* number of bytes of samples */ 183 int nsamples; /* number of samples */ 184 double actime; /* accumulated time thus far for putprofline */ 185 double totime; /* total time for all routines */ 186 double printtime; /* total of time being printed */ 187 double scale; /* scale factor converting samples to pc 188 values: each sample covers scale bytes */ 189 char *strtab; /* string table in core */ 190 off_t ssiz; /* size of the string table */ 191 struct exec xbuf; /* exec header of a.out */ 192 unsigned char *textspace; /* text space of a.out in core */ 193 int cyclethreshold; /* with -C, minimum cycle size to ignore */ 194 195 /* 196 * option flags, from a to z. 197 */ 198 bool aflag; /* suppress static functions */ 199 bool bflag; /* blurbs, too */ 200 bool cflag; /* discovered call graph, too */ 201 bool Cflag; /* find cut-set to eliminate cycles */ 202 bool dflag; /* debugging options */ 203 bool eflag; /* specific functions excluded */ 204 bool Eflag; /* functions excluded with time */ 205 bool fflag; /* specific functions requested */ 206 bool Fflag; /* functions requested with time */ 207 bool kflag; /* arcs to be deleted */ 208 bool sflag; /* sum multiple gmon.out files */ 209 bool zflag; /* zero time/called functions, too */ 210 211 /* 212 * structure for various string lists 213 */ 214 struct stringlist { 215 struct stringlist *next; 216 char *string; 217 }; 218 struct stringlist *elist; 219 struct stringlist *Elist; 220 struct stringlist *flist; 221 struct stringlist *Flist; 222 struct stringlist *kfromlist; 223 struct stringlist *ktolist; 224 225 /* 226 * function declarations 227 */ 228 /* 229 addarc(); 230 */ 231 int arccmp(); 232 arctype *arclookup(); 233 /* 234 asgnsamples(); 235 printblurb(); 236 cyclelink(); 237 dfn(); 238 */ 239 bool dfn_busy(); 240 /* 241 dfn_findcycle(); 242 */ 243 bool dfn_numbered(); 244 /* 245 dfn_post_visit(); 246 dfn_pre_visit(); 247 dfn_self_cycle(); 248 */ 249 nltype **doarcs(); 250 /* 251 done(); 252 findcalls(); 253 flatprofheader(); 254 flatprofline(); 255 */ 256 bool funcsymbol(); 257 /* 258 getnfile(); 259 getpfile(); 260 getstrtab(); 261 getsymtab(); 262 gettextspace(); 263 gprofheader(); 264 gprofline(); 265 main(); 266 */ 267 unsigned long max(); 268 int membercmp(); 269 unsigned long min(); 270 nltype *nllookup(); 271 FILE *openpfile(); 272 long operandlength(); 273 operandenum operandmode(); 274 char *operandname(); 275 /* 276 printchildren(); 277 printcycle(); 278 printgprof(); 279 printmembers(); 280 printname(); 281 printparents(); 282 printprof(); 283 readsamples(); 284 */ 285 unsigned long reladdr(); 286 /* 287 sortchildren(); 288 sortmembers(); 289 sortparents(); 290 tally(); 291 timecmp(); 292 topcmp(); 293 */ 294 int totalcmp(); 295 /* 296 valcmp(); 297 */ 298 299 #define LESSTHAN -1 300 #define EQUALTO 0 301 #define GREATERTHAN 1 302 303 #define DFNDEBUG 1 304 #define CYCLEDEBUG 2 305 #define ARCDEBUG 4 306 #define TALLYDEBUG 8 307 #define TIMEDEBUG 16 308 #define SAMPLEDEBUG 32 309 #define AOUTDEBUG 64 310 #define CALLDEBUG 128 311 #define LOOKUPDEBUG 256 312 #define PROPDEBUG 512 313 #define BREAKCYCLE 1024 314 #define SUBCYCLELIST 2048 315 #define ANYDEBUG 4096 316