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