1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)gprof.h	5.1 (Berkeley) 6/4/85
   7:  */
   8: 
   9: #include <stdio.h>
  10: #include <sys/types.h>
  11: #include <sys/stat.h>
  12: #include <a.out.h>
  13: #include "gcrt0.h"
  14: 
  15: #if vax
  16: #   include "vax.h"
  17: #endif
  18: #if sun
  19: #    include "sun.h"
  20: #endif
  21: 
  22: 
  23:     /*
  24:      *	who am i, for error messages.
  25:      */
  26: char    *whoami;
  27: 
  28:     /*
  29:      * booleans
  30:      */
  31: typedef int bool;
  32: #define FALSE   0
  33: #define TRUE    1
  34: 
  35:     /*
  36:      *	ticks per second
  37:      */
  38: long    hz;
  39: 
  40: typedef short UNIT;     /* unit of profiling */
  41: char    *a_outname;
  42: #define A_OUTNAME       "a.out"
  43: 
  44: char    *gmonname;
  45: #define GMONNAME        "gmon.out"
  46: #define GMONSUM         "gmon.sum"
  47: 
  48:     /*
  49:      *	blurbs on the flat and graph profiles.
  50:      */
  51: #define FLAT_BLURB  "/usr/lib/gprof.flat"
  52: #define CALLG_BLURB "/usr/lib/gprof.callg"
  53: 
  54:     /*
  55:      *	a constructed arc,
  56:      *	    with pointers to the namelist entry of the parent and the child,
  57:      *	    a count of how many times this arc was traversed,
  58:      *	    and pointers to the next parent of this child and
  59:      *		the next child of this parent.
  60:      */
  61: struct arcstruct {
  62:     struct nl       *arc_parentp;   /* pointer to parent's nl entry */
  63:     struct nl       *arc_childp;    /* pointer to child's nl entry */
  64:     long        arc_count;  /* how calls from parent to child */
  65:     double      arc_time;   /* time inherited along arc */
  66:     double      arc_childtime;  /* childtime inherited along arc */
  67:     struct arcstruct    *arc_parentlist; /* parents-of-this-child list */
  68:     struct arcstruct    *arc_childlist; /* children-of-this-parent list */
  69: };
  70: typedef struct arcstruct    arctype;
  71: 
  72:     /*
  73:      * The symbol table;
  74:      * for each external in the specified file we gather
  75:      * its address, the number of calls and compute its share of cpu time.
  76:      */
  77: struct nl {
  78:     char        *name;      /* the name */
  79:     unsigned long   value;      /* the pc entry point */
  80:     unsigned long   svalue;     /* entry point aligned to histograms */
  81:     double      time;       /* ticks in this routine */
  82:     double      childtime;  /* cumulative ticks in children */
  83:     long        ncall;      /* how many times called */
  84:     long        selfcalls;  /* how many calls to self */
  85:     double      propfraction;   /* what % of time propagates */
  86:     double      propself;   /* how much self time propagates */
  87:     double      propchild;  /* how much child time propagates */
  88:     bool        printflag;  /* should this be printed? */
  89:     int         index;      /* index in the graph list */
  90:     int         toporder;   /* graph call chain top-sort order */
  91:     int         cycleno;    /* internal number of cycle on */
  92:     struct nl       *cyclehead; /* pointer to head of cycle */
  93:     struct nl       *cnext;     /* pointer to next member of cycle */
  94:     arctype     *parents;   /* list of caller arcs */
  95:     arctype     *children;  /* list of callee arcs */
  96: };
  97: typedef struct nl   nltype;
  98: 
  99: nltype  *nl;            /* the whole namelist */
 100: nltype  *npe;           /* the virtual end of the namelist */
 101: int nname;          /* the number of function names */
 102: 
 103:     /*
 104:      *	flag which marks a nl entry as topologically ``busy''
 105:      *	flag which marks a nl entry as topologically ``not_numbered''
 106:      */
 107: #define DFN_BUSY    -1
 108: #define DFN_NAN     0
 109: 
 110:     /*
 111:      *	namelist entries for cycle headers.
 112:      *	the number of discovered cycles.
 113:      */
 114: nltype  *cyclenl;       /* cycle header namelist */
 115: int ncycle;         /* number of cycles discovered */
 116: 
 117:     /*
 118:      * The header on the gmon.out file.
 119:      * gmon.out consists of one of these headers,
 120:      * and then an array of ncnt samples
 121:      * representing the discretized program counter values.
 122:      *	this should be a struct phdr, but since everything is done
 123:      *	as UNITs, this is in UNITs too.
 124:      */
 125: struct hdr {
 126:     UNIT    *lowpc;
 127:     UNIT    *highpc;
 128:     int ncnt;
 129: };
 130: 
 131: struct hdr  h;
 132: 
 133: int debug;
 134: 
 135:     /*
 136:      * Each discretized pc sample has
 137:      * a count of the number of samples in its range
 138:      */
 139: unsigned UNIT   *samples;
 140: 
 141: unsigned long   s_lowpc;    /* lowpc from the profile file */
 142: unsigned long   s_highpc;   /* highpc from the profile file */
 143: unsigned lowpc, highpc;     /* range profiled, in UNIT's */
 144: unsigned sampbytes;     /* number of bytes of samples */
 145: int nsamples;       /* number of samples */
 146: double  actime;         /* accumulated time thus far for putprofline */
 147: double  totime;         /* total time for all routines */
 148: double  printtime;      /* total of time being printed */
 149: double  scale;          /* scale factor converting samples to pc
 150: 				   values: each sample covers scale bytes */
 151: char    *strtab;        /* string table in core */
 152: off_t   ssiz;           /* size of the string table */
 153: struct  exec xbuf;      /* exec header of a.out */
 154: unsigned char   *textspace;     /* text space of a.out in core */
 155: 
 156:     /*
 157:      *	option flags, from a to z.
 158:      */
 159: bool    aflag;              /* suppress static functions */
 160: bool    bflag;              /* blurbs, too */
 161: bool    cflag;              /* discovered call graph, too */
 162: bool    dflag;              /* debugging options */
 163: bool    eflag;              /* specific functions excluded */
 164: bool    Eflag;              /* functions excluded with time */
 165: bool    fflag;              /* specific functions requested */
 166: bool    Fflag;              /* functions requested with time */
 167: bool    sflag;              /* sum multiple gmon.out files */
 168: bool    zflag;              /* zero time/called functions, too */
 169: 
 170:     /*
 171:      *	structure for various string lists
 172:      */
 173: struct stringlist {
 174:     struct stringlist   *next;
 175:     char        *string;
 176: };
 177: struct stringlist   *elist;
 178: struct stringlist   *Elist;
 179: struct stringlist   *flist;
 180: struct stringlist   *Flist;
 181: 
 182:     /*
 183:      *	function declarations
 184:      */
 185:         addarc();
 186: int     arccmp();
 187: arctype     *arclookup();
 188:         asgnsamples();
 189:         printblurb();
 190:         cyclelink();
 191:         dfn();
 192: bool        dfn_busy();
 193:         dfn_findcycle();
 194: bool        dfn_numbered();
 195:         dfn_post_visit();
 196:         dfn_pre_visit();
 197:         dfn_self_cycle();
 198: nltype      **doarcs();
 199:         done();
 200:         findcalls();
 201:         flatprofheader();
 202:         flatprofline();
 203: bool        funcsymbol();
 204:         getnfile();
 205:         getpfile();
 206:         getstrtab();
 207:         getsymtab();
 208:         gettextspace();
 209:         gprofheader();
 210:         gprofline();
 211:         main();
 212: unsigned long   max();
 213: int     membercmp();
 214: unsigned long   min();
 215: nltype      *nllookup();
 216: FILE        *openpfile();
 217: long        operandlength();
 218: operandenum operandmode();
 219: char        *operandname();
 220:         printchildren();
 221:         printcycle();
 222:         printgprof();
 223:         printmembers();
 224:         printname();
 225:         printparents();
 226:         printprof();
 227:         readsamples();
 228: unsigned long   reladdr();
 229:         sortchildren();
 230:         sortmembers();
 231:         sortparents();
 232:         tally();
 233:         timecmp();
 234:         topcmp();
 235: int     totalcmp();
 236:         valcmp();
 237: 
 238: #define LESSTHAN    -1
 239: #define EQUALTO     0
 240: #define GREATERTHAN 1
 241: 
 242: #define DFNDEBUG    1
 243: #define CYCLEDEBUG  2
 244: #define ARCDEBUG    4
 245: #define TALLYDEBUG  8
 246: #define TIMEDEBUG   16
 247: #define SAMPLEDEBUG 32
 248: #define AOUTDEBUG   64
 249: #define CALLSDEBUG  128
 250: #define LOOKUPDEBUG 256
 251: #define PROPDEBUG   512
 252: #define ANYDEBUG    1024

Defined variables

Eflag defined in line 164; used 2 times
Elist defined in line 178; used 4 times
Fflag defined in line 166; used 2 times
Flist defined in line 180; used 3 times
a_outname defined in line 41; used 9 times
actime defined in line 146; used 4 times
aflag defined in line 159; used 3 times
bflag defined in line 160; used 4 times
cflag defined in line 161; used 3 times
cyclenl defined in line 114; used 6 times
dflag defined in line 162; used 1 times
eflag defined in line 163; used 3 times
elist defined in line 177; used 5 times
fflag defined in line 165; used 3 times
flist defined in line 179; used 4 times
gmonname defined in line 44; used 4 times
h defined in line 131; used 14 times
highpc defined in line 143; used 9 times
hz defined in line 38; used 19 times
lowpc defined in line 143; used 13 times
ncycle defined in line 115; used 12 times
nl defined in line 99; used 27 times
nname defined in line 101; used 30 times
npe defined in line 100; used 13 times
nsamples defined in line 145; used 9 times
printtime defined in line 148; used 8 times
s_highpc defined in line 142; used 6 times
s_lowpc defined in line 141; used 5 times
sampbytes defined in line 144; used 5 times
samples defined in line 139; used 6 times
scale defined in line 149; used 10 times
sflag defined in line 167; used 2 times
strtab defined in line 151; used 7 times
textspace defined in line 154; used 10 times
totime defined in line 147; used 7 times
xbuf defined in line 153; used 14 times
zflag defined in line 168; used 4 times

Defined struct's

arcstruct defined in line 61; used 6 times
hdr defined in line 125; used 8 times
nl defined in line 77; used 14 times
stringlist defined in line 173; used 40 times

Defined typedef's

UNIT defined in line 40; used 17 times
bool defined in line 31; used 19 times
nltype defined in line 97; used 105 times

Defined macros

ANYDEBUG defined in line 252; used 1 times
AOUTDEBUG defined in line 248; used 3 times
ARCDEBUG defined in line 244; never used
A_OUTNAME defined in line 42; used 1 times
CALLG_BLURB defined in line 52; used 1 times
CALLSDEBUG defined in line 249; used 5 times
CYCLEDEBUG defined in line 243; used 1 times
DFN_BUSY defined in line 107; used 2 times
DFN_NAN defined in line 108; used 6 times
EQUALTO defined in line 239; used 4 times
FLAT_BLURB defined in line 51; used 1 times
GMONNAME defined in line 45; used 1 times
GMONSUM defined in line 46; used 1 times
GREATERTHAN defined in line 240; used 10 times
LESSTHAN defined in line 238; used 9 times
LOOKUPDEBUG defined in line 250; used 3 times
PROPDEBUG defined in line 251; used 4 times
SAMPLEDEBUG defined in line 247; used 7 times
TALLYDEBUG defined in line 245; used 3 times
TIMEDEBUG defined in line 246; used 1 times
TRUE defined in line 33; used 20 times

Usage of this include

Last modified: 1985-06-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2079
Valid CSS Valid XHTML 1.0 Strict