gprof.h revision 85739
11590Srgrimes/* 21590Srgrimes * Copyright (c) 1983, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 3. All advertising materials mentioning features or use of this software 141590Srgrimes * must display the following acknowledgement: 151590Srgrimes * This product includes software developed by the University of 161590Srgrimes * California, Berkeley and its contributors. 171590Srgrimes * 4. Neither the name of the University nor the names of its contributors 181590Srgrimes * may be used to endorse or promote products derived from this software 191590Srgrimes * without specific prior written permission. 201590Srgrimes * 211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311590Srgrimes * SUCH DAMAGE. 321590Srgrimes * 331590Srgrimes * @(#)gprof.h 8.1 (Berkeley) 6/6/93 3485353Speter * $FreeBSD: head/usr.bin/gprof/gprof.h 85739 2001-10-30 15:54:09Z green $ 351590Srgrimes */ 361590Srgrimes 371590Srgrimes#include <sys/types.h> 381590Srgrimes#include <sys/stat.h> 391590Srgrimes#include <sys/gmon.h> 401590Srgrimes 411590Srgrimes#include <stdio.h> 421590Srgrimes#include <stdlib.h> 431590Srgrimes 4485353Speter#if __ia64__ 4585353Speter# include "ia64.h" 4685353Speter#endif 4748839Ssimokawa#if __alpha__ 4848839Ssimokawa# include "alpha.h" 4948839Ssimokawa#endif 501590Srgrimes#if vax 511590Srgrimes# include "vax.h" 521590Srgrimes#endif 531590Srgrimes#if sparc 541590Srgrimes# include "sparc.h" 551590Srgrimes#endif 561590Srgrimes#if tahoe 571590Srgrimes# include "tahoe.h" 581590Srgrimes#endif 591590Srgrimes#if hp300 601590Srgrimes# include "hp300.h" 611590Srgrimes#endif 621590Srgrimes#if luna68k 631590Srgrimes# include "luna68k.h" 641590Srgrimes#endif 651590Srgrimes#if i386 661590Srgrimes# include "i386.h" 671590Srgrimes#endif 681590Srgrimes#if mips 691590Srgrimes# include "mips.h" 701590Srgrimes#endif 711590Srgrimes 721590Srgrimes 731590Srgrimes /* 741590Srgrimes * booleans 751590Srgrimes */ 761590Srgrimestypedef int bool; 771590Srgrimes#define FALSE 0 781590Srgrimes#define TRUE 1 791590Srgrimes 801590Srgrimes /* 811590Srgrimes * ticks per second 821590Srgrimes */ 831590Srgrimeslong hz; 841590Srgrimes 8513108Sbde#ifdef GPROF4 8627379Sbdetypedef int64_t UNIT; 8713108Sbde#else 881590Srgrimestypedef u_short UNIT; /* unit of profiling */ 8913108Sbde#endif 901590Srgrimeschar *a_outname; 911590Srgrimes#define A_OUTNAME "a.out" 921590Srgrimes 931590Srgrimeschar *gmonname; 941590Srgrimes#define GMONSUM "gmon.sum" 951590Srgrimes 961590Srgrimes /* 971590Srgrimes * a constructed arc, 981590Srgrimes * with pointers to the namelist entry of the parent and the child, 991590Srgrimes * a count of how many times this arc was traversed, 1001590Srgrimes * and pointers to the next parent of this child and 1011590Srgrimes * the next child of this parent. 1021590Srgrimes */ 1031590Srgrimesstruct arcstruct { 1041590Srgrimes struct nl *arc_parentp; /* pointer to parent's nl entry */ 1051590Srgrimes struct nl *arc_childp; /* pointer to child's nl entry */ 1061590Srgrimes long arc_count; /* num calls from parent to child */ 1071590Srgrimes double arc_time; /* time inherited along arc */ 1081590Srgrimes double arc_childtime; /* childtime inherited along arc */ 1091590Srgrimes struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 1101590Srgrimes struct arcstruct *arc_childlist; /* children-of-this-parent list */ 1111590Srgrimes struct arcstruct *arc_next; /* list of arcs on cycle */ 1121590Srgrimes unsigned short arc_cyclecnt; /* num cycles involved in */ 1131590Srgrimes unsigned short arc_flags; /* see below */ 1141590Srgrimes}; 1151590Srgrimestypedef struct arcstruct arctype; 1161590Srgrimes 1171590Srgrimes /* 1181590Srgrimes * arc flags 1191590Srgrimes */ 1201590Srgrimes#define DEADARC 0x01 /* time should not propagate across the arc */ 1211590Srgrimes#define ONLIST 0x02 /* arc is on list of arcs in cycles */ 1221590Srgrimes 1231590Srgrimes /* 1241590Srgrimes * The symbol table; 1251590Srgrimes * for each external in the specified file we gather 1261590Srgrimes * its address, the number of calls and compute its share of cpu time. 1271590Srgrimes */ 1281590Srgrimesstruct nl { 12938928Sjdp const char *name; /* the name */ 1301590Srgrimes unsigned long value; /* the pc entry point */ 1311590Srgrimes unsigned long svalue; /* entry point aligned to histograms */ 1321590Srgrimes double time; /* ticks in this routine */ 1331590Srgrimes double childtime; /* cumulative ticks in children */ 1341590Srgrimes long ncall; /* how many times called */ 1351590Srgrimes long npropcall; /* times called by live arcs */ 1361590Srgrimes long selfcalls; /* how many calls to self */ 1371590Srgrimes double propfraction; /* what % of time propagates */ 1381590Srgrimes double propself; /* how much self time propagates */ 1391590Srgrimes double propchild; /* how much child time propagates */ 1401590Srgrimes short printflag; /* should this be printed? */ 1411590Srgrimes short flags; /* see below */ 1421590Srgrimes int index; /* index in the graph list */ 1431590Srgrimes int toporder; /* graph call chain top-sort order */ 1441590Srgrimes int cycleno; /* internal number of cycle on */ 1451590Srgrimes int parentcnt; /* number of live parent arcs */ 1461590Srgrimes struct nl *cyclehead; /* pointer to head of cycle */ 1471590Srgrimes struct nl *cnext; /* pointer to next member of cycle */ 1481590Srgrimes arctype *parents; /* list of caller arcs */ 1491590Srgrimes arctype *children; /* list of callee arcs */ 1501590Srgrimes}; 1511590Srgrimestypedef struct nl nltype; 1521590Srgrimes 1531590Srgrimesnltype *nl; /* the whole namelist */ 1541590Srgrimesnltype *npe; /* the virtual end of the namelist */ 1551590Srgrimesint nname; /* the number of function names */ 1561590Srgrimes 1571590Srgrimes#define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 1581590Srgrimes#define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 1591590Srgrimes#define VISITED 0x20 /* node visited during a cycle */ 1601590Srgrimes 1611590Srgrimes /* 1621590Srgrimes * The cycle list. 1631590Srgrimes * for each subcycle within an identified cycle, we gather 1641590Srgrimes * its size and the list of included arcs. 1651590Srgrimes */ 1661590Srgrimesstruct cl { 1671590Srgrimes int size; /* length of cycle */ 1681590Srgrimes struct cl *next; /* next member of list */ 1691590Srgrimes arctype *list[1]; /* list of arcs in cycle */ 1701590Srgrimes /* actually longer */ 1711590Srgrimes}; 1721590Srgrimestypedef struct cl cltype; 1731590Srgrimes 1741590Srgrimesarctype *archead; /* the head of arcs in current cycle list */ 1751590Srgrimescltype *cyclehead; /* the head of the list */ 1761590Srgrimesint cyclecnt; /* the number of cycles found */ 1771590Srgrimes#define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 1781590Srgrimes 1791590Srgrimes /* 1801590Srgrimes * flag which marks a nl entry as topologically ``busy'' 1811590Srgrimes * flag which marks a nl entry as topologically ``not_numbered'' 1821590Srgrimes */ 1831590Srgrimes#define DFN_BUSY -1 1841590Srgrimes#define DFN_NAN 0 1851590Srgrimes 1868874Srgrimes /* 1871590Srgrimes * namelist entries for cycle headers. 1881590Srgrimes * the number of discovered cycles. 1891590Srgrimes */ 1901590Srgrimesnltype *cyclenl; /* cycle header namelist */ 1911590Srgrimesint ncycle; /* number of cycles discovered */ 1921590Srgrimes 1931590Srgrimes /* 1941590Srgrimes * The header on the gmon.out file. 1951590Srgrimes * gmon.out consists of a struct phdr (defined in gmon.h) 1961590Srgrimes * and then an array of ncnt samples representing the 1971590Srgrimes * discretized program counter values. 1981590Srgrimes * 1991590Srgrimes * Backward compatible old style header 2001590Srgrimes */ 2011590Srgrimesstruct ophdr { 2021590Srgrimes UNIT *lpc; 2031590Srgrimes UNIT *hpc; 2041590Srgrimes int ncnt; 2051590Srgrimes}; 2061590Srgrimes 2071590Srgrimesint debug; 2081590Srgrimes 2091590Srgrimes /* 2101590Srgrimes * Each discretized pc sample has 2111590Srgrimes * a count of the number of samples in its range 2121590Srgrimes */ 2131590SrgrimesUNIT *samples; 2141590Srgrimes 2151590Srgrimesunsigned long s_lowpc; /* lowpc from the profile file */ 2161590Srgrimesunsigned long s_highpc; /* highpc from the profile file */ 21748839Ssimokawaunsigned long lowpc, highpc; /* range profiled, in UNIT's */ 2181590Srgrimesunsigned sampbytes; /* number of bytes of samples */ 2191590Srgrimesint nsamples; /* number of samples */ 2201590Srgrimesdouble actime; /* accumulated time thus far for putprofline */ 2211590Srgrimesdouble totime; /* total time for all routines */ 2221590Srgrimesdouble printtime; /* total of time being printed */ 2231590Srgrimesdouble scale; /* scale factor converting samples to pc 2241590Srgrimes values: each sample covers scale bytes */ 2251590Srgrimesunsigned char *textspace; /* text space of a.out in core */ 2261590Srgrimesint cyclethreshold; /* with -C, minimum cycle size to ignore */ 2271590Srgrimes 2281590Srgrimes /* 2291590Srgrimes * option flags, from a to z. 2301590Srgrimes */ 2311590Srgrimesbool aflag; /* suppress static functions */ 2321590Srgrimesbool bflag; /* blurbs, too */ 2331590Srgrimesbool cflag; /* discovered call graph, too */ 2341590Srgrimesbool Cflag; /* find cut-set to eliminate cycles */ 2351590Srgrimesbool dflag; /* debugging options */ 2361590Srgrimesbool eflag; /* specific functions excluded */ 2371590Srgrimesbool Eflag; /* functions excluded with time */ 2381590Srgrimesbool fflag; /* specific functions requested */ 2391590Srgrimesbool Fflag; /* functions requested with time */ 2401590Srgrimesbool kflag; /* arcs to be deleted */ 24185739Sgreenbool Kflag; /* use the running kernel for symbols */ 2421590Srgrimesbool sflag; /* sum multiple gmon.out files */ 24338928Sjdpbool uflag; /* suppress symbols hidden from C */ 2441590Srgrimesbool zflag; /* zero time/called functions, too */ 2451590Srgrimes 2461590Srgrimes /* 2471590Srgrimes * structure for various string lists 2481590Srgrimes */ 2491590Srgrimesstruct stringlist { 2501590Srgrimes struct stringlist *next; 2511590Srgrimes char *string; 2521590Srgrimes}; 2531590Srgrimesstruct stringlist *elist; 2541590Srgrimesstruct stringlist *Elist; 2551590Srgrimesstruct stringlist *flist; 2561590Srgrimesstruct stringlist *Flist; 2571590Srgrimesstruct stringlist *kfromlist; 2581590Srgrimesstruct stringlist *ktolist; 2591590Srgrimes 2601590Srgrimes /* 2611590Srgrimes * function declarations 2621590Srgrimes */ 2631590Srgrimes/* 2641590Srgrimes addarc(); 2651590Srgrimes*/ 26638928Sjdpint aout_getnfile(const char *, char ***); 2671590Srgrimesint arccmp(); 2681590Srgrimesarctype *arclookup(); 2691590Srgrimes/* 2701590Srgrimes asgnsamples(); 2711590Srgrimes printblurb(); 2721590Srgrimes cyclelink(); 2731590Srgrimes dfn(); 2741590Srgrimes*/ 2751590Srgrimesbool dfn_busy(); 2761590Srgrimes/* 2771590Srgrimes dfn_findcycle(); 2781590Srgrimes*/ 2791590Srgrimesbool dfn_numbered(); 2801590Srgrimes/* 2811590Srgrimes dfn_post_visit(); 2821590Srgrimes dfn_pre_visit(); 2831590Srgrimes dfn_self_cycle(); 2841590Srgrimes*/ 2851590Srgrimesnltype **doarcs(); 2861590Srgrimes/* 2871590Srgrimes done(); 28838928Sjdp*/ 28938928Sjdpint elf_getnfile(const char *, char ***); 29038928Sjdp/* 2911590Srgrimes findcalls(); 2921590Srgrimes flatprofheader(); 2931590Srgrimes flatprofline(); 2941590Srgrimes*/ 2951590Srgrimes/* 2961590Srgrimes getpfile(); 2971590Srgrimes gprofheader(); 2981590Srgrimes gprofline(); 29985739Sgreen*/ 30085739Sgreenint kernel_getnfile(const char *, char ***); 30185739Sgreen/* 3021590Srgrimes main(); 3031590Srgrimes*/ 3041590Srgrimesunsigned long max(); 3051590Srgrimesint membercmp(); 3061590Srgrimesunsigned long min(); 3071590Srgrimesnltype *nllookup(); 3081590SrgrimesFILE *openpfile(); 3091590Srgrimeslong operandlength(); 3101590Srgrimesoperandenum operandmode(); 3111590Srgrimeschar *operandname(); 3121590Srgrimes/* 3131590Srgrimes printchildren(); 3141590Srgrimes printcycle(); 3151590Srgrimes printgprof(); 3161590Srgrimes printmembers(); 3171590Srgrimes printname(); 3181590Srgrimes printparents(); 3191590Srgrimes printprof(); 3201590Srgrimes readsamples(); 3211590Srgrimes*/ 3221590Srgrimesunsigned long reladdr(); 3231590Srgrimes/* 3241590Srgrimes sortchildren(); 3251590Srgrimes sortmembers(); 3261590Srgrimes sortparents(); 3271590Srgrimes tally(); 3281590Srgrimes timecmp(); 3291590Srgrimes topcmp(); 3301590Srgrimes*/ 3311590Srgrimesint totalcmp(); 3321590Srgrimes/* 3331590Srgrimes valcmp(); 3341590Srgrimes*/ 3351590Srgrimes 3361590Srgrimes#define LESSTHAN -1 3371590Srgrimes#define EQUALTO 0 3381590Srgrimes#define GREATERTHAN 1 3391590Srgrimes 3401590Srgrimes#define DFNDEBUG 1 3411590Srgrimes#define CYCLEDEBUG 2 3421590Srgrimes#define ARCDEBUG 4 3431590Srgrimes#define TALLYDEBUG 8 3441590Srgrimes#define TIMEDEBUG 16 3451590Srgrimes#define SAMPLEDEBUG 32 3461590Srgrimes#define AOUTDEBUG 64 3471590Srgrimes#define CALLDEBUG 128 3481590Srgrimes#define LOOKUPDEBUG 256 3491590Srgrimes#define PROPDEBUG 512 3501590Srgrimes#define BREAKCYCLE 1024 3511590Srgrimes#define SUBCYCLELIST 2048 3521590Srgrimes#define ANYDEBUG 4096 353