[BACK]Return to gprof.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / gprof

Annotation of src/usr.bin/gprof/gprof.h, Revision 1.3

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