121965Sdist /* 221965Sdist * Copyright (c) 1983 Regents of the University of California. 334199Sbostic * All rights reserved. 421965Sdist * 542683Sbostic * %sccs.include.redist.c% 634199Sbostic * 7*52811Smckusick * @(#)gprof.h 5.12 (Berkeley) 03/02/92 821965Sdist */ 94511Speter 104511Speter #include <sys/types.h> 114511Speter #include <sys/stat.h> 124511Speter #include <a.out.h> 1340604Sbostic #include <stdio.h> 1440604Sbostic #include "gmon.h" 154511Speter 1611799Speter #if vax 1711799Speter # include "vax.h" 1811799Speter #endif 1911799Speter #if sun 2025709Ssam # include "sun.h" 2111799Speter #endif 2225709Ssam #if tahoe 2325709Ssam # include "tahoe.h" 2425709Ssam #endif 2548699Sdonn #if hp300 2648699Sdonn # include "hp300.h" 2748699Sdonn #endif 2848699Sdonn #if i386 2948699Sdonn # include "i386.h" 3048699Sdonn #endif 3111799Speter 3211799Speter 334511Speter /* 347129Speter * who am i, for error messages. 357129Speter */ 367129Speter char *whoami; 377129Speter 387129Speter /* 397174Speter * booleans 407174Speter */ 417174Speter typedef int bool; 427174Speter #define FALSE 0 437174Speter #define TRUE 1 447174Speter 457174Speter /* 464511Speter * ticks per second 474511Speter */ 4810250Speter long hz; 494511Speter 5033225Sbostic typedef u_short UNIT; /* unit of profiling */ 514511Speter char *a_outname; 524511Speter #define A_OUTNAME "a.out" 534511Speter 544560Speter char *gmonname; 554560Speter #define GMONNAME "gmon.out" 564867Smckusic #define GMONSUM "gmon.sum" 5733225Sbostic 584873Smckusic /* 594511Speter * a constructed arc, 604511Speter * with pointers to the namelist entry of the parent and the child, 614511Speter * a count of how many times this arc was traversed, 624511Speter * and pointers to the next parent of this child and 634511Speter * the next child of this parent. 644511Speter */ 654511Speter struct arcstruct { 664511Speter struct nl *arc_parentp; /* pointer to parent's nl entry */ 674511Speter struct nl *arc_childp; /* pointer to child's nl entry */ 6852648Smckusick long arc_count; /* num calls from parent to child */ 694511Speter double arc_time; /* time inherited along arc */ 704511Speter double arc_childtime; /* childtime inherited along arc */ 714511Speter struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 724511Speter struct arcstruct *arc_childlist; /* children-of-this-parent list */ 7352648Smckusick struct arcstruct *arc_next; /* list of arcs on cycle */ 7452648Smckusick unsigned short arc_cyclecnt; /* num cycles involved in */ 7552648Smckusick unsigned short arc_flags; /* see below */ 764511Speter }; 774511Speter typedef struct arcstruct arctype; 784511Speter 797129Speter /* 8052648Smckusick * arc flags 8152648Smckusick */ 8252648Smckusick #define DEADARC 0x01 /* time should not propagate across the arc */ 8352648Smckusick #define ONLIST 0x02 /* arc is on list of arcs in cycles */ 8452648Smckusick 8552648Smckusick /* 867129Speter * The symbol table; 877129Speter * for each external in the specified file we gather 887129Speter * its address, the number of calls and compute its share of cpu time. 897129Speter */ 904511Speter struct nl { 917129Speter char *name; /* the name */ 927129Speter unsigned long value; /* the pc entry point */ 9311799Speter unsigned long svalue; /* entry point aligned to histograms */ 947129Speter double time; /* ticks in this routine */ 957129Speter double childtime; /* cumulative ticks in children */ 967129Speter long ncall; /* how many times called */ 9752648Smckusick long npropcall; /* times called by live arcs */ 987129Speter long selfcalls; /* how many calls to self */ 997224Speter double propfraction; /* what % of time propagates */ 1007224Speter double propself; /* how much self time propagates */ 1017224Speter double propchild; /* how much child time propagates */ 10252648Smckusick short printflag; /* should this be printed? */ 10352648Smckusick short flags; /* see below */ 1047129Speter int index; /* index in the graph list */ 1057129Speter int toporder; /* graph call chain top-sort order */ 1067129Speter int cycleno; /* internal number of cycle on */ 10752648Smckusick int parentcnt; /* number of live parent arcs */ 1087129Speter struct nl *cyclehead; /* pointer to head of cycle */ 1097129Speter struct nl *cnext; /* pointer to next member of cycle */ 1107129Speter arctype *parents; /* list of caller arcs */ 1117129Speter arctype *children; /* list of callee arcs */ 1124511Speter }; 1134511Speter typedef struct nl nltype; 1144511Speter 1154511Speter nltype *nl; /* the whole namelist */ 1164511Speter nltype *npe; /* the virtual end of the namelist */ 1177129Speter int nname; /* the number of function names */ 1184511Speter 11952648Smckusick #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 12052648Smckusick #define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 12152648Smckusick #define VISITED 0x20 /* node visited during a cycle */ 12252648Smckusick 1234511Speter /* 12452648Smckusick * The cycle list. 12552648Smckusick * for each subcycle within an identified cycle, we gather 12652648Smckusick * its size and the list of included arcs. 12752648Smckusick */ 12852648Smckusick struct cl { 12952648Smckusick int size; /* length of cycle */ 13052648Smckusick struct cl *next; /* next member of list */ 13152648Smckusick arctype *list[1]; /* list of arcs in cycle */ 13252648Smckusick /* actually longer */ 13352648Smckusick }; 13452648Smckusick typedef struct cl cltype; 13552648Smckusick 13652648Smckusick arctype *archead; /* the head of arcs in current cycle list */ 13752648Smckusick cltype *cyclehead; /* the head of the list */ 13852648Smckusick int cyclecnt; /* the number of cycles found */ 13952648Smckusick #define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 14052648Smckusick 14152648Smckusick /* 1424511Speter * flag which marks a nl entry as topologically ``busy'' 14310284Speter * flag which marks a nl entry as topologically ``not_numbered'' 1444511Speter */ 1454511Speter #define DFN_BUSY -1 14610284Speter #define DFN_NAN 0 1474511Speter 1484511Speter /* 1497129Speter * namelist entries for cycle headers. 1507129Speter * the number of discovered cycles. 1514511Speter */ 1527129Speter nltype *cyclenl; /* cycle header namelist */ 1537129Speter int ncycle; /* number of cycles discovered */ 1544511Speter 1557129Speter /* 1567129Speter * The header on the gmon.out file. 157*52811Smckusick * gmon.out consists of a struct phdr (defined in gmon.h) 158*52811Smckusick * and then an array of ncnt samples representing the 159*52811Smckusick * discretized program counter values. 160*52811Smckusick * 161*52811Smckusick * Backward compatible old style header 1627129Speter */ 163*52811Smckusick struct ophdr { 164*52811Smckusick UNIT *lpc; 165*52811Smckusick UNIT *hpc; 166*52811Smckusick int ncnt; 1674511Speter }; 1684511Speter 1694511Speter int debug; 1704511Speter 1717129Speter /* 1727129Speter * Each discretized pc sample has 1737129Speter * a count of the number of samples in its range 1747129Speter */ 17533225Sbostic UNIT *samples; 1764511Speter 1774751Speter unsigned long s_lowpc; /* lowpc from the profile file */ 1784751Speter unsigned long s_highpc; /* highpc from the profile file */ 1794751Speter unsigned lowpc, highpc; /* range profiled, in UNIT's */ 1804511Speter unsigned sampbytes; /* number of bytes of samples */ 1814511Speter int nsamples; /* number of samples */ 1824511Speter double actime; /* accumulated time thus far for putprofline */ 1834511Speter double totime; /* total time for all routines */ 1847174Speter double printtime; /* total of time being printed */ 1854511Speter double scale; /* scale factor converting samples to pc 1864511Speter values: each sample covers scale bytes */ 1874511Speter char *strtab; /* string table in core */ 1884511Speter off_t ssiz; /* size of the string table */ 1894511Speter struct exec xbuf; /* exec header of a.out */ 19052648Smckusick unsigned char *textspace; /* text space of a.out in core */ 19152648Smckusick int cyclethreshold; /* with -C, minimum cycle size to ignore */ 1924511Speter 1934855Speter /* 1944855Speter * option flags, from a to z. 1954855Speter */ 1967174Speter bool aflag; /* suppress static functions */ 1977174Speter bool bflag; /* blurbs, too */ 1987174Speter bool cflag; /* discovered call graph, too */ 19952648Smckusick bool Cflag; /* find cut-set to eliminate cycles */ 2007174Speter bool dflag; /* debugging options */ 2017174Speter bool eflag; /* specific functions excluded */ 2027224Speter bool Eflag; /* functions excluded with time */ 2037174Speter bool fflag; /* specific functions requested */ 2047224Speter bool Fflag; /* functions requested with time */ 20530963Smckusick bool kflag; /* arcs to be deleted */ 2067174Speter bool sflag; /* sum multiple gmon.out files */ 2077174Speter bool zflag; /* zero time/called functions, too */ 2084511Speter 2094511Speter /* 2107224Speter * structure for various string lists 2117224Speter */ 2127224Speter struct stringlist { 2137224Speter struct stringlist *next; 2147224Speter char *string; 2157224Speter }; 2167224Speter struct stringlist *elist; 2177224Speter struct stringlist *Elist; 2187224Speter struct stringlist *flist; 2197224Speter struct stringlist *Flist; 22030963Smckusick struct stringlist *kfromlist; 22130963Smckusick struct stringlist *ktolist; 2227224Speter 2237224Speter /* 2244840Speter * function declarations 2254840Speter */ 22633225Sbostic /* 2274840Speter addarc(); 22833225Sbostic */ 2294840Speter int arccmp(); 2304511Speter arctype *arclookup(); 23133225Sbostic /* 2324840Speter asgnsamples(); 2334855Speter printblurb(); 2344840Speter cyclelink(); 2354840Speter dfn(); 23633225Sbostic */ 2374511Speter bool dfn_busy(); 23833225Sbostic /* 2394840Speter dfn_findcycle(); 24033225Sbostic */ 2414840Speter bool dfn_numbered(); 24233225Sbostic /* 2434840Speter dfn_post_visit(); 2444840Speter dfn_pre_visit(); 2454840Speter dfn_self_cycle(); 24633225Sbostic */ 24716851Smckusick nltype **doarcs(); 24833225Sbostic /* 2494840Speter done(); 2504840Speter findcalls(); 2514840Speter flatprofheader(); 2524840Speter flatprofline(); 25333225Sbostic */ 2544844Speter bool funcsymbol(); 25533225Sbostic /* 2564840Speter getnfile(); 2574840Speter getpfile(); 2584840Speter getstrtab(); 2594840Speter getsymtab(); 2604840Speter gettextspace(); 2614840Speter gprofheader(); 2624840Speter gprofline(); 2634840Speter main(); 26433225Sbostic */ 2654840Speter unsigned long max(); 2664840Speter int membercmp(); 2674840Speter unsigned long min(); 2684840Speter nltype *nllookup(); 2694840Speter FILE *openpfile(); 2704840Speter long operandlength(); 2714840Speter operandenum operandmode(); 2724840Speter char *operandname(); 27333225Sbostic /* 2744840Speter printchildren(); 2754840Speter printcycle(); 2764840Speter printgprof(); 2774840Speter printmembers(); 2784840Speter printname(); 2794840Speter printparents(); 2804840Speter printprof(); 2814840Speter readsamples(); 28233225Sbostic */ 2834840Speter unsigned long reladdr(); 28433225Sbostic /* 2854840Speter sortchildren(); 2864840Speter sortmembers(); 2874840Speter sortparents(); 2884840Speter tally(); 2894840Speter timecmp(); 2904840Speter topcmp(); 29133225Sbostic */ 2924840Speter int totalcmp(); 29333225Sbostic /* 2944840Speter valcmp(); 29533225Sbostic */ 2964511Speter 2974511Speter #define LESSTHAN -1 2984511Speter #define EQUALTO 0 2994511Speter #define GREATERTHAN 1 3004511Speter 3014511Speter #define DFNDEBUG 1 3024511Speter #define CYCLEDEBUG 2 3034511Speter #define ARCDEBUG 4 3044511Speter #define TALLYDEBUG 8 3054511Speter #define TIMEDEBUG 16 3064511Speter #define SAMPLEDEBUG 32 3074511Speter #define AOUTDEBUG 64 30825709Ssam #define CALLDEBUG 128 3094722Speter #define LOOKUPDEBUG 256 3107224Speter #define PROPDEBUG 512 31152648Smckusick #define BREAKCYCLE 1024 31252648Smckusick #define SUBCYCLELIST 2048 31352648Smckusick #define ANYDEBUG 4096 314