121965Sdist /* 221965Sdist * Copyright (c) 1983 Regents of the University of California. 334199Sbostic * All rights reserved. 421965Sdist * 542683Sbostic * %sccs.include.redist.c% 634199Sbostic * 7*56172Sbostic * @(#)gprof.h 5.14 (Berkeley) 09/02/92 821965Sdist */ 94511Speter 104511Speter #include <sys/types.h> 114511Speter #include <sys/stat.h> 1254804Storek #include <sys/gmon.h> 1354804Storek 144511Speter #include <a.out.h> 1540604Sbostic #include <stdio.h> 1654804Storek #include <stdlib.h> 174511Speter 1811799Speter #if vax 1911799Speter # include "vax.h" 2011799Speter #endif 2154804Storek #if sparc 2254804Storek # include "sparc.h" 2311799Speter #endif 2425709Ssam #if tahoe 2525709Ssam # include "tahoe.h" 2625709Ssam #endif 2748699Sdonn #if hp300 2848699Sdonn # include "hp300.h" 2948699Sdonn #endif 30*56172Sbostic #if luna68k 31*56172Sbostic # include "luna68k.h" 32*56172Sbostic #endif 3348699Sdonn #if i386 3448699Sdonn # include "i386.h" 3548699Sdonn #endif 3611799Speter 3711799Speter 384511Speter /* 397129Speter * who am i, for error messages. 407129Speter */ 417129Speter char *whoami; 427129Speter 437129Speter /* 447174Speter * booleans 457174Speter */ 467174Speter typedef int bool; 477174Speter #define FALSE 0 487174Speter #define TRUE 1 497174Speter 507174Speter /* 514511Speter * ticks per second 524511Speter */ 5310250Speter long hz; 544511Speter 5533225Sbostic typedef u_short UNIT; /* unit of profiling */ 564511Speter char *a_outname; 574511Speter #define A_OUTNAME "a.out" 584511Speter 594560Speter char *gmonname; 604560Speter #define GMONNAME "gmon.out" 614867Smckusic #define GMONSUM "gmon.sum" 6233225Sbostic 634873Smckusic /* 644511Speter * a constructed arc, 654511Speter * with pointers to the namelist entry of the parent and the child, 664511Speter * a count of how many times this arc was traversed, 674511Speter * and pointers to the next parent of this child and 684511Speter * the next child of this parent. 694511Speter */ 704511Speter struct arcstruct { 714511Speter struct nl *arc_parentp; /* pointer to parent's nl entry */ 724511Speter struct nl *arc_childp; /* pointer to child's nl entry */ 7352648Smckusick long arc_count; /* num calls from parent to child */ 744511Speter double arc_time; /* time inherited along arc */ 754511Speter double arc_childtime; /* childtime inherited along arc */ 764511Speter struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 774511Speter struct arcstruct *arc_childlist; /* children-of-this-parent list */ 7852648Smckusick struct arcstruct *arc_next; /* list of arcs on cycle */ 7952648Smckusick unsigned short arc_cyclecnt; /* num cycles involved in */ 8052648Smckusick unsigned short arc_flags; /* see below */ 814511Speter }; 824511Speter typedef struct arcstruct arctype; 834511Speter 847129Speter /* 8552648Smckusick * arc flags 8652648Smckusick */ 8752648Smckusick #define DEADARC 0x01 /* time should not propagate across the arc */ 8852648Smckusick #define ONLIST 0x02 /* arc is on list of arcs in cycles */ 8952648Smckusick 9052648Smckusick /* 917129Speter * The symbol table; 927129Speter * for each external in the specified file we gather 937129Speter * its address, the number of calls and compute its share of cpu time. 947129Speter */ 954511Speter struct nl { 967129Speter char *name; /* the name */ 977129Speter unsigned long value; /* the pc entry point */ 9811799Speter unsigned long svalue; /* entry point aligned to histograms */ 997129Speter double time; /* ticks in this routine */ 1007129Speter double childtime; /* cumulative ticks in children */ 1017129Speter long ncall; /* how many times called */ 10252648Smckusick long npropcall; /* times called by live arcs */ 1037129Speter long selfcalls; /* how many calls to self */ 1047224Speter double propfraction; /* what % of time propagates */ 1057224Speter double propself; /* how much self time propagates */ 1067224Speter double propchild; /* how much child time propagates */ 10752648Smckusick short printflag; /* should this be printed? */ 10852648Smckusick short flags; /* see below */ 1097129Speter int index; /* index in the graph list */ 1107129Speter int toporder; /* graph call chain top-sort order */ 1117129Speter int cycleno; /* internal number of cycle on */ 11252648Smckusick int parentcnt; /* number of live parent arcs */ 1137129Speter struct nl *cyclehead; /* pointer to head of cycle */ 1147129Speter struct nl *cnext; /* pointer to next member of cycle */ 1157129Speter arctype *parents; /* list of caller arcs */ 1167129Speter arctype *children; /* list of callee arcs */ 1174511Speter }; 1184511Speter typedef struct nl nltype; 1194511Speter 1204511Speter nltype *nl; /* the whole namelist */ 1214511Speter nltype *npe; /* the virtual end of the namelist */ 1227129Speter int nname; /* the number of function names */ 1234511Speter 12452648Smckusick #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 12552648Smckusick #define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 12652648Smckusick #define VISITED 0x20 /* node visited during a cycle */ 12752648Smckusick 1284511Speter /* 12952648Smckusick * The cycle list. 13052648Smckusick * for each subcycle within an identified cycle, we gather 13152648Smckusick * its size and the list of included arcs. 13252648Smckusick */ 13352648Smckusick struct cl { 13452648Smckusick int size; /* length of cycle */ 13552648Smckusick struct cl *next; /* next member of list */ 13652648Smckusick arctype *list[1]; /* list of arcs in cycle */ 13752648Smckusick /* actually longer */ 13852648Smckusick }; 13952648Smckusick typedef struct cl cltype; 14052648Smckusick 14152648Smckusick arctype *archead; /* the head of arcs in current cycle list */ 14252648Smckusick cltype *cyclehead; /* the head of the list */ 14352648Smckusick int cyclecnt; /* the number of cycles found */ 14452648Smckusick #define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 14552648Smckusick 14652648Smckusick /* 1474511Speter * flag which marks a nl entry as topologically ``busy'' 14810284Speter * flag which marks a nl entry as topologically ``not_numbered'' 1494511Speter */ 1504511Speter #define DFN_BUSY -1 15110284Speter #define DFN_NAN 0 1524511Speter 1534511Speter /* 1547129Speter * namelist entries for cycle headers. 1557129Speter * the number of discovered cycles. 1564511Speter */ 1577129Speter nltype *cyclenl; /* cycle header namelist */ 1587129Speter int ncycle; /* number of cycles discovered */ 1594511Speter 1607129Speter /* 1617129Speter * The header on the gmon.out file. 16252811Smckusick * gmon.out consists of a struct phdr (defined in gmon.h) 16352811Smckusick * and then an array of ncnt samples representing the 16452811Smckusick * discretized program counter values. 16552811Smckusick * 16652811Smckusick * Backward compatible old style header 1677129Speter */ 16852811Smckusick struct ophdr { 16952811Smckusick UNIT *lpc; 17052811Smckusick UNIT *hpc; 17152811Smckusick int ncnt; 1724511Speter }; 1734511Speter 1744511Speter int debug; 1754511Speter 1767129Speter /* 1777129Speter * Each discretized pc sample has 1787129Speter * a count of the number of samples in its range 1797129Speter */ 18033225Sbostic UNIT *samples; 1814511Speter 1824751Speter unsigned long s_lowpc; /* lowpc from the profile file */ 1834751Speter unsigned long s_highpc; /* highpc from the profile file */ 1844751Speter unsigned lowpc, highpc; /* range profiled, in UNIT's */ 1854511Speter unsigned sampbytes; /* number of bytes of samples */ 1864511Speter int nsamples; /* number of samples */ 1874511Speter double actime; /* accumulated time thus far for putprofline */ 1884511Speter double totime; /* total time for all routines */ 1897174Speter double printtime; /* total of time being printed */ 1904511Speter double scale; /* scale factor converting samples to pc 1914511Speter values: each sample covers scale bytes */ 1924511Speter char *strtab; /* string table in core */ 19354804Storek long ssiz; /* size of the string table */ 1944511Speter struct exec xbuf; /* exec header of a.out */ 19552648Smckusick unsigned char *textspace; /* text space of a.out in core */ 19652648Smckusick int cyclethreshold; /* with -C, minimum cycle size to ignore */ 1974511Speter 1984855Speter /* 1994855Speter * option flags, from a to z. 2004855Speter */ 2017174Speter bool aflag; /* suppress static functions */ 2027174Speter bool bflag; /* blurbs, too */ 2037174Speter bool cflag; /* discovered call graph, too */ 20452648Smckusick bool Cflag; /* find cut-set to eliminate cycles */ 2057174Speter bool dflag; /* debugging options */ 2067174Speter bool eflag; /* specific functions excluded */ 2077224Speter bool Eflag; /* functions excluded with time */ 2087174Speter bool fflag; /* specific functions requested */ 2097224Speter bool Fflag; /* functions requested with time */ 21030963Smckusick bool kflag; /* arcs to be deleted */ 2117174Speter bool sflag; /* sum multiple gmon.out files */ 2127174Speter bool zflag; /* zero time/called functions, too */ 2134511Speter 2144511Speter /* 2157224Speter * structure for various string lists 2167224Speter */ 2177224Speter struct stringlist { 2187224Speter struct stringlist *next; 2197224Speter char *string; 2207224Speter }; 2217224Speter struct stringlist *elist; 2227224Speter struct stringlist *Elist; 2237224Speter struct stringlist *flist; 2247224Speter struct stringlist *Flist; 22530963Smckusick struct stringlist *kfromlist; 22630963Smckusick struct stringlist *ktolist; 2277224Speter 2287224Speter /* 2294840Speter * function declarations 2304840Speter */ 23133225Sbostic /* 2324840Speter addarc(); 23333225Sbostic */ 2344840Speter int arccmp(); 2354511Speter arctype *arclookup(); 23633225Sbostic /* 2374840Speter asgnsamples(); 2384855Speter printblurb(); 2394840Speter cyclelink(); 2404840Speter dfn(); 24133225Sbostic */ 2424511Speter bool dfn_busy(); 24333225Sbostic /* 2444840Speter dfn_findcycle(); 24533225Sbostic */ 2464840Speter bool dfn_numbered(); 24733225Sbostic /* 2484840Speter dfn_post_visit(); 2494840Speter dfn_pre_visit(); 2504840Speter dfn_self_cycle(); 25133225Sbostic */ 25216851Smckusick nltype **doarcs(); 25333225Sbostic /* 2544840Speter done(); 2554840Speter findcalls(); 2564840Speter flatprofheader(); 2574840Speter flatprofline(); 25833225Sbostic */ 2594844Speter bool funcsymbol(); 26033225Sbostic /* 2614840Speter getnfile(); 2624840Speter getpfile(); 2634840Speter getstrtab(); 2644840Speter getsymtab(); 2654840Speter gettextspace(); 2664840Speter gprofheader(); 2674840Speter gprofline(); 2684840Speter main(); 26933225Sbostic */ 2704840Speter unsigned long max(); 2714840Speter int membercmp(); 2724840Speter unsigned long min(); 2734840Speter nltype *nllookup(); 2744840Speter FILE *openpfile(); 2754840Speter long operandlength(); 2764840Speter operandenum operandmode(); 2774840Speter char *operandname(); 27833225Sbostic /* 2794840Speter printchildren(); 2804840Speter printcycle(); 2814840Speter printgprof(); 2824840Speter printmembers(); 2834840Speter printname(); 2844840Speter printparents(); 2854840Speter printprof(); 2864840Speter readsamples(); 28733225Sbostic */ 2884840Speter unsigned long reladdr(); 28933225Sbostic /* 2904840Speter sortchildren(); 2914840Speter sortmembers(); 2924840Speter sortparents(); 2934840Speter tally(); 2944840Speter timecmp(); 2954840Speter topcmp(); 29633225Sbostic */ 2974840Speter int totalcmp(); 29833225Sbostic /* 2994840Speter valcmp(); 30033225Sbostic */ 3014511Speter 3024511Speter #define LESSTHAN -1 3034511Speter #define EQUALTO 0 3044511Speter #define GREATERTHAN 1 3054511Speter 3064511Speter #define DFNDEBUG 1 3074511Speter #define CYCLEDEBUG 2 3084511Speter #define ARCDEBUG 4 3094511Speter #define TALLYDEBUG 8 3104511Speter #define TIMEDEBUG 16 3114511Speter #define SAMPLEDEBUG 32 3124511Speter #define AOUTDEBUG 64 31325709Ssam #define CALLDEBUG 128 3144722Speter #define LOOKUPDEBUG 256 3157224Speter #define PROPDEBUG 512 31652648Smckusick #define BREAKCYCLE 1024 31752648Smckusick #define SUBCYCLELIST 2048 31852648Smckusick #define ANYDEBUG 4096 319