gprof.h revision 38928
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)gprof.h 8.1 (Berkeley) 6/6/93 34 */ 35 36#include <sys/types.h> 37#include <sys/stat.h> 38#include <sys/gmon.h> 39 40#include <stdio.h> 41#include <stdlib.h> 42 43#if vax 44# include "vax.h" 45#endif 46#if sparc 47# include "sparc.h" 48#endif 49#if tahoe 50# include "tahoe.h" 51#endif 52#if hp300 53# include "hp300.h" 54#endif 55#if luna68k 56# include "luna68k.h" 57#endif 58#if i386 59# include "i386.h" 60#endif 61#if mips 62# include "mips.h" 63#endif 64 65 66 /* 67 * booleans 68 */ 69typedef int bool; 70#define FALSE 0 71#define TRUE 1 72 73 /* 74 * ticks per second 75 */ 76long hz; 77 78#ifdef GPROF4 79typedef int64_t UNIT; 80#else 81typedef u_short UNIT; /* unit of profiling */ 82#endif 83char *a_outname; 84#define A_OUTNAME "a.out" 85 86char *gmonname; 87#define GMONNAME "gmon.out" 88#define GMONSUM "gmon.sum" 89 90 /* 91 * a constructed arc, 92 * with pointers to the namelist entry of the parent and the child, 93 * a count of how many times this arc was traversed, 94 * and pointers to the next parent of this child and 95 * the next child of this parent. 96 */ 97struct arcstruct { 98 struct nl *arc_parentp; /* pointer to parent's nl entry */ 99 struct nl *arc_childp; /* pointer to child's nl entry */ 100 long arc_count; /* num calls from parent to child */ 101 double arc_time; /* time inherited along arc */ 102 double arc_childtime; /* childtime inherited along arc */ 103 struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 104 struct arcstruct *arc_childlist; /* children-of-this-parent list */ 105 struct arcstruct *arc_next; /* list of arcs on cycle */ 106 unsigned short arc_cyclecnt; /* num cycles involved in */ 107 unsigned short arc_flags; /* see below */ 108}; 109typedef struct arcstruct arctype; 110 111 /* 112 * arc flags 113 */ 114#define DEADARC 0x01 /* time should not propagate across the arc */ 115#define ONLIST 0x02 /* arc is on list of arcs in cycles */ 116 117 /* 118 * The symbol table; 119 * for each external in the specified file we gather 120 * its address, the number of calls and compute its share of cpu time. 121 */ 122struct nl { 123 const char *name; /* the name */ 124 unsigned long value; /* the pc entry point */ 125 unsigned long svalue; /* entry point aligned to histograms */ 126 double time; /* ticks in this routine */ 127 double childtime; /* cumulative ticks in children */ 128 long ncall; /* how many times called */ 129 long npropcall; /* times called by live arcs */ 130 long selfcalls; /* how many calls to self */ 131 double propfraction; /* what % of time propagates */ 132 double propself; /* how much self time propagates */ 133 double propchild; /* how much child time propagates */ 134 short printflag; /* should this be printed? */ 135 short flags; /* see below */ 136 int index; /* index in the graph list */ 137 int toporder; /* graph call chain top-sort order */ 138 int cycleno; /* internal number of cycle on */ 139 int parentcnt; /* number of live parent arcs */ 140 struct nl *cyclehead; /* pointer to head of cycle */ 141 struct nl *cnext; /* pointer to next member of cycle */ 142 arctype *parents; /* list of caller arcs */ 143 arctype *children; /* list of callee arcs */ 144}; 145typedef struct nl nltype; 146 147nltype *nl; /* the whole namelist */ 148nltype *npe; /* the virtual end of the namelist */ 149int nname; /* the number of function names */ 150 151#define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 152#define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 153#define VISITED 0x20 /* node visited during a cycle */ 154 155 /* 156 * The cycle list. 157 * for each subcycle within an identified cycle, we gather 158 * its size and the list of included arcs. 159 */ 160struct cl { 161 int size; /* length of cycle */ 162 struct cl *next; /* next member of list */ 163 arctype *list[1]; /* list of arcs in cycle */ 164 /* actually longer */ 165}; 166typedef struct cl cltype; 167 168arctype *archead; /* the head of arcs in current cycle list */ 169cltype *cyclehead; /* the head of the list */ 170int cyclecnt; /* the number of cycles found */ 171#define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 172 173 /* 174 * flag which marks a nl entry as topologically ``busy'' 175 * flag which marks a nl entry as topologically ``not_numbered'' 176 */ 177#define DFN_BUSY -1 178#define DFN_NAN 0 179 180 /* 181 * namelist entries for cycle headers. 182 * the number of discovered cycles. 183 */ 184nltype *cyclenl; /* cycle header namelist */ 185int ncycle; /* number of cycles discovered */ 186 187 /* 188 * The header on the gmon.out file. 189 * gmon.out consists of a struct phdr (defined in gmon.h) 190 * and then an array of ncnt samples representing the 191 * discretized program counter values. 192 * 193 * Backward compatible old style header 194 */ 195struct ophdr { 196 UNIT *lpc; 197 UNIT *hpc; 198 int ncnt; 199}; 200 201int debug; 202 203 /* 204 * Each discretized pc sample has 205 * a count of the number of samples in its range 206 */ 207UNIT *samples; 208 209unsigned long s_lowpc; /* lowpc from the profile file */ 210unsigned long s_highpc; /* highpc from the profile file */ 211unsigned lowpc, highpc; /* range profiled, in UNIT's */ 212unsigned sampbytes; /* number of bytes of samples */ 213int nsamples; /* number of samples */ 214double actime; /* accumulated time thus far for putprofline */ 215double totime; /* total time for all routines */ 216double printtime; /* total of time being printed */ 217double scale; /* scale factor converting samples to pc 218 values: each sample covers scale bytes */ 219unsigned char *textspace; /* text space of a.out in core */ 220int cyclethreshold; /* with -C, minimum cycle size to ignore */ 221 222 /* 223 * option flags, from a to z. 224 */ 225bool aflag; /* suppress static functions */ 226bool bflag; /* blurbs, too */ 227bool cflag; /* discovered call graph, too */ 228bool Cflag; /* find cut-set to eliminate cycles */ 229bool dflag; /* debugging options */ 230bool eflag; /* specific functions excluded */ 231bool Eflag; /* functions excluded with time */ 232bool fflag; /* specific functions requested */ 233bool Fflag; /* functions requested with time */ 234bool kflag; /* arcs to be deleted */ 235bool sflag; /* sum multiple gmon.out files */ 236bool uflag; /* suppress symbols hidden from C */ 237bool zflag; /* zero time/called functions, too */ 238 239 /* 240 * structure for various string lists 241 */ 242struct stringlist { 243 struct stringlist *next; 244 char *string; 245}; 246struct stringlist *elist; 247struct stringlist *Elist; 248struct stringlist *flist; 249struct stringlist *Flist; 250struct stringlist *kfromlist; 251struct stringlist *ktolist; 252 253 /* 254 * function declarations 255 */ 256/* 257 addarc(); 258*/ 259int aout_getnfile(const char *, char ***); 260int arccmp(); 261arctype *arclookup(); 262/* 263 asgnsamples(); 264 printblurb(); 265 cyclelink(); 266 dfn(); 267*/ 268bool dfn_busy(); 269/* 270 dfn_findcycle(); 271*/ 272bool dfn_numbered(); 273/* 274 dfn_post_visit(); 275 dfn_pre_visit(); 276 dfn_self_cycle(); 277*/ 278nltype **doarcs(); 279/* 280 done(); 281*/ 282int elf_getnfile(const char *, char ***); 283/* 284 findcalls(); 285 flatprofheader(); 286 flatprofline(); 287*/ 288/* 289 getpfile(); 290 gprofheader(); 291 gprofline(); 292 main(); 293*/ 294unsigned long max(); 295int membercmp(); 296unsigned long min(); 297nltype *nllookup(); 298FILE *openpfile(); 299long operandlength(); 300operandenum operandmode(); 301char *operandname(); 302/* 303 printchildren(); 304 printcycle(); 305 printgprof(); 306 printmembers(); 307 printname(); 308 printparents(); 309 printprof(); 310 readsamples(); 311*/ 312unsigned long reladdr(); 313/* 314 sortchildren(); 315 sortmembers(); 316 sortparents(); 317 tally(); 318 timecmp(); 319 topcmp(); 320*/ 321int totalcmp(); 322/* 323 valcmp(); 324*/ 325 326#define LESSTHAN -1 327#define EQUALTO 0 328#define GREATERTHAN 1 329 330#define DFNDEBUG 1 331#define CYCLEDEBUG 2 332#define ARCDEBUG 4 333#define TALLYDEBUG 8 334#define TIMEDEBUG 16 335#define SAMPLEDEBUG 32 336#define AOUTDEBUG 64 337#define CALLDEBUG 128 338#define LOOKUPDEBUG 256 339#define PROPDEBUG 512 340#define BREAKCYCLE 1024 341#define SUBCYCLELIST 2048 342#define ANYDEBUG 4096 343