19b50d902SRodney W. Grimes /* 29b50d902SRodney W. Grimes * Copyright (c) 1983, 1993 39b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 49b50d902SRodney W. Grimes * 59b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 69b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 79b50d902SRodney W. Grimes * are met: 89b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 99b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 109b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 119b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 129b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 139b50d902SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 149b50d902SRodney W. Grimes * must display the following acknowledgement: 159b50d902SRodney W. Grimes * This product includes software developed by the University of 169b50d902SRodney W. Grimes * California, Berkeley and its contributors. 179b50d902SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 189b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 199b50d902SRodney W. Grimes * without specific prior written permission. 209b50d902SRodney W. Grimes * 219b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 229b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 239b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 249b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 259b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 269b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 279b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 289b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 299b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 309b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 319b50d902SRodney W. Grimes * SUCH DAMAGE. 329b50d902SRodney W. Grimes * 339b50d902SRodney W. Grimes * @(#)gprof.h 8.1 (Berkeley) 6/6/93 349b50d902SRodney W. Grimes */ 359b50d902SRodney W. Grimes 369b50d902SRodney W. Grimes #include <sys/types.h> 379b50d902SRodney W. Grimes #include <sys/stat.h> 389b50d902SRodney W. Grimes #include <sys/gmon.h> 399b50d902SRodney W. Grimes 409b50d902SRodney W. Grimes #include <stdio.h> 419b50d902SRodney W. Grimes #include <stdlib.h> 429b50d902SRodney W. Grimes 4313a29a8aSHidetoshi Shimokawa #if __alpha__ 4413a29a8aSHidetoshi Shimokawa # include "alpha.h" 4513a29a8aSHidetoshi Shimokawa #endif 469b50d902SRodney W. Grimes #if vax 479b50d902SRodney W. Grimes # include "vax.h" 489b50d902SRodney W. Grimes #endif 499b50d902SRodney W. Grimes #if sparc 509b50d902SRodney W. Grimes # include "sparc.h" 519b50d902SRodney W. Grimes #endif 529b50d902SRodney W. Grimes #if tahoe 539b50d902SRodney W. Grimes # include "tahoe.h" 549b50d902SRodney W. Grimes #endif 559b50d902SRodney W. Grimes #if hp300 569b50d902SRodney W. Grimes # include "hp300.h" 579b50d902SRodney W. Grimes #endif 589b50d902SRodney W. Grimes #if luna68k 599b50d902SRodney W. Grimes # include "luna68k.h" 609b50d902SRodney W. Grimes #endif 619b50d902SRodney W. Grimes #if i386 629b50d902SRodney W. Grimes # include "i386.h" 639b50d902SRodney W. Grimes #endif 649b50d902SRodney W. Grimes #if mips 659b50d902SRodney W. Grimes # include "mips.h" 669b50d902SRodney W. Grimes #endif 679b50d902SRodney W. Grimes 689b50d902SRodney W. Grimes 699b50d902SRodney W. Grimes /* 709b50d902SRodney W. Grimes * booleans 719b50d902SRodney W. Grimes */ 729b50d902SRodney W. Grimes typedef int bool; 739b50d902SRodney W. Grimes #define FALSE 0 749b50d902SRodney W. Grimes #define TRUE 1 759b50d902SRodney W. Grimes 769b50d902SRodney W. Grimes /* 779b50d902SRodney W. Grimes * ticks per second 789b50d902SRodney W. Grimes */ 799b50d902SRodney W. Grimes long hz; 809b50d902SRodney W. Grimes 81e6c645faSBruce Evans #ifdef GPROF4 82ffbce11fSBruce Evans typedef int64_t UNIT; 83e6c645faSBruce Evans #else 849b50d902SRodney W. Grimes typedef u_short UNIT; /* unit of profiling */ 85e6c645faSBruce Evans #endif 869b50d902SRodney W. Grimes char *a_outname; 879b50d902SRodney W. Grimes #define A_OUTNAME "a.out" 889b50d902SRodney W. Grimes 899b50d902SRodney W. Grimes char *gmonname; 909b50d902SRodney W. Grimes #define GMONSUM "gmon.sum" 919b50d902SRodney W. Grimes 929b50d902SRodney W. Grimes /* 939b50d902SRodney W. Grimes * a constructed arc, 949b50d902SRodney W. Grimes * with pointers to the namelist entry of the parent and the child, 959b50d902SRodney W. Grimes * a count of how many times this arc was traversed, 969b50d902SRodney W. Grimes * and pointers to the next parent of this child and 979b50d902SRodney W. Grimes * the next child of this parent. 989b50d902SRodney W. Grimes */ 999b50d902SRodney W. Grimes struct arcstruct { 1009b50d902SRodney W. Grimes struct nl *arc_parentp; /* pointer to parent's nl entry */ 1019b50d902SRodney W. Grimes struct nl *arc_childp; /* pointer to child's nl entry */ 1029b50d902SRodney W. Grimes long arc_count; /* num calls from parent to child */ 1039b50d902SRodney W. Grimes double arc_time; /* time inherited along arc */ 1049b50d902SRodney W. Grimes double arc_childtime; /* childtime inherited along arc */ 1059b50d902SRodney W. Grimes struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 1069b50d902SRodney W. Grimes struct arcstruct *arc_childlist; /* children-of-this-parent list */ 1079b50d902SRodney W. Grimes struct arcstruct *arc_next; /* list of arcs on cycle */ 1089b50d902SRodney W. Grimes unsigned short arc_cyclecnt; /* num cycles involved in */ 1099b50d902SRodney W. Grimes unsigned short arc_flags; /* see below */ 1109b50d902SRodney W. Grimes }; 1119b50d902SRodney W. Grimes typedef struct arcstruct arctype; 1129b50d902SRodney W. Grimes 1139b50d902SRodney W. Grimes /* 1149b50d902SRodney W. Grimes * arc flags 1159b50d902SRodney W. Grimes */ 1169b50d902SRodney W. Grimes #define DEADARC 0x01 /* time should not propagate across the arc */ 1179b50d902SRodney W. Grimes #define ONLIST 0x02 /* arc is on list of arcs in cycles */ 1189b50d902SRodney W. Grimes 1199b50d902SRodney W. Grimes /* 1209b50d902SRodney W. Grimes * The symbol table; 1219b50d902SRodney W. Grimes * for each external in the specified file we gather 1229b50d902SRodney W. Grimes * its address, the number of calls and compute its share of cpu time. 1239b50d902SRodney W. Grimes */ 1249b50d902SRodney W. Grimes struct nl { 1255584f22bSJohn Polstra const char *name; /* the name */ 1269b50d902SRodney W. Grimes unsigned long value; /* the pc entry point */ 1279b50d902SRodney W. Grimes unsigned long svalue; /* entry point aligned to histograms */ 1289b50d902SRodney W. Grimes double time; /* ticks in this routine */ 1299b50d902SRodney W. Grimes double childtime; /* cumulative ticks in children */ 1309b50d902SRodney W. Grimes long ncall; /* how many times called */ 1319b50d902SRodney W. Grimes long npropcall; /* times called by live arcs */ 1329b50d902SRodney W. Grimes long selfcalls; /* how many calls to self */ 1339b50d902SRodney W. Grimes double propfraction; /* what % of time propagates */ 1349b50d902SRodney W. Grimes double propself; /* how much self time propagates */ 1359b50d902SRodney W. Grimes double propchild; /* how much child time propagates */ 1369b50d902SRodney W. Grimes short printflag; /* should this be printed? */ 1379b50d902SRodney W. Grimes short flags; /* see below */ 1389b50d902SRodney W. Grimes int index; /* index in the graph list */ 1399b50d902SRodney W. Grimes int toporder; /* graph call chain top-sort order */ 1409b50d902SRodney W. Grimes int cycleno; /* internal number of cycle on */ 1419b50d902SRodney W. Grimes int parentcnt; /* number of live parent arcs */ 1429b50d902SRodney W. Grimes struct nl *cyclehead; /* pointer to head of cycle */ 1439b50d902SRodney W. Grimes struct nl *cnext; /* pointer to next member of cycle */ 1449b50d902SRodney W. Grimes arctype *parents; /* list of caller arcs */ 1459b50d902SRodney W. Grimes arctype *children; /* list of callee arcs */ 1469b50d902SRodney W. Grimes }; 1479b50d902SRodney W. Grimes typedef struct nl nltype; 1489b50d902SRodney W. Grimes 1499b50d902SRodney W. Grimes nltype *nl; /* the whole namelist */ 1509b50d902SRodney W. Grimes nltype *npe; /* the virtual end of the namelist */ 1519b50d902SRodney W. Grimes int nname; /* the number of function names */ 1529b50d902SRodney W. Grimes 1539b50d902SRodney W. Grimes #define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 1549b50d902SRodney W. Grimes #define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 1559b50d902SRodney W. Grimes #define VISITED 0x20 /* node visited during a cycle */ 1569b50d902SRodney W. Grimes 1579b50d902SRodney W. Grimes /* 1589b50d902SRodney W. Grimes * The cycle list. 1599b50d902SRodney W. Grimes * for each subcycle within an identified cycle, we gather 1609b50d902SRodney W. Grimes * its size and the list of included arcs. 1619b50d902SRodney W. Grimes */ 1629b50d902SRodney W. Grimes struct cl { 1639b50d902SRodney W. Grimes int size; /* length of cycle */ 1649b50d902SRodney W. Grimes struct cl *next; /* next member of list */ 1659b50d902SRodney W. Grimes arctype *list[1]; /* list of arcs in cycle */ 1669b50d902SRodney W. Grimes /* actually longer */ 1679b50d902SRodney W. Grimes }; 1689b50d902SRodney W. Grimes typedef struct cl cltype; 1699b50d902SRodney W. Grimes 1709b50d902SRodney W. Grimes arctype *archead; /* the head of arcs in current cycle list */ 1719b50d902SRodney W. Grimes cltype *cyclehead; /* the head of the list */ 1729b50d902SRodney W. Grimes int cyclecnt; /* the number of cycles found */ 1739b50d902SRodney W. Grimes #define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 1749b50d902SRodney W. Grimes 1759b50d902SRodney W. Grimes /* 1769b50d902SRodney W. Grimes * flag which marks a nl entry as topologically ``busy'' 1779b50d902SRodney W. Grimes * flag which marks a nl entry as topologically ``not_numbered'' 1789b50d902SRodney W. Grimes */ 1799b50d902SRodney W. Grimes #define DFN_BUSY -1 1809b50d902SRodney W. Grimes #define DFN_NAN 0 1819b50d902SRodney W. Grimes 1829b50d902SRodney W. Grimes /* 1839b50d902SRodney W. Grimes * namelist entries for cycle headers. 1849b50d902SRodney W. Grimes * the number of discovered cycles. 1859b50d902SRodney W. Grimes */ 1869b50d902SRodney W. Grimes nltype *cyclenl; /* cycle header namelist */ 1879b50d902SRodney W. Grimes int ncycle; /* number of cycles discovered */ 1889b50d902SRodney W. Grimes 1899b50d902SRodney W. Grimes /* 1909b50d902SRodney W. Grimes * The header on the gmon.out file. 1919b50d902SRodney W. Grimes * gmon.out consists of a struct phdr (defined in gmon.h) 1929b50d902SRodney W. Grimes * and then an array of ncnt samples representing the 1939b50d902SRodney W. Grimes * discretized program counter values. 1949b50d902SRodney W. Grimes * 1959b50d902SRodney W. Grimes * Backward compatible old style header 1969b50d902SRodney W. Grimes */ 1979b50d902SRodney W. Grimes struct ophdr { 1989b50d902SRodney W. Grimes UNIT *lpc; 1999b50d902SRodney W. Grimes UNIT *hpc; 2009b50d902SRodney W. Grimes int ncnt; 2019b50d902SRodney W. Grimes }; 2029b50d902SRodney W. Grimes 2039b50d902SRodney W. Grimes int debug; 2049b50d902SRodney W. Grimes 2059b50d902SRodney W. Grimes /* 2069b50d902SRodney W. Grimes * Each discretized pc sample has 2079b50d902SRodney W. Grimes * a count of the number of samples in its range 2089b50d902SRodney W. Grimes */ 2099b50d902SRodney W. Grimes UNIT *samples; 2109b50d902SRodney W. Grimes 2119b50d902SRodney W. Grimes unsigned long s_lowpc; /* lowpc from the profile file */ 2129b50d902SRodney W. Grimes unsigned long s_highpc; /* highpc from the profile file */ 21313a29a8aSHidetoshi Shimokawa unsigned long lowpc, highpc; /* range profiled, in UNIT's */ 2149b50d902SRodney W. Grimes unsigned sampbytes; /* number of bytes of samples */ 2159b50d902SRodney W. Grimes int nsamples; /* number of samples */ 2169b50d902SRodney W. Grimes double actime; /* accumulated time thus far for putprofline */ 2179b50d902SRodney W. Grimes double totime; /* total time for all routines */ 2189b50d902SRodney W. Grimes double printtime; /* total of time being printed */ 2199b50d902SRodney W. Grimes double scale; /* scale factor converting samples to pc 2209b50d902SRodney W. Grimes values: each sample covers scale bytes */ 2219b50d902SRodney W. Grimes unsigned char *textspace; /* text space of a.out in core */ 2229b50d902SRodney W. Grimes int cyclethreshold; /* with -C, minimum cycle size to ignore */ 2239b50d902SRodney W. Grimes 2249b50d902SRodney W. Grimes /* 2259b50d902SRodney W. Grimes * option flags, from a to z. 2269b50d902SRodney W. Grimes */ 2279b50d902SRodney W. Grimes bool aflag; /* suppress static functions */ 2289b50d902SRodney W. Grimes bool bflag; /* blurbs, too */ 2299b50d902SRodney W. Grimes bool cflag; /* discovered call graph, too */ 2309b50d902SRodney W. Grimes bool Cflag; /* find cut-set to eliminate cycles */ 2319b50d902SRodney W. Grimes bool dflag; /* debugging options */ 2329b50d902SRodney W. Grimes bool eflag; /* specific functions excluded */ 2339b50d902SRodney W. Grimes bool Eflag; /* functions excluded with time */ 2349b50d902SRodney W. Grimes bool fflag; /* specific functions requested */ 2359b50d902SRodney W. Grimes bool Fflag; /* functions requested with time */ 2369b50d902SRodney W. Grimes bool kflag; /* arcs to be deleted */ 2379b50d902SRodney W. Grimes bool sflag; /* sum multiple gmon.out files */ 2385584f22bSJohn Polstra bool uflag; /* suppress symbols hidden from C */ 2399b50d902SRodney W. Grimes bool zflag; /* zero time/called functions, too */ 2409b50d902SRodney W. Grimes 2419b50d902SRodney W. Grimes /* 2429b50d902SRodney W. Grimes * structure for various string lists 2439b50d902SRodney W. Grimes */ 2449b50d902SRodney W. Grimes struct stringlist { 2459b50d902SRodney W. Grimes struct stringlist *next; 2469b50d902SRodney W. Grimes char *string; 2479b50d902SRodney W. Grimes }; 2489b50d902SRodney W. Grimes struct stringlist *elist; 2499b50d902SRodney W. Grimes struct stringlist *Elist; 2509b50d902SRodney W. Grimes struct stringlist *flist; 2519b50d902SRodney W. Grimes struct stringlist *Flist; 2529b50d902SRodney W. Grimes struct stringlist *kfromlist; 2539b50d902SRodney W. Grimes struct stringlist *ktolist; 2549b50d902SRodney W. Grimes 2559b50d902SRodney W. Grimes /* 2569b50d902SRodney W. Grimes * function declarations 2579b50d902SRodney W. Grimes */ 2589b50d902SRodney W. Grimes /* 2599b50d902SRodney W. Grimes addarc(); 2609b50d902SRodney W. Grimes */ 2615584f22bSJohn Polstra int aout_getnfile(const char *, char ***); 2629b50d902SRodney W. Grimes int arccmp(); 2639b50d902SRodney W. Grimes arctype *arclookup(); 2649b50d902SRodney W. Grimes /* 2659b50d902SRodney W. Grimes asgnsamples(); 2669b50d902SRodney W. Grimes printblurb(); 2679b50d902SRodney W. Grimes cyclelink(); 2689b50d902SRodney W. Grimes dfn(); 2699b50d902SRodney W. Grimes */ 2709b50d902SRodney W. Grimes bool dfn_busy(); 2719b50d902SRodney W. Grimes /* 2729b50d902SRodney W. Grimes dfn_findcycle(); 2739b50d902SRodney W. Grimes */ 2749b50d902SRodney W. Grimes bool dfn_numbered(); 2759b50d902SRodney W. Grimes /* 2769b50d902SRodney W. Grimes dfn_post_visit(); 2779b50d902SRodney W. Grimes dfn_pre_visit(); 2789b50d902SRodney W. Grimes dfn_self_cycle(); 2799b50d902SRodney W. Grimes */ 2809b50d902SRodney W. Grimes nltype **doarcs(); 2819b50d902SRodney W. Grimes /* 2829b50d902SRodney W. Grimes done(); 2835584f22bSJohn Polstra */ 2845584f22bSJohn Polstra int elf_getnfile(const char *, char ***); 2855584f22bSJohn Polstra /* 2869b50d902SRodney W. Grimes findcalls(); 2879b50d902SRodney W. Grimes flatprofheader(); 2889b50d902SRodney W. Grimes flatprofline(); 2899b50d902SRodney W. Grimes */ 2909b50d902SRodney W. Grimes /* 2919b50d902SRodney W. Grimes getpfile(); 2929b50d902SRodney W. Grimes gprofheader(); 2939b50d902SRodney W. Grimes gprofline(); 2949b50d902SRodney W. Grimes main(); 2959b50d902SRodney W. Grimes */ 2969b50d902SRodney W. Grimes unsigned long max(); 2979b50d902SRodney W. Grimes int membercmp(); 2989b50d902SRodney W. Grimes unsigned long min(); 2999b50d902SRodney W. Grimes nltype *nllookup(); 3009b50d902SRodney W. Grimes FILE *openpfile(); 3019b50d902SRodney W. Grimes long operandlength(); 3029b50d902SRodney W. Grimes operandenum operandmode(); 3039b50d902SRodney W. Grimes char *operandname(); 3049b50d902SRodney W. Grimes /* 3059b50d902SRodney W. Grimes printchildren(); 3069b50d902SRodney W. Grimes printcycle(); 3079b50d902SRodney W. Grimes printgprof(); 3089b50d902SRodney W. Grimes printmembers(); 3099b50d902SRodney W. Grimes printname(); 3109b50d902SRodney W. Grimes printparents(); 3119b50d902SRodney W. Grimes printprof(); 3129b50d902SRodney W. Grimes readsamples(); 3139b50d902SRodney W. Grimes */ 3149b50d902SRodney W. Grimes unsigned long reladdr(); 3159b50d902SRodney W. Grimes /* 3169b50d902SRodney W. Grimes sortchildren(); 3179b50d902SRodney W. Grimes sortmembers(); 3189b50d902SRodney W. Grimes sortparents(); 3199b50d902SRodney W. Grimes tally(); 3209b50d902SRodney W. Grimes timecmp(); 3219b50d902SRodney W. Grimes topcmp(); 3229b50d902SRodney W. Grimes */ 3239b50d902SRodney W. Grimes int totalcmp(); 3249b50d902SRodney W. Grimes /* 3259b50d902SRodney W. Grimes valcmp(); 3269b50d902SRodney W. Grimes */ 3279b50d902SRodney W. Grimes 3289b50d902SRodney W. Grimes #define LESSTHAN -1 3299b50d902SRodney W. Grimes #define EQUALTO 0 3309b50d902SRodney W. Grimes #define GREATERTHAN 1 3319b50d902SRodney W. Grimes 3329b50d902SRodney W. Grimes #define DFNDEBUG 1 3339b50d902SRodney W. Grimes #define CYCLEDEBUG 2 3349b50d902SRodney W. Grimes #define ARCDEBUG 4 3359b50d902SRodney W. Grimes #define TALLYDEBUG 8 3369b50d902SRodney W. Grimes #define TIMEDEBUG 16 3379b50d902SRodney W. Grimes #define SAMPLEDEBUG 32 3389b50d902SRodney W. Grimes #define AOUTDEBUG 64 3399b50d902SRodney W. Grimes #define CALLDEBUG 128 3409b50d902SRodney W. Grimes #define LOOKUPDEBUG 256 3419b50d902SRodney W. Grimes #define PROPDEBUG 512 3429b50d902SRodney W. Grimes #define BREAKCYCLE 1024 3439b50d902SRodney W. Grimes #define SUBCYCLELIST 2048 3449b50d902SRodney W. Grimes #define ANYDEBUG 4096 345