gprof.h revision 91976
1257378Sbdrewery/* 2257378Sbdrewery * Copyright (c) 1983, 1993 3257378Sbdrewery * The Regents of the University of California. All rights reserved. 4257378Sbdrewery * 5257378Sbdrewery * Redistribution and use in source and binary forms, with or without 6257378Sbdrewery * modification, are permitted provided that the following conditions 7257378Sbdrewery * are met: 8257378Sbdrewery * 1. Redistributions of source code must retain the above copyright 9257378Sbdrewery * notice, this list of conditions and the following disclaimer. 10257378Sbdrewery * 2. Redistributions in binary form must reproduce the above copyright 11257378Sbdrewery * notice, this list of conditions and the following disclaimer in the 12257378Sbdrewery * documentation and/or other materials provided with the distribution. 13257378Sbdrewery * 3. All advertising materials mentioning features or use of this software 14257378Sbdrewery * must display the following acknowledgement: 15257378Sbdrewery * This product includes software developed by the University of 16257378Sbdrewery * California, Berkeley and its contributors. 17257378Sbdrewery * 4. Neither the name of the University nor the names of its contributors 18257378Sbdrewery * may be used to endorse or promote products derived from this software 19257378Sbdrewery * without specific prior written permission. 20257378Sbdrewery * 21257378Sbdrewery * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22257378Sbdrewery * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23257378Sbdrewery * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24257378Sbdrewery * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25257378Sbdrewery * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26257378Sbdrewery * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27259614Sbdrewery * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28257378Sbdrewery * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29257378Sbdrewery * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30257378Sbdrewery * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31257378Sbdrewery * SUCH DAMAGE. 32257573Sbdrewery * 33257378Sbdrewery * @(#)gprof.h 8.1 (Berkeley) 6/6/93 34257378Sbdrewery * $FreeBSD: head/usr.bin/gprof/gprof.h 91976 2002-03-10 01:25:47Z jake $ 35257378Sbdrewery */ 36257378Sbdrewery 37257378Sbdrewery#include <sys/types.h> 38257632Sbdrewery#include <sys/stat.h> 39257378Sbdrewery#include <sys/gmon.h> 40257378Sbdrewery 41257378Sbdrewery#include <stdio.h> 42257378Sbdrewery#include <stdlib.h> 43257378Sbdrewery 44257632Sbdrewery#if __ia64__ 45257378Sbdrewery# include "ia64.h" 46257378Sbdrewery#endif 47257378Sbdrewery#if __alpha__ 48257378Sbdrewery# include "alpha.h" 49257378Sbdrewery#endif 50257378Sbdrewery#if __sparc64__ 51257378Sbdrewery# include "sparc64.h" 52257378Sbdrewery#endif 53257378Sbdrewery#if vax 54257378Sbdrewery# include "vax.h" 55257378Sbdrewery#endif 56257378Sbdrewery#if sparc 57257378Sbdrewery# include "sparc.h" 58257378Sbdrewery#endif 59257378Sbdrewery#if tahoe 60257632Sbdrewery# include "tahoe.h" 61257378Sbdrewery#endif 62257378Sbdrewery#if hp300 63257378Sbdrewery# include "hp300.h" 64257378Sbdrewery#endif 65257378Sbdrewery#if luna68k 66257378Sbdrewery# include "luna68k.h" 67257378Sbdrewery#endif 68257632Sbdrewery#if i386 69257378Sbdrewery# include "i386.h" 70257378Sbdrewery#endif 71257378Sbdrewery#if mips 72257378Sbdrewery# include "mips.h" 73257378Sbdrewery#endif 74257378Sbdrewery 75257378Sbdrewery 76257378Sbdrewery /* 77257632Sbdrewery * booleans 78257632Sbdrewery */ 79257632Sbdrewerytypedef int bool; 80257632Sbdrewery#define FALSE 0 81257632Sbdrewery#define TRUE 1 82257378Sbdrewery 83257378Sbdrewery /* 84257378Sbdrewery * Historical scale factor in profil(2)'s algorithm for converting 85257378Sbdrewery * pc addresses to bucket numbers. This now just complicates the 86257378Sbdrewery * scaling and makes bucket:pc densities of more than 1/2 useless. 87257378Sbdrewery */ 88257632Sbdrewery#define HISTORICAL_SCALE_2 2 89257378Sbdrewery 90257378Sbdrewery /* 91257378Sbdrewery * ticks per second 92257632Sbdrewery */ 93257632Sbdrewerylong hz; 94257632Sbdrewery 95257632Sbdrewerysize_t histcounter_size; 96257632Sbdreweryint histcounter_type; 97257378Sbdrewery 98257378Sbdrewerychar *a_outname; 99257378Sbdrewery#define A_OUTNAME "a.out" 100257378Sbdrewery 101257378Sbdrewerychar *gmonname; 102257378Sbdrewery#define GMONSUM "gmon.sum" 103257378Sbdrewery 104257378Sbdrewery /* 105257378Sbdrewery * a constructed arc, 106257378Sbdrewery * with pointers to the namelist entry of the parent and the child, 107257378Sbdrewery * a count of how many times this arc was traversed, 108257378Sbdrewery * and pointers to the next parent of this child and 109257378Sbdrewery * the next child of this parent. 110257378Sbdrewery */ 111258755Sbdrewerystruct arcstruct { 112257378Sbdrewery struct nl *arc_parentp; /* pointer to parent's nl entry */ 113257378Sbdrewery struct nl *arc_childp; /* pointer to child's nl entry */ 114257378Sbdrewery long arc_count; /* num calls from parent to child */ 115257378Sbdrewery double arc_time; /* time inherited along arc */ 116257378Sbdrewery double arc_childtime; /* childtime inherited along arc */ 117257378Sbdrewery struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 118257378Sbdrewery struct arcstruct *arc_childlist; /* children-of-this-parent list */ 119257378Sbdrewery struct arcstruct *arc_next; /* list of arcs on cycle */ 120257378Sbdrewery unsigned short arc_cyclecnt; /* num cycles involved in */ 121257378Sbdrewery unsigned short arc_flags; /* see below */ 122257378Sbdrewery}; 123257378Sbdrewerytypedef struct arcstruct arctype; 124257378Sbdrewery 125257378Sbdrewery /* 126257378Sbdrewery * arc flags 127257378Sbdrewery */ 128257378Sbdrewery#define DEADARC 0x01 /* time should not propagate across the arc */ 129257378Sbdrewery#define ONLIST 0x02 /* arc is on list of arcs in cycles */ 130257378Sbdrewery 131257378Sbdrewery /* 132257378Sbdrewery * The symbol table; 133257378Sbdrewery * for each external in the specified file we gather 134257378Sbdrewery * its address, the number of calls and compute its share of cpu time. 135257378Sbdrewery */ 136257378Sbdrewerystruct nl { 137257378Sbdrewery const char *name; /* the name */ 138257378Sbdrewery unsigned long value; /* the pc entry point */ 139257378Sbdrewery unsigned long svalue; /* entry point aligned to histograms */ 140257378Sbdrewery double time; /* ticks in this routine */ 141257378Sbdrewery double childtime; /* cumulative ticks in children */ 142257378Sbdrewery long ncall; /* how many times called */ 143257378Sbdrewery long npropcall; /* times called by live arcs */ 144257378Sbdrewery long selfcalls; /* how many calls to self */ 145257378Sbdrewery double propfraction; /* what % of time propagates */ 146257378Sbdrewery double propself; /* how much self time propagates */ 147257378Sbdrewery double propchild; /* how much child time propagates */ 148257378Sbdrewery short printflag; /* should this be printed? */ 149257378Sbdrewery short flags; /* see below */ 150257797Sbdrewery int index; /* index in the graph list */ 151257378Sbdrewery int toporder; /* graph call chain top-sort order */ 152257378Sbdrewery int cycleno; /* internal number of cycle on */ 153257378Sbdrewery int parentcnt; /* number of live parent arcs */ 154257378Sbdrewery struct nl *cyclehead; /* pointer to head of cycle */ 155259614Sbdrewery struct nl *cnext; /* pointer to next member of cycle */ 156257378Sbdrewery arctype *parents; /* list of caller arcs */ 157257573Sbdrewery arctype *children; /* list of callee arcs */ 158257378Sbdrewery}; 159257378Sbdrewerytypedef struct nl nltype; 160257378Sbdrewery 161257378Sbdrewerynltype *nl; /* the whole namelist */ 162257378Sbdrewerynltype *npe; /* the virtual end of the namelist */ 163257378Sbdreweryint nname; /* the number of function names */ 164257378Sbdrewery 165257378Sbdrewery#define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 166257378Sbdrewery#define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 167257378Sbdrewery#define VISITED 0x20 /* node visited during a cycle */ 168257378Sbdrewery 169257378Sbdrewery /* 170257378Sbdrewery * The cycle list. 171257378Sbdrewery * for each subcycle within an identified cycle, we gather 172257378Sbdrewery * its size and the list of included arcs. 173257378Sbdrewery */ 174257378Sbdrewerystruct cl { 175257378Sbdrewery int size; /* length of cycle */ 176257378Sbdrewery struct cl *next; /* next member of list */ 177257378Sbdrewery arctype *list[1]; /* list of arcs in cycle */ 178257378Sbdrewery /* actually longer */ 179257378Sbdrewery}; 180257378Sbdrewerytypedef struct cl cltype; 181257378Sbdrewery 182257378Sbdreweryarctype *archead; /* the head of arcs in current cycle list */ 183257378Sbdrewerycltype *cyclehead; /* the head of the list */ 184257378Sbdreweryint cyclecnt; /* the number of cycles found */ 185257378Sbdrewery#define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 186257378Sbdrewery 187257378Sbdrewery /* 188257378Sbdrewery * flag which marks a nl entry as topologically ``busy'' 189257378Sbdrewery * flag which marks a nl entry as topologically ``not_numbered'' 190257378Sbdrewery */ 191257378Sbdrewery#define DFN_BUSY -1 192257378Sbdrewery#define DFN_NAN 0 193257378Sbdrewery 194257378Sbdrewery /* 195257378Sbdrewery * namelist entries for cycle headers. 196257378Sbdrewery * the number of discovered cycles. 197257378Sbdrewery */ 198259614Sbdrewerynltype *cyclenl; /* cycle header namelist */ 199259614Sbdreweryint ncycle; /* number of cycles discovered */ 200259614Sbdrewery 201257378Sbdrewery /* 202257378Sbdrewery * The header on the gmon.out file. 203257378Sbdrewery * gmon.out consists of a struct phdr (defined in gmon.h) 204259614Sbdrewery * and then an array of ncnt samples representing the 205259614Sbdrewery * discretized program counter values. 206259614Sbdrewery * 207257378Sbdrewery * Backward compatible old style header 208257378Sbdrewery */ 209257378Sbdrewerystruct ophdr { 210257378Sbdrewery u_short *lpc; 211259614Sbdrewery u_short *hpc; 212257378Sbdrewery int ncnt; 213257378Sbdrewery}; 214257378Sbdrewery 215257378Sbdreweryint debug; 216257378Sbdrewery 217257378Sbdrewery /* 218257378Sbdrewery * Each discretized pc sample has 219257378Sbdrewery * a count of the number of samples in its range 220257378Sbdrewery */ 221257378Sbdrewerydouble *samples; 222257378Sbdrewery 223257378Sbdreweryunsigned long s_lowpc; /* lowpc from the profile file */ 224257378Sbdreweryunsigned long s_highpc; /* highpc from the profile file */ 225257378Sbdreweryunsigned long lowpc, highpc; /* range profiled, in historical units */ 226257378Sbdreweryunsigned sampbytes; /* number of bytes of samples */ 227257378Sbdreweryint nsamples; /* number of samples */ 228257378Sbdrewerydouble actime; /* accumulated time thus far for putprofline */ 229257378Sbdrewerydouble totime; /* total time for all routines */ 230257378Sbdrewerydouble printtime; /* total of time being printed */ 231257378Sbdrewerydouble scale; /* scale factor converting samples to pc 232257378Sbdrewery values: each sample covers scale bytes */ 233257378Sbdreweryunsigned char *textspace; /* text space of a.out in core */ 234257378Sbdreweryint cyclethreshold; /* with -C, minimum cycle size to ignore */ 235257378Sbdrewery 236257378Sbdrewery /* 237257378Sbdrewery * option flags, from a to z. 238257378Sbdrewery */ 239257378Sbdrewerybool aflag; /* suppress static functions */ 240257378Sbdrewerybool bflag; /* blurbs, too */ 241257378Sbdrewerybool cflag; /* discovered call graph, too */ 242257378Sbdrewerybool Cflag; /* find cut-set to eliminate cycles */ 243257378Sbdrewerybool dflag; /* debugging options */ 244257378Sbdrewerybool eflag; /* specific functions excluded */ 245257378Sbdrewerybool Eflag; /* functions excluded with time */ 246257378Sbdrewerybool fflag; /* specific functions requested */ 247257378Sbdrewerybool Fflag; /* functions requested with time */ 248257378Sbdrewerybool kflag; /* arcs to be deleted */ 249257378Sbdrewerybool Kflag; /* use the running kernel for symbols */ 250257378Sbdrewerybool sflag; /* sum multiple gmon.out files */ 251257378Sbdrewerybool uflag; /* suppress symbols hidden from C */ 252257378Sbdrewerybool zflag; /* zero time/called functions, too */ 253257378Sbdrewery 254257378Sbdrewery /* 255257378Sbdrewery * structure for various string lists 256257378Sbdrewery */ 257257378Sbdrewerystruct stringlist { 258257378Sbdrewery struct stringlist *next; 259257378Sbdrewery char *string; 260257378Sbdrewery}; 261257378Sbdrewerystruct stringlist *elist; 262257378Sbdrewerystruct stringlist *Elist; 263257378Sbdrewerystruct stringlist *flist; 264257378Sbdrewerystruct stringlist *Flist; 265257378Sbdrewerystruct stringlist *kfromlist; 266257378Sbdrewerystruct stringlist *ktolist; 267257378Sbdrewery 268257573Sbdrewery /* 269257573Sbdrewery * function declarations 270257378Sbdrewery */ 271257378Sbdrewery/* 272257378Sbdrewery addarc(); 273257378Sbdrewery*/ 274257378Sbdreweryint aout_getnfile(const char *, char ***); 275257378Sbdreweryint arccmp(); 276257378Sbdreweryarctype *arclookup(); 277257378Sbdrewery/* 278257378Sbdrewery asgnsamples(); 279257378Sbdrewery printblurb(); 280257378Sbdrewery cyclelink(); 281257378Sbdrewery dfn(); 282*/ 283bool dfn_busy(); 284/* 285 dfn_findcycle(); 286*/ 287bool dfn_numbered(); 288/* 289 dfn_post_visit(); 290 dfn_pre_visit(); 291 dfn_self_cycle(); 292*/ 293nltype **doarcs(); 294/* 295 done(); 296*/ 297int elf_getnfile(const char *, char ***); 298/* 299 findcalls(); 300 flatprofheader(); 301 flatprofline(); 302*/ 303/* 304 getpfile(); 305 gprofheader(); 306 gprofline(); 307*/ 308int kernel_getnfile(const char *, char ***); 309/* 310 main(); 311*/ 312unsigned long max(); 313int membercmp(); 314unsigned long min(); 315nltype *nllookup(); 316FILE *openpfile(); 317long operandlength(); 318operandenum operandmode(); 319char *operandname(); 320/* 321 printchildren(); 322 printcycle(); 323 printgprof(); 324 printmembers(); 325 printname(); 326 printparents(); 327 printprof(); 328 readsamples(); 329*/ 330unsigned long reladdr(); 331/* 332 sortchildren(); 333 sortmembers(); 334 sortparents(); 335 tally(); 336 timecmp(); 337 topcmp(); 338*/ 339int totalcmp(); 340/* 341 valcmp(); 342*/ 343 344#define LESSTHAN -1 345#define EQUALTO 0 346#define GREATERTHAN 1 347 348#define DFNDEBUG 1 349#define CYCLEDEBUG 2 350#define ARCDEBUG 4 351#define TALLYDEBUG 8 352#define TIMEDEBUG 16 353#define SAMPLEDEBUG 32 354#define AOUTDEBUG 64 355#define CALLDEBUG 128 356#define LOOKUPDEBUG 256 357#define PROPDEBUG 512 358#define BREAKCYCLE 1024 359#define SUBCYCLELIST 2048 360#define ANYDEBUG 4096 361