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