gprof.h revision 268351
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)gprof.h 8.1 (Berkeley) 6/6/93 30 * $FreeBSD: head/usr.bin/gprof/gprof.h 268351 2014-07-07 00:27:09Z marcel $ 31 */ 32 33#include <sys/types.h> 34#include <sys/stat.h> 35#include <sys/gmon.h> 36 37#include <stdio.h> 38#include <stdlib.h> 39 40#if __amd64__ 41# include "amd64.h" 42#endif 43#if __arm__ 44# include "arm.h" 45#endif 46#if __i386__ 47# include "i386.h" 48#endif 49#if __mips__ 50# include "mips.h" 51#endif 52#if __powerpc__ 53# include "powerpc.h" 54#endif 55#if __sparc64__ 56# include "sparc64.h" 57#endif 58 59 /* 60 * booleans 61 */ 62typedef int bool; 63#define FALSE 0 64#define TRUE 1 65 66 /* 67 * Historical scale factor in profil(2)'s algorithm for converting 68 * pc addresses to bucket numbers. This now just complicates the 69 * scaling and makes bucket:pc densities of more than 1/2 useless. 70 */ 71#define HISTORICAL_SCALE_2 2 72 73 /* 74 * ticks per second 75 */ 76long hz; 77 78size_t histcounter_size; 79int histcounter_type; 80 81char *a_outname; 82#define A_OUTNAME "a.out" 83 84char *gmonname; 85#define GMONSUM "gmon.sum" 86 87 /* 88 * a constructed arc, 89 * with pointers to the namelist entry of the parent and the child, 90 * a count of how many times this arc was traversed, 91 * and pointers to the next parent of this child and 92 * the next child of this parent. 93 */ 94struct arcstruct { 95 struct nl *arc_parentp; /* pointer to parent's nl entry */ 96 struct nl *arc_childp; /* pointer to child's nl entry */ 97 long arc_count; /* num calls from parent to child */ 98 double arc_time; /* time inherited along arc */ 99 double arc_childtime; /* childtime inherited along arc */ 100 struct arcstruct *arc_parentlist; /* parents-of-this-child list */ 101 struct arcstruct *arc_childlist; /* children-of-this-parent list */ 102 struct arcstruct *arc_next; /* list of arcs on cycle */ 103 unsigned short arc_cyclecnt; /* num cycles involved in */ 104 unsigned short arc_flags; /* see below */ 105}; 106typedef struct arcstruct arctype; 107 108 /* 109 * arc flags 110 */ 111#define DEADARC 0x01 /* time should not propagate across the arc */ 112#define ONLIST 0x02 /* arc is on list of arcs in cycles */ 113 114 /* 115 * The symbol table; 116 * for each external in the specified file we gather 117 * its address, the number of calls and compute its share of CPU time. 118 */ 119struct nl { 120 const char *name; /* the name */ 121 unsigned long value; /* the pc entry point */ 122 unsigned long svalue; /* entry point aligned to histograms */ 123 double time; /* ticks in this routine */ 124 double childtime; /* cumulative ticks in children */ 125 long ncall; /* how many times called */ 126 long npropcall; /* times called by live arcs */ 127 long selfcalls; /* how many calls to self */ 128 double propfraction; /* what % of time propagates */ 129 double propself; /* how much self time propagates */ 130 double propchild; /* how much child time propagates */ 131 short printflag; /* should this be printed? */ 132 short flags; /* see below */ 133 int index; /* index in the graph list */ 134 int toporder; /* graph call chain top-sort order */ 135 int cycleno; /* internal number of cycle on */ 136 int parentcnt; /* number of live parent arcs */ 137 struct nl *cyclehead; /* pointer to head of cycle */ 138 struct nl *cnext; /* pointer to next member of cycle */ 139 arctype *parents; /* list of caller arcs */ 140 arctype *children; /* list of callee arcs */ 141}; 142typedef struct nl nltype; 143 144nltype *nl; /* the whole namelist */ 145nltype *npe; /* the virtual end of the namelist */ 146int nname; /* the number of function names */ 147 148#define HASCYCLEXIT 0x08 /* node has arc exiting from cycle */ 149#define CYCLEHEAD 0x10 /* node marked as head of a cycle */ 150#define VISITED 0x20 /* node visited during a cycle */ 151 152 /* 153 * The cycle list. 154 * for each subcycle within an identified cycle, we gather 155 * its size and the list of included arcs. 156 */ 157struct cl { 158 int size; /* length of cycle */ 159 struct cl *next; /* next member of list */ 160 arctype *list[1]; /* list of arcs in cycle */ 161 /* actually longer */ 162}; 163typedef struct cl cltype; 164 165arctype *archead; /* the head of arcs in current cycle list */ 166cltype *cyclehead; /* the head of the list */ 167int cyclecnt; /* the number of cycles found */ 168#define CYCLEMAX 100 /* maximum cycles before cutting one of them */ 169 170 /* 171 * flag which marks a nl entry as topologically ``busy'' 172 * flag which marks a nl entry as topologically ``not_numbered'' 173 */ 174#define DFN_BUSY -1 175#define DFN_NAN 0 176 177 /* 178 * namelist entries for cycle headers. 179 * the number of discovered cycles. 180 */ 181nltype *cyclenl; /* cycle header namelist */ 182int ncycle; /* number of cycles discovered */ 183 184 /* 185 * The header on the gmon.out file. 186 * gmon.out consists of a struct phdr (defined in gmon.h) 187 * and then an array of ncnt samples representing the 188 * discretized program counter values. 189 * 190 * Backward compatible old style header 191 */ 192struct ophdr { 193 u_short *lpc; 194 u_short *hpc; 195 int ncnt; 196}; 197 198int debug; 199 200 /* 201 * Each discretized pc sample has 202 * a count of the number of samples in its range 203 */ 204double *samples; 205 206unsigned long s_lowpc; /* lowpc from the profile file */ 207unsigned long s_highpc; /* highpc from the profile file */ 208unsigned long lowpc, highpc; /* range profiled, in historical units */ 209unsigned sampbytes; /* number of bytes of samples */ 210int nsamples; /* number of samples */ 211double actime; /* accumulated time thus far for putprofline */ 212double totime; /* total time for all routines */ 213double printtime; /* total of time being printed */ 214double scale; /* scale factor converting samples to pc 215 values: each sample covers scale bytes */ 216unsigned char *textspace; /* text space of a.out in core */ 217int cyclethreshold; /* with -C, minimum cycle size to ignore */ 218 219 /* 220 * option flags, from a to z. 221 */ 222bool aflag; /* suppress static functions */ 223bool bflag; /* blurbs, too */ 224bool Cflag; /* find cut-set to eliminate cycles */ 225bool dflag; /* debugging options */ 226bool eflag; /* specific functions excluded */ 227bool Eflag; /* functions excluded with time */ 228bool fflag; /* specific functions requested */ 229bool Fflag; /* functions requested with time */ 230bool kflag; /* arcs to be deleted */ 231bool Kflag; /* use the running kernel for symbols */ 232bool sflag; /* sum multiple gmon.out files */ 233bool uflag; /* suppress symbols hidden from C */ 234bool zflag; /* zero time/called functions, too */ 235 236 /* 237 * structure for various string lists 238 */ 239struct stringlist { 240 struct stringlist *next; 241 char *string; 242}; 243struct stringlist *elist; 244struct stringlist *Elist; 245struct stringlist *flist; 246struct stringlist *Flist; 247struct stringlist *kfromlist; 248struct stringlist *ktolist; 249 250 /* 251 * function declarations 252 */ 253void addarc(nltype *, nltype *, long); 254bool addcycle(arctype **, arctype **); 255void addlist(struct stringlist *, char *); 256void alignentries(void); 257int aout_getnfile(const char *, char ***); 258int arccmp(arctype *, arctype *); 259arctype *arclookup(nltype *, nltype *); 260void asgnsamples(void); 261void compresslist(void); 262bool cycleanalyze(void); 263void cyclelink(void); 264void cycletime(void); 265bool descend(nltype *, arctype **, arctype **); 266void dfn(nltype *); 267bool dfn_busy(nltype *); 268void dfn_findcycle(nltype *); 269void dfn_init(void); 270bool dfn_numbered(nltype *); 271void dfn_post_visit(nltype *); 272void dfn_pre_visit(nltype *); 273void dfn_self_cycle(nltype *); 274nltype **doarcs(void); 275void doflags(void); 276void dotime(void); 277void dumpsum(const char *); 278int elf_getnfile(const char *, char ***); 279void flatprofheader(void); 280void flatprofline(nltype *); 281void getpfile(char *); 282void gprofheader(void); 283void gprofline(register nltype *); 284int hertz(void); 285void inheritflags(nltype *); 286int kernel_getnfile(const char *, char ***); 287/* 288 main(); 289*/ 290unsigned long max(unsigned long, unsigned long); 291int membercmp(nltype *, nltype *); 292unsigned long min(unsigned long, unsigned long); 293nltype *nllookup(unsigned long); 294bool onlist(struct stringlist *, const char *); 295FILE *openpfile(char *); 296void printblurb(const char *); 297void printchildren(nltype *); 298void printcycle(nltype *); 299void printgprof(nltype **); 300void printindex(void); 301void printmembers(nltype *); 302void printname(nltype *); 303void printparents(nltype *); 304void printprof(void); 305void printsubcycle(cltype *); 306void readsamples(FILE *); 307void sortchildren(nltype *); 308void sortmembers(nltype *); 309void sortparents(nltype *); 310void tally(struct rawarc *); 311void timepropagate(nltype *); 312int totalcmp(const void *, const void *); 313 314#define LESSTHAN -1 315#define EQUALTO 0 316#define GREATERTHAN 1 317 318#define DFNDEBUG 1 319#define CYCLEDEBUG 2 320#define ARCDEBUG 4 321#define TALLYDEBUG 8 322#define TIMEDEBUG 16 323#define SAMPLEDEBUG 32 324#define AOUTDEBUG 64 325#define CALLDEBUG 128 326#define LOOKUPDEBUG 256 327#define PROPDEBUG 512 328#define BREAKCYCLE 1024 329#define SUBCYCLELIST 2048 330#define ANYDEBUG 4096 331