121965Sdist /* 221965Sdist * Copyright (c) 1983 Regents of the University of California. 321965Sdist * All rights reserved. The Berkeley software License Agreement 421965Sdist * specifies the terms and conditions for redistribution. 521965Sdist * 6*25709Ssam * @(#)gprof.h 5.2 (Berkeley) 01/07/86 721965Sdist */ 84511Speter 94511Speter #include <stdio.h> 104511Speter #include <sys/types.h> 114511Speter #include <sys/stat.h> 124511Speter #include <a.out.h> 134870Smckusic #include "gcrt0.h" 144511Speter 1511799Speter #if vax 1611799Speter # include "vax.h" 1711799Speter #endif 1811799Speter #if sun 19*25709Ssam # include "sun.h" 2011799Speter #endif 21*25709Ssam #if tahoe 22*25709Ssam # include "tahoe.h" 23*25709Ssam #endif 2411799Speter 2511799Speter 264511Speter /* 277129Speter * who am i, for error messages. 287129Speter */ 297129Speter char *whoami; 307129Speter 317129Speter /* 327174Speter * booleans 337174Speter */ 347174Speter typedef int bool; 357174Speter #define FALSE 0 367174Speter #define TRUE 1 377174Speter 387174Speter /* 394511Speter * ticks per second 404511Speter */ 4110250Speter long hz; 424511Speter 434511Speter typedef short UNIT; /* unit of profiling */ 444511Speter char *a_outname; 454511Speter #define A_OUTNAME "a.out" 464511Speter 474560Speter char *gmonname; 484560Speter #define GMONNAME "gmon.out" 494867Smckusic #define GMONSUM "gmon.sum" 504873Smckusic 514873Smckusic /* 5210286Speter * blurbs on the flat and graph profiles. 534873Smckusic */ 5416862Smckusick #define FLAT_BLURB "/usr/lib/gprof.flat" 5516862Smckusick #define CALLG_BLURB "/usr/lib/gprof.callg" 564511Speter 574511Speter /* 584511Speter * a constructed arc, 594511Speter * with pointers to the namelist entry of the parent and the child, 604511Speter * a count of how many times this arc was traversed, 614511Speter * and pointers to the next parent of this child and 624511Speter * the next child of this parent. 634511Speter */ 644511Speter struct arcstruct { 654511Speter struct nl *arc_parentp; /* pointer to parent's nl entry */ 664511Speter struct nl *arc_childp; /* pointer to child's nl entry */ 674511Speter long arc_count; /* how calls from parent to child */ 684511Speter double arc_time; /* time inherited along arc */ 694511Speter double arc_childtime; /* childtime inherited along arc */ 704511Speter struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 714511Speter struct arcstruct *arc_childlist; /* children-of-this-parent list */ 724511Speter }; 734511Speter typedef struct arcstruct arctype; 744511Speter 757129Speter /* 767129Speter * The symbol table; 777129Speter * for each external in the specified file we gather 787129Speter * its address, the number of calls and compute its share of cpu time. 797129Speter */ 804511Speter struct nl { 817129Speter char *name; /* the name */ 827129Speter unsigned long value; /* the pc entry point */ 8311799Speter unsigned long svalue; /* entry point aligned to histograms */ 847129Speter double time; /* ticks in this routine */ 857129Speter double childtime; /* cumulative ticks in children */ 867129Speter long ncall; /* how many times called */ 877129Speter long selfcalls; /* how many calls to self */ 887224Speter double propfraction; /* what % of time propagates */ 897224Speter double propself; /* how much self time propagates */ 907224Speter double propchild; /* how much child time propagates */ 917174Speter bool printflag; /* should this be printed? */ 927129Speter int index; /* index in the graph list */ 937129Speter int toporder; /* graph call chain top-sort order */ 947129Speter int cycleno; /* internal number of cycle on */ 957129Speter struct nl *cyclehead; /* pointer to head of cycle */ 967129Speter struct nl *cnext; /* pointer to next member of cycle */ 977129Speter arctype *parents; /* list of caller arcs */ 987129Speter arctype *children; /* list of callee arcs */ 994511Speter }; 1004511Speter typedef struct nl nltype; 1014511Speter 1024511Speter nltype *nl; /* the whole namelist */ 1034511Speter nltype *npe; /* the virtual end of the namelist */ 1047129Speter int nname; /* the number of function names */ 1054511Speter 1064511Speter /* 1074511Speter * flag which marks a nl entry as topologically ``busy'' 10810284Speter * flag which marks a nl entry as topologically ``not_numbered'' 1094511Speter */ 1104511Speter #define DFN_BUSY -1 11110284Speter #define DFN_NAN 0 1124511Speter 1134511Speter /* 1147129Speter * namelist entries for cycle headers. 1157129Speter * the number of discovered cycles. 1164511Speter */ 1177129Speter nltype *cyclenl; /* cycle header namelist */ 1187129Speter int ncycle; /* number of cycles discovered */ 1194511Speter 1207129Speter /* 1217129Speter * The header on the gmon.out file. 1227129Speter * gmon.out consists of one of these headers, 1237129Speter * and then an array of ncnt samples 1247129Speter * representing the discretized program counter values. 1257129Speter * this should be a struct phdr, but since everything is done 1267129Speter * as UNITs, this is in UNITs too. 1277129Speter */ 1284511Speter struct hdr { 1297129Speter UNIT *lowpc; 1307129Speter UNIT *highpc; 1317129Speter int ncnt; 1324511Speter }; 1334511Speter 1344511Speter struct hdr h; 1354511Speter 1364511Speter int debug; 1374511Speter 1387129Speter /* 1397129Speter * Each discretized pc sample has 1407129Speter * a count of the number of samples in its range 1417129Speter */ 1424511Speter unsigned UNIT *samples; 1434511Speter 1444751Speter unsigned long s_lowpc; /* lowpc from the profile file */ 1454751Speter unsigned long s_highpc; /* highpc from the profile file */ 1464751Speter unsigned lowpc, highpc; /* range profiled, in UNIT's */ 1474511Speter unsigned sampbytes; /* number of bytes of samples */ 1484511Speter int nsamples; /* number of samples */ 1494511Speter double actime; /* accumulated time thus far for putprofline */ 1504511Speter double totime; /* total time for all routines */ 1517174Speter double printtime; /* total of time being printed */ 1524511Speter double scale; /* scale factor converting samples to pc 1534511Speter values: each sample covers scale bytes */ 1544511Speter char *strtab; /* string table in core */ 1554511Speter off_t ssiz; /* size of the string table */ 1564511Speter struct exec xbuf; /* exec header of a.out */ 1574722Speter unsigned char *textspace; /* text space of a.out in core */ 1584511Speter 1594855Speter /* 1604855Speter * option flags, from a to z. 1614855Speter */ 1627174Speter bool aflag; /* suppress static functions */ 1637174Speter bool bflag; /* blurbs, too */ 1647174Speter bool cflag; /* discovered call graph, too */ 1657174Speter bool dflag; /* debugging options */ 1667174Speter bool eflag; /* specific functions excluded */ 1677224Speter bool Eflag; /* functions excluded with time */ 1687174Speter bool fflag; /* specific functions requested */ 1697224Speter bool Fflag; /* functions requested with time */ 1707174Speter bool sflag; /* sum multiple gmon.out files */ 1717174Speter bool zflag; /* zero time/called functions, too */ 1724511Speter 1734511Speter /* 1747224Speter * structure for various string lists 1757224Speter */ 1767224Speter struct stringlist { 1777224Speter struct stringlist *next; 1787224Speter char *string; 1797224Speter }; 1807224Speter struct stringlist *elist; 1817224Speter struct stringlist *Elist; 1827224Speter struct stringlist *flist; 1837224Speter struct stringlist *Flist; 1847224Speter 1857224Speter /* 1864840Speter * function declarations 1874840Speter */ 1884840Speter addarc(); 1894840Speter int arccmp(); 1904511Speter arctype *arclookup(); 1914840Speter asgnsamples(); 1924855Speter printblurb(); 1934840Speter cyclelink(); 1944840Speter dfn(); 1954511Speter bool dfn_busy(); 1964840Speter dfn_findcycle(); 1974840Speter bool dfn_numbered(); 1984840Speter dfn_post_visit(); 1994840Speter dfn_pre_visit(); 2004840Speter dfn_self_cycle(); 20116851Smckusick nltype **doarcs(); 2024840Speter done(); 2034840Speter findcalls(); 2044840Speter flatprofheader(); 2054840Speter flatprofline(); 2064844Speter bool funcsymbol(); 2074840Speter getnfile(); 2084840Speter getpfile(); 2094840Speter getstrtab(); 2104840Speter getsymtab(); 2114840Speter gettextspace(); 2124840Speter gprofheader(); 2134840Speter gprofline(); 2144840Speter main(); 2154840Speter unsigned long max(); 2164840Speter int membercmp(); 2174840Speter unsigned long min(); 2184840Speter nltype *nllookup(); 2194840Speter FILE *openpfile(); 2204840Speter long operandlength(); 2214840Speter operandenum operandmode(); 2224840Speter char *operandname(); 2234840Speter printchildren(); 2244840Speter printcycle(); 2254840Speter printgprof(); 2264840Speter printmembers(); 2274840Speter printname(); 2284840Speter printparents(); 2294840Speter printprof(); 2304840Speter readsamples(); 2314840Speter unsigned long reladdr(); 2324840Speter sortchildren(); 2334840Speter sortmembers(); 2344840Speter sortparents(); 2354840Speter tally(); 2364840Speter timecmp(); 2374840Speter topcmp(); 2384840Speter int totalcmp(); 2394840Speter valcmp(); 2404511Speter 2414511Speter #define LESSTHAN -1 2424511Speter #define EQUALTO 0 2434511Speter #define GREATERTHAN 1 2444511Speter 2454511Speter #define DFNDEBUG 1 2464511Speter #define CYCLEDEBUG 2 2474511Speter #define ARCDEBUG 4 2484511Speter #define TALLYDEBUG 8 2494511Speter #define TIMEDEBUG 16 2504511Speter #define SAMPLEDEBUG 32 2514511Speter #define AOUTDEBUG 64 252*25709Ssam #define CALLDEBUG 128 2534722Speter #define LOOKUPDEBUG 256 2547224Speter #define PROPDEBUG 512 2557224Speter #define ANYDEBUG 1024 256