121965Sdist /* 221965Sdist * Copyright (c) 1983 Regents of the University of California. 334199Sbostic * All rights reserved. 421965Sdist * 542683Sbostic * %sccs.include.redist.c% 634199Sbostic * 7*54804Storek * @(#)gprof.h 5.13 (Berkeley) 07/08/92 821965Sdist */ 94511Speter 104511Speter #include <sys/types.h> 114511Speter #include <sys/stat.h> 12*54804Storek #include <sys/gmon.h> 13*54804Storek 144511Speter #include <a.out.h> 1540604Sbostic #include <stdio.h> 16*54804Storek #include <stdlib.h> 174511Speter 1811799Speter #if vax 1911799Speter # include "vax.h" 2011799Speter #endif 21*54804Storek #if sparc 22*54804Storek # include "sparc.h" 2311799Speter #endif 2425709Ssam #if tahoe 2525709Ssam # include "tahoe.h" 2625709Ssam #endif 2748699Sdonn #if hp300 2848699Sdonn # include "hp300.h" 2948699Sdonn #endif 3048699Sdonn #if i386 3148699Sdonn # include "i386.h" 3248699Sdonn #endif 3311799Speter 3411799Speter 354511Speter /* 367129Speter * who am i, for error messages. 377129Speter */ 387129Speter char *whoami; 397129Speter 407129Speter /* 417174Speter * booleans 427174Speter */ 437174Speter typedef int bool; 447174Speter #define FALSE 0 457174Speter #define TRUE 1 467174Speter 477174Speter /* 484511Speter * ticks per second 494511Speter */ 5010250Speter long hz; 514511Speter 5233225Sbostic typedef u_short UNIT; /* unit of profiling */ 534511Speter char *a_outname; 544511Speter #define A_OUTNAME "a.out" 554511Speter 564560Speter char *gmonname; 574560Speter #define GMONNAME "gmon.out" 584867Smckusic #define GMONSUM "gmon.sum" 5933225Sbostic 604873Smckusic /* 614511Speter * a constructed arc, 624511Speter * with pointers to the namelist entry of the parent and the child, 634511Speter * a count of how many times this arc was traversed, 644511Speter * and pointers to the next parent of this child and 654511Speter * the next child of this parent. 664511Speter */ 674511Speter struct arcstruct { 684511Speter struct nl *arc_parentp; /* pointer to parent's nl entry */ 694511Speter struct nl *arc_childp; /* pointer to child's nl entry */ 7052648Smckusick long arc_count; /* num calls from parent to child */ 714511Speter double arc_time; /* time inherited along arc */ 724511Speter double arc_childtime; /* childtime inherited along arc */ 734511Speter struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 744511Speter struct arcstruct *arc_childlist; /* children-of-this-parent list */ 7552648Smckusick struct arcstruct *arc_next; /* list of arcs on cycle */ 7652648Smckusick unsigned short arc_cyclecnt; /* num cycles involved in */ 7752648Smckusick unsigned short arc_flags; /* see below */ 784511Speter }; 794511Speter typedef struct arcstruct arctype; 804511Speter 817129Speter /* 8252648Smckusick * arc flags 8352648Smckusick */ 8452648Smckusick #define DEADARC 0x01 /* time should not propagate across the arc */ 8552648Smckusick #define ONLIST 0x02 /* arc is on list of arcs in cycles */ 8652648Smckusick 8752648Smckusick /* 887129Speter * The symbol table; 897129Speter * for each external in the specified file we gather 907129Speter * its address, the number of calls and compute its share of cpu time. 917129Speter */ 924511Speter struct nl { 937129Speter char *name; /* the name */ 947129Speter unsigned long value; /* the pc entry point */ 9511799Speter unsigned long svalue; /* entry point aligned to histograms */ 967129Speter double time; /* ticks in this routine */ 977129Speter double childtime; /* cumulative ticks in children */ 987129Speter long ncall; /* how many times called */ 9952648Smckusick long npropcall; /* times called by live arcs */ 1007129Speter long selfcalls; /* how many calls to self */ 1017224Speter double propfraction; /* what % of time propagates */ 1027224Speter double propself; /* how much self time propagates */ 1037224Speter double propchild; /* how much child time propagates */ 10452648Smckusick short printflag; /* should this be printed? */ 10552648Smckusick short flags; /* see below */ 1067129Speter int index; /* index in the graph list */ 1077129Speter int toporder; /* graph call chain top-sort order */ 1087129Speter int cycleno; /* internal number of cycle on */ 10952648Smckusick int parentcnt; /* number of live parent arcs */ 1107129Speter struct nl *cyclehead; /* pointer to head of cycle */ 1117129Speter struct nl *cnext; /* pointer to next member of cycle */ 1127129Speter arctype *parents; /* list of caller arcs */ 1137129Speter arctype *children; /* list of callee arcs */ 1144511Speter }; 1154511Speter typedef struct nl nltype; 1164511Speter 1174511Speter nltype *nl; /* the whole namelist */ 1184511Speter nltype *npe; /* the virtual end of the namelist */ 1197129Speter int nname; /* the number of function names */ 1204511Speter 12152648Smckusick #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 12252648Smckusick #define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 12352648Smckusick #define VISITED 0x20 /* node visited during a cycle */ 12452648Smckusick 1254511Speter /* 12652648Smckusick * The cycle list. 12752648Smckusick * for each subcycle within an identified cycle, we gather 12852648Smckusick * its size and the list of included arcs. 12952648Smckusick */ 13052648Smckusick struct cl { 13152648Smckusick int size; /* length of cycle */ 13252648Smckusick struct cl *next; /* next member of list */ 13352648Smckusick arctype *list[1]; /* list of arcs in cycle */ 13452648Smckusick /* actually longer */ 13552648Smckusick }; 13652648Smckusick typedef struct cl cltype; 13752648Smckusick 13852648Smckusick arctype *archead; /* the head of arcs in current cycle list */ 13952648Smckusick cltype *cyclehead; /* the head of the list */ 14052648Smckusick int cyclecnt; /* the number of cycles found */ 14152648Smckusick #define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 14252648Smckusick 14352648Smckusick /* 1444511Speter * flag which marks a nl entry as topologically ``busy'' 14510284Speter * flag which marks a nl entry as topologically ``not_numbered'' 1464511Speter */ 1474511Speter #define DFN_BUSY -1 14810284Speter #define DFN_NAN 0 1494511Speter 1504511Speter /* 1517129Speter * namelist entries for cycle headers. 1527129Speter * the number of discovered cycles. 1534511Speter */ 1547129Speter nltype *cyclenl; /* cycle header namelist */ 1557129Speter int ncycle; /* number of cycles discovered */ 1564511Speter 1577129Speter /* 1587129Speter * The header on the gmon.out file. 15952811Smckusick * gmon.out consists of a struct phdr (defined in gmon.h) 16052811Smckusick * and then an array of ncnt samples representing the 16152811Smckusick * discretized program counter values. 16252811Smckusick * 16352811Smckusick * Backward compatible old style header 1647129Speter */ 16552811Smckusick struct ophdr { 16652811Smckusick UNIT *lpc; 16752811Smckusick UNIT *hpc; 16852811Smckusick int ncnt; 1694511Speter }; 1704511Speter 1714511Speter int debug; 1724511Speter 1737129Speter /* 1747129Speter * Each discretized pc sample has 1757129Speter * a count of the number of samples in its range 1767129Speter */ 17733225Sbostic UNIT *samples; 1784511Speter 1794751Speter unsigned long s_lowpc; /* lowpc from the profile file */ 1804751Speter unsigned long s_highpc; /* highpc from the profile file */ 1814751Speter unsigned lowpc, highpc; /* range profiled, in UNIT's */ 1824511Speter unsigned sampbytes; /* number of bytes of samples */ 1834511Speter int nsamples; /* number of samples */ 1844511Speter double actime; /* accumulated time thus far for putprofline */ 1854511Speter double totime; /* total time for all routines */ 1867174Speter double printtime; /* total of time being printed */ 1874511Speter double scale; /* scale factor converting samples to pc 1884511Speter values: each sample covers scale bytes */ 1894511Speter char *strtab; /* string table in core */ 190*54804Storek long ssiz; /* size of the string table */ 1914511Speter struct exec xbuf; /* exec header of a.out */ 19252648Smckusick unsigned char *textspace; /* text space of a.out in core */ 19352648Smckusick int cyclethreshold; /* with -C, minimum cycle size to ignore */ 1944511Speter 1954855Speter /* 1964855Speter * option flags, from a to z. 1974855Speter */ 1987174Speter bool aflag; /* suppress static functions */ 1997174Speter bool bflag; /* blurbs, too */ 2007174Speter bool cflag; /* discovered call graph, too */ 20152648Smckusick bool Cflag; /* find cut-set to eliminate cycles */ 2027174Speter bool dflag; /* debugging options */ 2037174Speter bool eflag; /* specific functions excluded */ 2047224Speter bool Eflag; /* functions excluded with time */ 2057174Speter bool fflag; /* specific functions requested */ 2067224Speter bool Fflag; /* functions requested with time */ 20730963Smckusick bool kflag; /* arcs to be deleted */ 2087174Speter bool sflag; /* sum multiple gmon.out files */ 2097174Speter bool zflag; /* zero time/called functions, too */ 2104511Speter 2114511Speter /* 2127224Speter * structure for various string lists 2137224Speter */ 2147224Speter struct stringlist { 2157224Speter struct stringlist *next; 2167224Speter char *string; 2177224Speter }; 2187224Speter struct stringlist *elist; 2197224Speter struct stringlist *Elist; 2207224Speter struct stringlist *flist; 2217224Speter struct stringlist *Flist; 22230963Smckusick struct stringlist *kfromlist; 22330963Smckusick struct stringlist *ktolist; 2247224Speter 2257224Speter /* 2264840Speter * function declarations 2274840Speter */ 22833225Sbostic /* 2294840Speter addarc(); 23033225Sbostic */ 2314840Speter int arccmp(); 2324511Speter arctype *arclookup(); 23333225Sbostic /* 2344840Speter asgnsamples(); 2354855Speter printblurb(); 2364840Speter cyclelink(); 2374840Speter dfn(); 23833225Sbostic */ 2394511Speter bool dfn_busy(); 24033225Sbostic /* 2414840Speter dfn_findcycle(); 24233225Sbostic */ 2434840Speter bool dfn_numbered(); 24433225Sbostic /* 2454840Speter dfn_post_visit(); 2464840Speter dfn_pre_visit(); 2474840Speter dfn_self_cycle(); 24833225Sbostic */ 24916851Smckusick nltype **doarcs(); 25033225Sbostic /* 2514840Speter done(); 2524840Speter findcalls(); 2534840Speter flatprofheader(); 2544840Speter flatprofline(); 25533225Sbostic */ 2564844Speter bool funcsymbol(); 25733225Sbostic /* 2584840Speter getnfile(); 2594840Speter getpfile(); 2604840Speter getstrtab(); 2614840Speter getsymtab(); 2624840Speter gettextspace(); 2634840Speter gprofheader(); 2644840Speter gprofline(); 2654840Speter main(); 26633225Sbostic */ 2674840Speter unsigned long max(); 2684840Speter int membercmp(); 2694840Speter unsigned long min(); 2704840Speter nltype *nllookup(); 2714840Speter FILE *openpfile(); 2724840Speter long operandlength(); 2734840Speter operandenum operandmode(); 2744840Speter char *operandname(); 27533225Sbostic /* 2764840Speter printchildren(); 2774840Speter printcycle(); 2784840Speter printgprof(); 2794840Speter printmembers(); 2804840Speter printname(); 2814840Speter printparents(); 2824840Speter printprof(); 2834840Speter readsamples(); 28433225Sbostic */ 2854840Speter unsigned long reladdr(); 28633225Sbostic /* 2874840Speter sortchildren(); 2884840Speter sortmembers(); 2894840Speter sortparents(); 2904840Speter tally(); 2914840Speter timecmp(); 2924840Speter topcmp(); 29333225Sbostic */ 2944840Speter int totalcmp(); 29533225Sbostic /* 2964840Speter valcmp(); 29733225Sbostic */ 2984511Speter 2994511Speter #define LESSTHAN -1 3004511Speter #define EQUALTO 0 3014511Speter #define GREATERTHAN 1 3024511Speter 3034511Speter #define DFNDEBUG 1 3044511Speter #define CYCLEDEBUG 2 3054511Speter #define ARCDEBUG 4 3064511Speter #define TALLYDEBUG 8 3074511Speter #define TIMEDEBUG 16 3084511Speter #define SAMPLEDEBUG 32 3094511Speter #define AOUTDEBUG 64 31025709Ssam #define CALLDEBUG 128 3114722Speter #define LOOKUPDEBUG 256 3127224Speter #define PROPDEBUG 512 31352648Smckusick #define BREAKCYCLE 1024 31452648Smckusick #define SUBCYCLELIST 2048 31552648Smckusick #define ANYDEBUG 4096 316