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