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