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.13 (Berkeley) 07/08/92 8 */ 9 10 #include <sys/types.h> 11 #include <sys/stat.h> 12 #include <sys/gmon.h> 13 14 #include <a.out.h> 15 #include <stdio.h> 16 #include <stdlib.h> 17 18 #if vax 19 # include "vax.h" 20 #endif 21 #if sparc 22 # include "sparc.h" 23 #endif 24 #if tahoe 25 # include "tahoe.h" 26 #endif 27 #if hp300 28 # include "hp300.h" 29 #endif 30 #if i386 31 # include "i386.h" 32 #endif 33 34 35 /* 36 * who am i, for error messages. 37 */ 38 char *whoami; 39 40 /* 41 * booleans 42 */ 43 typedef int bool; 44 #define FALSE 0 45 #define TRUE 1 46 47 /* 48 * ticks per second 49 */ 50 long hz; 51 52 typedef u_short UNIT; /* unit of profiling */ 53 char *a_outname; 54 #define A_OUTNAME "a.out" 55 56 char *gmonname; 57 #define GMONNAME "gmon.out" 58 #define GMONSUM "gmon.sum" 59 60 /* 61 * a constructed arc, 62 * with pointers to the namelist entry of the parent and the child, 63 * a count of how many times this arc was traversed, 64 * and pointers to the next parent of this child and 65 * the next child of this parent. 66 */ 67 struct arcstruct { 68 struct nl *arc_parentp; /* pointer to parent's nl entry */ 69 struct nl *arc_childp; /* pointer to child's nl entry */ 70 long arc_count; /* num calls from parent to child */ 71 double arc_time; /* time inherited along arc */ 72 double arc_childtime; /* childtime inherited along arc */ 73 struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 74 struct arcstruct *arc_childlist; /* children-of-this-parent list */ 75 struct arcstruct *arc_next; /* list of arcs on cycle */ 76 unsigned short arc_cyclecnt; /* num cycles involved in */ 77 unsigned short arc_flags; /* see below */ 78 }; 79 typedef struct arcstruct arctype; 80 81 /* 82 * arc flags 83 */ 84 #define DEADARC 0x01 /* time should not propagate across the arc */ 85 #define ONLIST 0x02 /* arc is on list of arcs in cycles */ 86 87 /* 88 * The symbol table; 89 * for each external in the specified file we gather 90 * its address, the number of calls and compute its share of cpu time. 91 */ 92 struct nl { 93 char *name; /* the name */ 94 unsigned long value; /* the pc entry point */ 95 unsigned long svalue; /* entry point aligned to histograms */ 96 double time; /* ticks in this routine */ 97 double childtime; /* cumulative ticks in children */ 98 long ncall; /* how many times called */ 99 long npropcall; /* times called by live arcs */ 100 long selfcalls; /* how many calls to self */ 101 double propfraction; /* what % of time propagates */ 102 double propself; /* how much self time propagates */ 103 double propchild; /* how much child time propagates */ 104 short printflag; /* should this be printed? */ 105 short flags; /* see below */ 106 int index; /* index in the graph list */ 107 int toporder; /* graph call chain top-sort order */ 108 int cycleno; /* internal number of cycle on */ 109 int parentcnt; /* number of live parent arcs */ 110 struct nl *cyclehead; /* pointer to head of cycle */ 111 struct nl *cnext; /* pointer to next member of cycle */ 112 arctype *parents; /* list of caller arcs */ 113 arctype *children; /* list of callee arcs */ 114 }; 115 typedef struct nl nltype; 116 117 nltype *nl; /* the whole namelist */ 118 nltype *npe; /* the virtual end of the namelist */ 119 int nname; /* the number of function names */ 120 121 #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 122 #define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 123 #define VISITED 0x20 /* node visited during a cycle */ 124 125 /* 126 * The cycle list. 127 * for each subcycle within an identified cycle, we gather 128 * its size and the list of included arcs. 129 */ 130 struct cl { 131 int size; /* length of cycle */ 132 struct cl *next; /* next member of list */ 133 arctype *list[1]; /* list of arcs in cycle */ 134 /* actually longer */ 135 }; 136 typedef struct cl cltype; 137 138 arctype *archead; /* the head of arcs in current cycle list */ 139 cltype *cyclehead; /* the head of the list */ 140 int cyclecnt; /* the number of cycles found */ 141 #define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 142 143 /* 144 * flag which marks a nl entry as topologically ``busy'' 145 * flag which marks a nl entry as topologically ``not_numbered'' 146 */ 147 #define DFN_BUSY -1 148 #define DFN_NAN 0 149 150 /* 151 * namelist entries for cycle headers. 152 * the number of discovered cycles. 153 */ 154 nltype *cyclenl; /* cycle header namelist */ 155 int ncycle; /* number of cycles discovered */ 156 157 /* 158 * The header on the gmon.out file. 159 * gmon.out consists of a struct phdr (defined in gmon.h) 160 * and then an array of ncnt samples representing the 161 * discretized program counter values. 162 * 163 * Backward compatible old style header 164 */ 165 struct ophdr { 166 UNIT *lpc; 167 UNIT *hpc; 168 int ncnt; 169 }; 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 long 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