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.10 (Berkeley) 04/24/91 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; /* how 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 }; 74 typedef struct arcstruct arctype; 75 76 /* 77 * The symbol table; 78 * for each external in the specified file we gather 79 * its address, the number of calls and compute its share of cpu time. 80 */ 81 struct nl { 82 char *name; /* the name */ 83 unsigned long value; /* the pc entry point */ 84 unsigned long svalue; /* entry point aligned to histograms */ 85 double time; /* ticks in this routine */ 86 double childtime; /* cumulative ticks in children */ 87 long ncall; /* how many times called */ 88 long selfcalls; /* how many calls to self */ 89 double propfraction; /* what % of time propagates */ 90 double propself; /* how much self time propagates */ 91 double propchild; /* how much child time propagates */ 92 bool printflag; /* should this be printed? */ 93 int index; /* index in the graph list */ 94 int toporder; /* graph call chain top-sort order */ 95 int cycleno; /* internal number of cycle on */ 96 struct nl *cyclehead; /* pointer to head of cycle */ 97 struct nl *cnext; /* pointer to next member of cycle */ 98 arctype *parents; /* list of caller arcs */ 99 arctype *children; /* list of callee arcs */ 100 }; 101 typedef struct nl nltype; 102 103 nltype *nl; /* the whole namelist */ 104 nltype *npe; /* the virtual end of the namelist */ 105 int nname; /* the number of function names */ 106 107 /* 108 * flag which marks a nl entry as topologically ``busy'' 109 * flag which marks a nl entry as topologically ``not_numbered'' 110 */ 111 #define DFN_BUSY -1 112 #define DFN_NAN 0 113 114 /* 115 * namelist entries for cycle headers. 116 * the number of discovered cycles. 117 */ 118 nltype *cyclenl; /* cycle header namelist */ 119 int ncycle; /* number of cycles discovered */ 120 121 /* 122 * The header on the gmon.out file. 123 * gmon.out consists of one of these headers, 124 * and then an array of ncnt samples 125 * representing the discretized program counter values. 126 * this should be a struct phdr, but since everything is done 127 * as UNITs, this is in UNITs too. 128 */ 129 struct hdr { 130 UNIT *lowpc; 131 UNIT *highpc; 132 int ncnt; 133 }; 134 135 struct hdr h; 136 137 int debug; 138 139 /* 140 * Each discretized pc sample has 141 * a count of the number of samples in its range 142 */ 143 UNIT *samples; 144 145 unsigned long s_lowpc; /* lowpc from the profile file */ 146 unsigned long s_highpc; /* highpc from the profile file */ 147 unsigned lowpc, highpc; /* range profiled, in UNIT's */ 148 unsigned sampbytes; /* number of bytes of samples */ 149 int nsamples; /* number of samples */ 150 double actime; /* accumulated time thus far for putprofline */ 151 double totime; /* total time for all routines */ 152 double printtime; /* total of time being printed */ 153 double scale; /* scale factor converting samples to pc 154 values: each sample covers scale bytes */ 155 char *strtab; /* string table in core */ 156 off_t ssiz; /* size of the string table */ 157 struct exec xbuf; /* exec header of a.out */ 158 unsigned char *textspace; /* text space of a.out in core */ 159 160 /* 161 * option flags, from a to z. 162 */ 163 bool aflag; /* suppress static functions */ 164 bool bflag; /* blurbs, too */ 165 bool cflag; /* discovered call graph, too */ 166 bool dflag; /* debugging options */ 167 bool eflag; /* specific functions excluded */ 168 bool Eflag; /* functions excluded with time */ 169 bool fflag; /* specific functions requested */ 170 bool Fflag; /* functions requested with time */ 171 bool kflag; /* arcs to be deleted */ 172 bool sflag; /* sum multiple gmon.out files */ 173 bool zflag; /* zero time/called functions, too */ 174 175 /* 176 * structure for various string lists 177 */ 178 struct stringlist { 179 struct stringlist *next; 180 char *string; 181 }; 182 struct stringlist *elist; 183 struct stringlist *Elist; 184 struct stringlist *flist; 185 struct stringlist *Flist; 186 struct stringlist *kfromlist; 187 struct stringlist *ktolist; 188 189 /* 190 * function declarations 191 */ 192 /* 193 addarc(); 194 */ 195 int arccmp(); 196 arctype *arclookup(); 197 /* 198 asgnsamples(); 199 printblurb(); 200 cyclelink(); 201 dfn(); 202 */ 203 bool dfn_busy(); 204 /* 205 dfn_findcycle(); 206 */ 207 bool dfn_numbered(); 208 /* 209 dfn_post_visit(); 210 dfn_pre_visit(); 211 dfn_self_cycle(); 212 */ 213 nltype **doarcs(); 214 /* 215 done(); 216 findcalls(); 217 flatprofheader(); 218 flatprofline(); 219 */ 220 bool funcsymbol(); 221 /* 222 getnfile(); 223 getpfile(); 224 getstrtab(); 225 getsymtab(); 226 gettextspace(); 227 gprofheader(); 228 gprofline(); 229 main(); 230 */ 231 unsigned long max(); 232 int membercmp(); 233 unsigned long min(); 234 nltype *nllookup(); 235 FILE *openpfile(); 236 long operandlength(); 237 operandenum operandmode(); 238 char *operandname(); 239 /* 240 printchildren(); 241 printcycle(); 242 printgprof(); 243 printmembers(); 244 printname(); 245 printparents(); 246 printprof(); 247 readsamples(); 248 */ 249 unsigned long reladdr(); 250 /* 251 sortchildren(); 252 sortmembers(); 253 sortparents(); 254 tally(); 255 timecmp(); 256 topcmp(); 257 */ 258 int totalcmp(); 259 /* 260 valcmp(); 261 */ 262 263 #define LESSTHAN -1 264 #define EQUALTO 0 265 #define GREATERTHAN 1 266 267 #define DFNDEBUG 1 268 #define CYCLEDEBUG 2 269 #define ARCDEBUG 4 270 #define TALLYDEBUG 8 271 #define TIMEDEBUG 16 272 #define SAMPLEDEBUG 32 273 #define AOUTDEBUG 64 274 #define CALLDEBUG 128 275 #define LOOKUPDEBUG 256 276 #define PROPDEBUG 512 277 #define ANYDEBUG 1024 278