121965Sdist /* 221965Sdist * Copyright (c) 1983 Regents of the University of California. 334199Sbostic * All rights reserved. 421965Sdist * 534199Sbostic * Redistribution and use in source and binary forms are permitted 6*34881Sbostic * provided that the above copyright notice and this paragraph are 7*34881Sbostic * duplicated in all such forms and that any documentation, 8*34881Sbostic * advertising materials, and other materials related to such 9*34881Sbostic * distribution and use acknowledge that the software was developed 10*34881Sbostic * by the University of California, Berkeley. The name of the 11*34881Sbostic * University may not be used to endorse or promote products derived 12*34881Sbostic * from this software without specific prior written permission. 13*34881Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34881Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34881Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1634199Sbostic * 17*34881Sbostic * @(#)gprof.h 5.6 (Berkeley) 06/29/88 1821965Sdist */ 194511Speter 204511Speter #include <stdio.h> 214511Speter #include <sys/types.h> 224511Speter #include <sys/stat.h> 234511Speter #include <a.out.h> 244870Smckusic #include "gcrt0.h" 254511Speter 2611799Speter #if vax 2711799Speter # include "vax.h" 2811799Speter #endif 2911799Speter #if sun 3025709Ssam # include "sun.h" 3111799Speter #endif 3225709Ssam #if tahoe 3325709Ssam # include "tahoe.h" 3425709Ssam #endif 3511799Speter 3611799Speter 374511Speter /* 387129Speter * who am i, for error messages. 397129Speter */ 407129Speter char *whoami; 417129Speter 427129Speter /* 437174Speter * booleans 447174Speter */ 457174Speter typedef int bool; 467174Speter #define FALSE 0 477174Speter #define TRUE 1 487174Speter 497174Speter /* 504511Speter * ticks per second 514511Speter */ 5210250Speter long hz; 534511Speter 5433225Sbostic typedef u_short UNIT; /* unit of profiling */ 554511Speter char *a_outname; 564511Speter #define A_OUTNAME "a.out" 574511Speter 584560Speter char *gmonname; 594560Speter #define GMONNAME "gmon.out" 604867Smckusic #define GMONSUM "gmon.sum" 6133225Sbostic 624873Smckusic /* 6310286Speter * blurbs on the flat and graph profiles. 644873Smckusic */ 6516862Smckusick #define FLAT_BLURB "/usr/lib/gprof.flat" 6616862Smckusick #define CALLG_BLURB "/usr/lib/gprof.callg" 674511Speter 684511Speter /* 694511Speter * a constructed arc, 704511Speter * with pointers to the namelist entry of the parent and the child, 714511Speter * a count of how many times this arc was traversed, 724511Speter * and pointers to the next parent of this child and 734511Speter * the next child of this parent. 744511Speter */ 754511Speter struct arcstruct { 764511Speter struct nl *arc_parentp; /* pointer to parent's nl entry */ 774511Speter struct nl *arc_childp; /* pointer to child's nl entry */ 784511Speter long arc_count; /* how calls from parent to child */ 794511Speter double arc_time; /* time inherited along arc */ 804511Speter double arc_childtime; /* childtime inherited along arc */ 814511Speter struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 824511Speter struct arcstruct *arc_childlist; /* children-of-this-parent list */ 834511Speter }; 844511Speter typedef struct arcstruct arctype; 854511Speter 867129Speter /* 877129Speter * The symbol table; 887129Speter * for each external in the specified file we gather 897129Speter * its address, the number of calls and compute its share of cpu time. 907129Speter */ 914511Speter struct nl { 927129Speter char *name; /* the name */ 937129Speter unsigned long value; /* the pc entry point */ 9411799Speter unsigned long svalue; /* entry point aligned to histograms */ 957129Speter double time; /* ticks in this routine */ 967129Speter double childtime; /* cumulative ticks in children */ 977129Speter long ncall; /* how many times called */ 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 */ 1027174Speter bool printflag; /* should this be printed? */ 1037129Speter int index; /* index in the graph list */ 1047129Speter int toporder; /* graph call chain top-sort order */ 1057129Speter int cycleno; /* internal number of cycle on */ 1067129Speter struct nl *cyclehead; /* pointer to head of cycle */ 1077129Speter struct nl *cnext; /* pointer to next member of cycle */ 1087129Speter arctype *parents; /* list of caller arcs */ 1097129Speter arctype *children; /* list of callee arcs */ 1104511Speter }; 1114511Speter typedef struct nl nltype; 1124511Speter 1134511Speter nltype *nl; /* the whole namelist */ 1144511Speter nltype *npe; /* the virtual end of the namelist */ 1157129Speter int nname; /* the number of function names */ 1164511Speter 1174511Speter /* 1184511Speter * flag which marks a nl entry as topologically ``busy'' 11910284Speter * flag which marks a nl entry as topologically ``not_numbered'' 1204511Speter */ 1214511Speter #define DFN_BUSY -1 12210284Speter #define DFN_NAN 0 1234511Speter 1244511Speter /* 1257129Speter * namelist entries for cycle headers. 1267129Speter * the number of discovered cycles. 1274511Speter */ 1287129Speter nltype *cyclenl; /* cycle header namelist */ 1297129Speter int ncycle; /* number of cycles discovered */ 1304511Speter 1317129Speter /* 1327129Speter * The header on the gmon.out file. 1337129Speter * gmon.out consists of one of these headers, 1347129Speter * and then an array of ncnt samples 1357129Speter * representing the discretized program counter values. 1367129Speter * this should be a struct phdr, but since everything is done 1377129Speter * as UNITs, this is in UNITs too. 1387129Speter */ 1394511Speter struct hdr { 1407129Speter UNIT *lowpc; 1417129Speter UNIT *highpc; 1427129Speter int ncnt; 1434511Speter }; 1444511Speter 1454511Speter struct hdr h; 1464511Speter 1474511Speter int debug; 1484511Speter 1497129Speter /* 1507129Speter * Each discretized pc sample has 1517129Speter * a count of the number of samples in its range 1527129Speter */ 15333225Sbostic UNIT *samples; 1544511Speter 1554751Speter unsigned long s_lowpc; /* lowpc from the profile file */ 1564751Speter unsigned long s_highpc; /* highpc from the profile file */ 1574751Speter unsigned lowpc, highpc; /* range profiled, in UNIT's */ 1584511Speter unsigned sampbytes; /* number of bytes of samples */ 1594511Speter int nsamples; /* number of samples */ 1604511Speter double actime; /* accumulated time thus far for putprofline */ 1614511Speter double totime; /* total time for all routines */ 1627174Speter double printtime; /* total of time being printed */ 1634511Speter double scale; /* scale factor converting samples to pc 1644511Speter values: each sample covers scale bytes */ 1654511Speter char *strtab; /* string table in core */ 1664511Speter off_t ssiz; /* size of the string table */ 1674511Speter struct exec xbuf; /* exec header of a.out */ 1684722Speter unsigned char *textspace; /* text space of a.out in core */ 1694511Speter 1704855Speter /* 1714855Speter * option flags, from a to z. 1724855Speter */ 1737174Speter bool aflag; /* suppress static functions */ 1747174Speter bool bflag; /* blurbs, too */ 1757174Speter bool cflag; /* discovered call graph, too */ 1767174Speter bool dflag; /* debugging options */ 1777174Speter bool eflag; /* specific functions excluded */ 1787224Speter bool Eflag; /* functions excluded with time */ 1797174Speter bool fflag; /* specific functions requested */ 1807224Speter bool Fflag; /* functions requested with time */ 18130963Smckusick bool kflag; /* arcs to be deleted */ 1827174Speter bool sflag; /* sum multiple gmon.out files */ 1837174Speter bool zflag; /* zero time/called functions, too */ 1844511Speter 1854511Speter /* 1867224Speter * structure for various string lists 1877224Speter */ 1887224Speter struct stringlist { 1897224Speter struct stringlist *next; 1907224Speter char *string; 1917224Speter }; 1927224Speter struct stringlist *elist; 1937224Speter struct stringlist *Elist; 1947224Speter struct stringlist *flist; 1957224Speter struct stringlist *Flist; 19630963Smckusick struct stringlist *kfromlist; 19730963Smckusick struct stringlist *ktolist; 1987224Speter 1997224Speter /* 2004840Speter * function declarations 2014840Speter */ 20233225Sbostic /* 2034840Speter addarc(); 20433225Sbostic */ 2054840Speter int arccmp(); 2064511Speter arctype *arclookup(); 20733225Sbostic /* 2084840Speter asgnsamples(); 2094855Speter printblurb(); 2104840Speter cyclelink(); 2114840Speter dfn(); 21233225Sbostic */ 2134511Speter bool dfn_busy(); 21433225Sbostic /* 2154840Speter dfn_findcycle(); 21633225Sbostic */ 2174840Speter bool dfn_numbered(); 21833225Sbostic /* 2194840Speter dfn_post_visit(); 2204840Speter dfn_pre_visit(); 2214840Speter dfn_self_cycle(); 22233225Sbostic */ 22316851Smckusick nltype **doarcs(); 22433225Sbostic /* 2254840Speter done(); 2264840Speter findcalls(); 2274840Speter flatprofheader(); 2284840Speter flatprofline(); 22933225Sbostic */ 2304844Speter bool funcsymbol(); 23133225Sbostic /* 2324840Speter getnfile(); 2334840Speter getpfile(); 2344840Speter getstrtab(); 2354840Speter getsymtab(); 2364840Speter gettextspace(); 2374840Speter gprofheader(); 2384840Speter gprofline(); 2394840Speter main(); 24033225Sbostic */ 2414840Speter unsigned long max(); 2424840Speter int membercmp(); 2434840Speter unsigned long min(); 2444840Speter nltype *nllookup(); 2454840Speter FILE *openpfile(); 2464840Speter long operandlength(); 2474840Speter operandenum operandmode(); 2484840Speter char *operandname(); 24933225Sbostic /* 2504840Speter printchildren(); 2514840Speter printcycle(); 2524840Speter printgprof(); 2534840Speter printmembers(); 2544840Speter printname(); 2554840Speter printparents(); 2564840Speter printprof(); 2574840Speter readsamples(); 25833225Sbostic */ 2594840Speter unsigned long reladdr(); 26033225Sbostic /* 2614840Speter sortchildren(); 2624840Speter sortmembers(); 2634840Speter sortparents(); 2644840Speter tally(); 2654840Speter timecmp(); 2664840Speter topcmp(); 26733225Sbostic */ 2684840Speter int totalcmp(); 26933225Sbostic /* 2704840Speter valcmp(); 27133225Sbostic */ 2724511Speter 2734511Speter #define LESSTHAN -1 2744511Speter #define EQUALTO 0 2754511Speter #define GREATERTHAN 1 2764511Speter 2774511Speter #define DFNDEBUG 1 2784511Speter #define CYCLEDEBUG 2 2794511Speter #define ARCDEBUG 4 2804511Speter #define TALLYDEBUG 8 2814511Speter #define TIMEDEBUG 16 2824511Speter #define SAMPLEDEBUG 32 2834511Speter #define AOUTDEBUG 64 28425709Ssam #define CALLDEBUG 128 2854722Speter #define LOOKUPDEBUG 256 2867224Speter #define PROPDEBUG 512 2877224Speter #define ANYDEBUG 1024 288