gprof.h revision 1590
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 341590Srgrimes */ 351590Srgrimes 361590Srgrimes#include <sys/types.h> 371590Srgrimes#include <sys/stat.h> 381590Srgrimes#include <sys/gmon.h> 391590Srgrimes 401590Srgrimes#include <a.out.h> 411590Srgrimes#include <stdio.h> 421590Srgrimes#include <stdlib.h> 431590Srgrimes 441590Srgrimes#if vax 451590Srgrimes# include "vax.h" 461590Srgrimes#endif 471590Srgrimes#if sparc 481590Srgrimes# include "sparc.h" 491590Srgrimes#endif 501590Srgrimes#if tahoe 511590Srgrimes# include "tahoe.h" 521590Srgrimes#endif 531590Srgrimes#if hp300 541590Srgrimes# include "hp300.h" 551590Srgrimes#endif 561590Srgrimes#if luna68k 571590Srgrimes# include "luna68k.h" 581590Srgrimes#endif 591590Srgrimes#if i386 601590Srgrimes# include "i386.h" 611590Srgrimes#endif 621590Srgrimes#if mips 631590Srgrimes# include "mips.h" 641590Srgrimes#endif 651590Srgrimes 661590Srgrimes 671590Srgrimes /* 681590Srgrimes * who am i, for error messages. 691590Srgrimes */ 701590Srgrimeschar *whoami; 711590Srgrimes 721590Srgrimes /* 731590Srgrimes * booleans 741590Srgrimes */ 751590Srgrimestypedef int bool; 761590Srgrimes#define FALSE 0 771590Srgrimes#define TRUE 1 781590Srgrimes 791590Srgrimes /* 801590Srgrimes * ticks per second 811590Srgrimes */ 821590Srgrimeslong hz; 831590Srgrimes 841590Srgrimestypedef u_short UNIT; /* unit of profiling */ 851590Srgrimeschar *a_outname; 861590Srgrimes#define A_OUTNAME "a.out" 871590Srgrimes 881590Srgrimeschar *gmonname; 891590Srgrimes#define GMONNAME "gmon.out" 901590Srgrimes#define GMONSUM "gmon.sum" 911590Srgrimes 921590Srgrimes /* 931590Srgrimes * a constructed arc, 941590Srgrimes * with pointers to the namelist entry of the parent and the child, 951590Srgrimes * a count of how many times this arc was traversed, 961590Srgrimes * and pointers to the next parent of this child and 971590Srgrimes * the next child of this parent. 981590Srgrimes */ 991590Srgrimesstruct arcstruct { 1001590Srgrimes struct nl *arc_parentp; /* pointer to parent's nl entry */ 1011590Srgrimes struct nl *arc_childp; /* pointer to child's nl entry */ 1021590Srgrimes long arc_count; /* num calls from parent to child */ 1031590Srgrimes double arc_time; /* time inherited along arc */ 1041590Srgrimes double arc_childtime; /* childtime inherited along arc */ 1051590Srgrimes struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 1061590Srgrimes struct arcstruct *arc_childlist; /* children-of-this-parent list */ 1071590Srgrimes struct arcstruct *arc_next; /* list of arcs on cycle */ 1081590Srgrimes unsigned short arc_cyclecnt; /* num cycles involved in */ 1091590Srgrimes unsigned short arc_flags; /* see below */ 1101590Srgrimes}; 1111590Srgrimestypedef struct arcstruct arctype; 1121590Srgrimes 1131590Srgrimes /* 1141590Srgrimes * arc flags 1151590Srgrimes */ 1161590Srgrimes#define DEADARC 0x01 /* time should not propagate across the arc */ 1171590Srgrimes#define ONLIST 0x02 /* arc is on list of arcs in cycles */ 1181590Srgrimes 1191590Srgrimes /* 1201590Srgrimes * The symbol table; 1211590Srgrimes * for each external in the specified file we gather 1221590Srgrimes * its address, the number of calls and compute its share of cpu time. 1231590Srgrimes */ 1241590Srgrimesstruct nl { 1251590Srgrimes char *name; /* the name */ 1261590Srgrimes unsigned long value; /* the pc entry point */ 1271590Srgrimes unsigned long svalue; /* entry point aligned to histograms */ 1281590Srgrimes double time; /* ticks in this routine */ 1291590Srgrimes double childtime; /* cumulative ticks in children */ 1301590Srgrimes long ncall; /* how many times called */ 1311590Srgrimes long npropcall; /* times called by live arcs */ 1321590Srgrimes long selfcalls; /* how many calls to self */ 1331590Srgrimes double propfraction; /* what % of time propagates */ 1341590Srgrimes double propself; /* how much self time propagates */ 1351590Srgrimes double propchild; /* how much child time propagates */ 1361590Srgrimes short printflag; /* should this be printed? */ 1371590Srgrimes short flags; /* see below */ 1381590Srgrimes int index; /* index in the graph list */ 1391590Srgrimes int toporder; /* graph call chain top-sort order */ 1401590Srgrimes int cycleno; /* internal number of cycle on */ 1411590Srgrimes int parentcnt; /* number of live parent arcs */ 1421590Srgrimes struct nl *cyclehead; /* pointer to head of cycle */ 1431590Srgrimes struct nl *cnext; /* pointer to next member of cycle */ 1441590Srgrimes arctype *parents; /* list of caller arcs */ 1451590Srgrimes arctype *children; /* list of callee arcs */ 1461590Srgrimes}; 1471590Srgrimestypedef struct nl nltype; 1481590Srgrimes 1491590Srgrimesnltype *nl; /* the whole namelist */ 1501590Srgrimesnltype *npe; /* the virtual end of the namelist */ 1511590Srgrimesint nname; /* the number of function names */ 1521590Srgrimes 1531590Srgrimes#define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 1541590Srgrimes#define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 1551590Srgrimes#define VISITED 0x20 /* node visited during a cycle */ 1561590Srgrimes 1571590Srgrimes /* 1581590Srgrimes * The cycle list. 1591590Srgrimes * for each subcycle within an identified cycle, we gather 1601590Srgrimes * its size and the list of included arcs. 1611590Srgrimes */ 1621590Srgrimesstruct cl { 1631590Srgrimes int size; /* length of cycle */ 1641590Srgrimes struct cl *next; /* next member of list */ 1651590Srgrimes arctype *list[1]; /* list of arcs in cycle */ 1661590Srgrimes /* actually longer */ 1671590Srgrimes}; 1681590Srgrimestypedef struct cl cltype; 1691590Srgrimes 1701590Srgrimesarctype *archead; /* the head of arcs in current cycle list */ 1711590Srgrimescltype *cyclehead; /* the head of the list */ 1721590Srgrimesint cyclecnt; /* the number of cycles found */ 1731590Srgrimes#define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 1741590Srgrimes 1751590Srgrimes /* 1761590Srgrimes * flag which marks a nl entry as topologically ``busy'' 1771590Srgrimes * flag which marks a nl entry as topologically ``not_numbered'' 1781590Srgrimes */ 1791590Srgrimes#define DFN_BUSY -1 1801590Srgrimes#define DFN_NAN 0 1811590Srgrimes 1821590Srgrimes /* 1831590Srgrimes * namelist entries for cycle headers. 1841590Srgrimes * the number of discovered cycles. 1851590Srgrimes */ 1861590Srgrimesnltype *cyclenl; /* cycle header namelist */ 1871590Srgrimesint ncycle; /* number of cycles discovered */ 1881590Srgrimes 1891590Srgrimes /* 1901590Srgrimes * The header on the gmon.out file. 1911590Srgrimes * gmon.out consists of a struct phdr (defined in gmon.h) 1921590Srgrimes * and then an array of ncnt samples representing the 1931590Srgrimes * discretized program counter values. 1941590Srgrimes * 1951590Srgrimes * Backward compatible old style header 1961590Srgrimes */ 1971590Srgrimesstruct ophdr { 1981590Srgrimes UNIT *lpc; 1991590Srgrimes UNIT *hpc; 2001590Srgrimes int ncnt; 2011590Srgrimes}; 2021590Srgrimes 2031590Srgrimesint debug; 2041590Srgrimes 2051590Srgrimes /* 2061590Srgrimes * Each discretized pc sample has 2071590Srgrimes * a count of the number of samples in its range 2081590Srgrimes */ 2091590SrgrimesUNIT *samples; 2101590Srgrimes 2111590Srgrimesunsigned long s_lowpc; /* lowpc from the profile file */ 2121590Srgrimesunsigned long s_highpc; /* highpc from the profile file */ 2131590Srgrimesunsigned lowpc, highpc; /* range profiled, in UNIT's */ 2141590Srgrimesunsigned sampbytes; /* number of bytes of samples */ 2151590Srgrimesint nsamples; /* number of samples */ 2161590Srgrimesdouble actime; /* accumulated time thus far for putprofline */ 2171590Srgrimesdouble totime; /* total time for all routines */ 2181590Srgrimesdouble printtime; /* total of time being printed */ 2191590Srgrimesdouble scale; /* scale factor converting samples to pc 2201590Srgrimes values: each sample covers scale bytes */ 2211590Srgrimeschar *strtab; /* string table in core */ 2221590Srgrimeslong ssiz; /* size of the string table */ 2231590Srgrimesstruct exec xbuf; /* exec header of a.out */ 2241590Srgrimesunsigned char *textspace; /* text space of a.out in core */ 2251590Srgrimesint cyclethreshold; /* with -C, minimum cycle size to ignore */ 2261590Srgrimes 2271590Srgrimes /* 2281590Srgrimes * option flags, from a to z. 2291590Srgrimes */ 2301590Srgrimesbool aflag; /* suppress static functions */ 2311590Srgrimesbool bflag; /* blurbs, too */ 2321590Srgrimesbool cflag; /* discovered call graph, too */ 2331590Srgrimesbool Cflag; /* find cut-set to eliminate cycles */ 2341590Srgrimesbool dflag; /* debugging options */ 2351590Srgrimesbool eflag; /* specific functions excluded */ 2361590Srgrimesbool Eflag; /* functions excluded with time */ 2371590Srgrimesbool fflag; /* specific functions requested */ 2381590Srgrimesbool Fflag; /* functions requested with time */ 2391590Srgrimesbool kflag; /* arcs to be deleted */ 2401590Srgrimesbool sflag; /* sum multiple gmon.out files */ 2411590Srgrimesbool zflag; /* zero time/called functions, too */ 2421590Srgrimes 2431590Srgrimes /* 2441590Srgrimes * structure for various string lists 2451590Srgrimes */ 2461590Srgrimesstruct stringlist { 2471590Srgrimes struct stringlist *next; 2481590Srgrimes char *string; 2491590Srgrimes}; 2501590Srgrimesstruct stringlist *elist; 2511590Srgrimesstruct stringlist *Elist; 2521590Srgrimesstruct stringlist *flist; 2531590Srgrimesstruct stringlist *Flist; 2541590Srgrimesstruct stringlist *kfromlist; 2551590Srgrimesstruct stringlist *ktolist; 2561590Srgrimes 2571590Srgrimes /* 2581590Srgrimes * function declarations 2591590Srgrimes */ 2601590Srgrimes/* 2611590Srgrimes addarc(); 2621590Srgrimes*/ 2631590Srgrimesint arccmp(); 2641590Srgrimesarctype *arclookup(); 2651590Srgrimes/* 2661590Srgrimes asgnsamples(); 2671590Srgrimes printblurb(); 2681590Srgrimes cyclelink(); 2691590Srgrimes dfn(); 2701590Srgrimes*/ 2711590Srgrimesbool dfn_busy(); 2721590Srgrimes/* 2731590Srgrimes dfn_findcycle(); 2741590Srgrimes*/ 2751590Srgrimesbool dfn_numbered(); 2761590Srgrimes/* 2771590Srgrimes dfn_post_visit(); 2781590Srgrimes dfn_pre_visit(); 2791590Srgrimes dfn_self_cycle(); 2801590Srgrimes*/ 2811590Srgrimesnltype **doarcs(); 2821590Srgrimes/* 2831590Srgrimes done(); 2841590Srgrimes findcalls(); 2851590Srgrimes flatprofheader(); 2861590Srgrimes flatprofline(); 2871590Srgrimes*/ 2881590Srgrimesbool funcsymbol(); 2891590Srgrimes/* 2901590Srgrimes getnfile(); 2911590Srgrimes getpfile(); 2921590Srgrimes getstrtab(); 2931590Srgrimes getsymtab(); 2941590Srgrimes gettextspace(); 2951590Srgrimes gprofheader(); 2961590Srgrimes gprofline(); 2971590Srgrimes main(); 2981590Srgrimes*/ 2991590Srgrimesunsigned long max(); 3001590Srgrimesint membercmp(); 3011590Srgrimesunsigned long min(); 3021590Srgrimesnltype *nllookup(); 3031590SrgrimesFILE *openpfile(); 3041590Srgrimeslong operandlength(); 3051590Srgrimesoperandenum operandmode(); 3061590Srgrimeschar *operandname(); 3071590Srgrimes/* 3081590Srgrimes printchildren(); 3091590Srgrimes printcycle(); 3101590Srgrimes printgprof(); 3111590Srgrimes printmembers(); 3121590Srgrimes printname(); 3131590Srgrimes printparents(); 3141590Srgrimes printprof(); 3151590Srgrimes readsamples(); 3161590Srgrimes*/ 3171590Srgrimesunsigned long reladdr(); 3181590Srgrimes/* 3191590Srgrimes sortchildren(); 3201590Srgrimes sortmembers(); 3211590Srgrimes sortparents(); 3221590Srgrimes tally(); 3231590Srgrimes timecmp(); 3241590Srgrimes topcmp(); 3251590Srgrimes*/ 3261590Srgrimesint totalcmp(); 3271590Srgrimes/* 3281590Srgrimes valcmp(); 3291590Srgrimes*/ 3301590Srgrimes 3311590Srgrimes#define LESSTHAN -1 3321590Srgrimes#define EQUALTO 0 3331590Srgrimes#define GREATERTHAN 1 3341590Srgrimes 3351590Srgrimes#define DFNDEBUG 1 3361590Srgrimes#define CYCLEDEBUG 2 3371590Srgrimes#define ARCDEBUG 4 3381590Srgrimes#define TALLYDEBUG 8 3391590Srgrimes#define TIMEDEBUG 16 3401590Srgrimes#define SAMPLEDEBUG 32 3411590Srgrimes#define AOUTDEBUG 64 3421590Srgrimes#define CALLDEBUG 128 3431590Srgrimes#define LOOKUPDEBUG 256 3441590Srgrimes#define PROPDEBUG 512 3451590Srgrimes#define BREAKCYCLE 1024 3461590Srgrimes#define SUBCYCLELIST 2048 3471590Srgrimes#define ANYDEBUG 4096 348