121965Sdist /* 221965Sdist * Copyright (c) 1983 Regents of the University of California. 334199Sbostic * All rights reserved. 421965Sdist * 542683Sbostic * %sccs.include.redist.c% 634199Sbostic * 7*48699Sdonn * @(#)gprof.h 5.10 (Berkeley) 04/24/91 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 25*48699Sdonn #if hp300 26*48699Sdonn # include "hp300.h" 27*48699Sdonn #endif 28*48699Sdonn #if i386 29*48699Sdonn # include "i386.h" 30*48699Sdonn #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 */ 684511Speter long arc_count; /* how 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 */ 734511Speter }; 744511Speter typedef struct arcstruct arctype; 754511Speter 767129Speter /* 777129Speter * The symbol table; 787129Speter * for each external in the specified file we gather 797129Speter * its address, the number of calls and compute its share of cpu time. 807129Speter */ 814511Speter struct nl { 827129Speter char *name; /* the name */ 837129Speter unsigned long value; /* the pc entry point */ 8411799Speter unsigned long svalue; /* entry point aligned to histograms */ 857129Speter double time; /* ticks in this routine */ 867129Speter double childtime; /* cumulative ticks in children */ 877129Speter long ncall; /* how many times called */ 887129Speter long selfcalls; /* how many calls to self */ 897224Speter double propfraction; /* what % of time propagates */ 907224Speter double propself; /* how much self time propagates */ 917224Speter double propchild; /* how much child time propagates */ 927174Speter bool printflag; /* should this be printed? */ 937129Speter int index; /* index in the graph list */ 947129Speter int toporder; /* graph call chain top-sort order */ 957129Speter int cycleno; /* internal number of cycle on */ 967129Speter struct nl *cyclehead; /* pointer to head of cycle */ 977129Speter struct nl *cnext; /* pointer to next member of cycle */ 987129Speter arctype *parents; /* list of caller arcs */ 997129Speter arctype *children; /* list of callee arcs */ 1004511Speter }; 1014511Speter typedef struct nl nltype; 1024511Speter 1034511Speter nltype *nl; /* the whole namelist */ 1044511Speter nltype *npe; /* the virtual end of the namelist */ 1057129Speter int nname; /* the number of function names */ 1064511Speter 1074511Speter /* 1084511Speter * flag which marks a nl entry as topologically ``busy'' 10910284Speter * flag which marks a nl entry as topologically ``not_numbered'' 1104511Speter */ 1114511Speter #define DFN_BUSY -1 11210284Speter #define DFN_NAN 0 1134511Speter 1144511Speter /* 1157129Speter * namelist entries for cycle headers. 1167129Speter * the number of discovered cycles. 1174511Speter */ 1187129Speter nltype *cyclenl; /* cycle header namelist */ 1197129Speter int ncycle; /* number of cycles discovered */ 1204511Speter 1217129Speter /* 1227129Speter * The header on the gmon.out file. 1237129Speter * gmon.out consists of one of these headers, 1247129Speter * and then an array of ncnt samples 1257129Speter * representing the discretized program counter values. 1267129Speter * this should be a struct phdr, but since everything is done 1277129Speter * as UNITs, this is in UNITs too. 1287129Speter */ 1294511Speter struct hdr { 1307129Speter UNIT *lowpc; 1317129Speter UNIT *highpc; 1327129Speter int ncnt; 1334511Speter }; 1344511Speter 1354511Speter struct hdr h; 1364511Speter 1374511Speter int debug; 1384511Speter 1397129Speter /* 1407129Speter * Each discretized pc sample has 1417129Speter * a count of the number of samples in its range 1427129Speter */ 14333225Sbostic UNIT *samples; 1444511Speter 1454751Speter unsigned long s_lowpc; /* lowpc from the profile file */ 1464751Speter unsigned long s_highpc; /* highpc from the profile file */ 1474751Speter unsigned lowpc, highpc; /* range profiled, in UNIT's */ 1484511Speter unsigned sampbytes; /* number of bytes of samples */ 1494511Speter int nsamples; /* number of samples */ 1504511Speter double actime; /* accumulated time thus far for putprofline */ 1514511Speter double totime; /* total time for all routines */ 1527174Speter double printtime; /* total of time being printed */ 1534511Speter double scale; /* scale factor converting samples to pc 1544511Speter values: each sample covers scale bytes */ 1554511Speter char *strtab; /* string table in core */ 1564511Speter off_t ssiz; /* size of the string table */ 1574511Speter struct exec xbuf; /* exec header of a.out */ 1584722Speter unsigned char *textspace; /* text space of a.out in core */ 1594511Speter 1604855Speter /* 1614855Speter * option flags, from a to z. 1624855Speter */ 1637174Speter bool aflag; /* suppress static functions */ 1647174Speter bool bflag; /* blurbs, too */ 1657174Speter bool cflag; /* discovered call graph, too */ 1667174Speter bool dflag; /* debugging options */ 1677174Speter bool eflag; /* specific functions excluded */ 1687224Speter bool Eflag; /* functions excluded with time */ 1697174Speter bool fflag; /* specific functions requested */ 1707224Speter bool Fflag; /* functions requested with time */ 17130963Smckusick bool kflag; /* arcs to be deleted */ 1727174Speter bool sflag; /* sum multiple gmon.out files */ 1737174Speter bool zflag; /* zero time/called functions, too */ 1744511Speter 1754511Speter /* 1767224Speter * structure for various string lists 1777224Speter */ 1787224Speter struct stringlist { 1797224Speter struct stringlist *next; 1807224Speter char *string; 1817224Speter }; 1827224Speter struct stringlist *elist; 1837224Speter struct stringlist *Elist; 1847224Speter struct stringlist *flist; 1857224Speter struct stringlist *Flist; 18630963Smckusick struct stringlist *kfromlist; 18730963Smckusick struct stringlist *ktolist; 1887224Speter 1897224Speter /* 1904840Speter * function declarations 1914840Speter */ 19233225Sbostic /* 1934840Speter addarc(); 19433225Sbostic */ 1954840Speter int arccmp(); 1964511Speter arctype *arclookup(); 19733225Sbostic /* 1984840Speter asgnsamples(); 1994855Speter printblurb(); 2004840Speter cyclelink(); 2014840Speter dfn(); 20233225Sbostic */ 2034511Speter bool dfn_busy(); 20433225Sbostic /* 2054840Speter dfn_findcycle(); 20633225Sbostic */ 2074840Speter bool dfn_numbered(); 20833225Sbostic /* 2094840Speter dfn_post_visit(); 2104840Speter dfn_pre_visit(); 2114840Speter dfn_self_cycle(); 21233225Sbostic */ 21316851Smckusick nltype **doarcs(); 21433225Sbostic /* 2154840Speter done(); 2164840Speter findcalls(); 2174840Speter flatprofheader(); 2184840Speter flatprofline(); 21933225Sbostic */ 2204844Speter bool funcsymbol(); 22133225Sbostic /* 2224840Speter getnfile(); 2234840Speter getpfile(); 2244840Speter getstrtab(); 2254840Speter getsymtab(); 2264840Speter gettextspace(); 2274840Speter gprofheader(); 2284840Speter gprofline(); 2294840Speter main(); 23033225Sbostic */ 2314840Speter unsigned long max(); 2324840Speter int membercmp(); 2334840Speter unsigned long min(); 2344840Speter nltype *nllookup(); 2354840Speter FILE *openpfile(); 2364840Speter long operandlength(); 2374840Speter operandenum operandmode(); 2384840Speter char *operandname(); 23933225Sbostic /* 2404840Speter printchildren(); 2414840Speter printcycle(); 2424840Speter printgprof(); 2434840Speter printmembers(); 2444840Speter printname(); 2454840Speter printparents(); 2464840Speter printprof(); 2474840Speter readsamples(); 24833225Sbostic */ 2494840Speter unsigned long reladdr(); 25033225Sbostic /* 2514840Speter sortchildren(); 2524840Speter sortmembers(); 2534840Speter sortparents(); 2544840Speter tally(); 2554840Speter timecmp(); 2564840Speter topcmp(); 25733225Sbostic */ 2584840Speter int totalcmp(); 25933225Sbostic /* 2604840Speter valcmp(); 26133225Sbostic */ 2624511Speter 2634511Speter #define LESSTHAN -1 2644511Speter #define EQUALTO 0 2654511Speter #define GREATERTHAN 1 2664511Speter 2674511Speter #define DFNDEBUG 1 2684511Speter #define CYCLEDEBUG 2 2694511Speter #define ARCDEBUG 4 2704511Speter #define TALLYDEBUG 8 2714511Speter #define TIMEDEBUG 16 2724511Speter #define SAMPLEDEBUG 32 2734511Speter #define AOUTDEBUG 64 27425709Ssam #define CALLDEBUG 128 2754722Speter #define LOOKUPDEBUG 256 2767224Speter #define PROPDEBUG 512 2777224Speter #define ANYDEBUG 1024 278