[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.4

1.4     ! rahnds      1: /*     $OpenBSD: gprof.h,v 1.3 1996/06/26 05:33:51 deraadt 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"
1.4     ! rahnds     64: #endif
        !            65: #if powerpc
        !            66: #   include "powerpc.h"
1.1       deraadt    67: #endif
                     68: #if pmax
                     69: #   include "pmax.h"
                     70: #endif
                     71: #if sparc
                     72: #   include "sparc.h"
                     73: #endif
                     74: #if tahoe
                     75: #   include "tahoe.h"
                     76: #endif
                     77: #if vax
                     78: #   include "vax.h"
                     79: #endif
                     80:
                     81:
                     82:     /*
                     83:      * who am i, for error messages.
                     84:      */
                     85: char   *whoami;
                     86:
                     87:     /*
                     88:      * booleans
                     89:      */
                     90: typedef int    bool;
                     91: #define        FALSE   0
                     92: #define        TRUE    1
                     93:
                     94:     /*
                     95:      * ticks per second
                     96:      */
                     97: long   hz;
                     98:
                     99: typedef        u_short UNIT;           /* unit of profiling */
                    100: char   *a_outname;
                    101: #define        A_OUTNAME               "a.out"
                    102:
                    103: char   *gmonname;
                    104: #define        GMONNAME                "gmon.out"
                    105: #define        GMONSUM                 "gmon.sum"
                    106:
                    107:     /*
                    108:      * a constructed arc,
                    109:      *     with pointers to the namelist entry of the parent and the child,
                    110:      *     a count of how many times this arc was traversed,
                    111:      *     and pointers to the next parent of this child and
                    112:      *         the next child of this parent.
                    113:      */
                    114: struct arcstruct {
                    115:     struct nl          *arc_parentp;   /* pointer to parent's nl entry */
                    116:     struct nl          *arc_childp;    /* pointer to child's nl entry */
                    117:     long               arc_count;      /* num calls from parent to child */
                    118:     double             arc_time;       /* time inherited along arc */
                    119:     double             arc_childtime;  /* childtime inherited along arc */
                    120:     struct arcstruct   *arc_parentlist; /* parents-of-this-child list */
                    121:     struct arcstruct   *arc_childlist; /* children-of-this-parent list */
                    122:     struct arcstruct   *arc_next;      /* list of arcs on cycle */
                    123:     unsigned short     arc_cyclecnt;   /* num cycles involved in */
                    124:     unsigned short     arc_flags;      /* see below */
                    125: };
                    126: typedef struct arcstruct       arctype;
                    127:
                    128:     /*
                    129:      * arc flags
                    130:      */
                    131: #define        DEADARC 0x01    /* time should not propagate across the arc */
                    132: #define        ONLIST  0x02    /* arc is on list of arcs in cycles */
                    133:
                    134:     /*
                    135:      * The symbol table;
                    136:      * for each external in the specified file we gather
                    137:      * its address, the number of calls and compute its share of cpu time.
                    138:      */
                    139: struct nl {
                    140:     char               *name;          /* the name */
                    141:     unsigned long      value;          /* the pc entry point */
                    142:     unsigned long      svalue;         /* entry point aligned to histograms */
                    143:     double             time;           /* ticks in this routine */
                    144:     double             childtime;      /* cumulative ticks in children */
                    145:     long               ncall;          /* how many times called */
                    146:     long               npropcall;      /* times called by live arcs */
                    147:     long               selfcalls;      /* how many calls to self */
                    148:     double             propfraction;   /* what % of time propagates */
                    149:     double             propself;       /* how much self time propagates */
                    150:     double             propchild;      /* how much child time propagates */
                    151:     short              printflag;      /* should this be printed? */
                    152:     short              flags;          /* see below */
                    153:     int                        index;          /* index in the graph list */
                    154:     int                        toporder;       /* graph call chain top-sort order */
                    155:     int                        cycleno;        /* internal number of cycle on */
                    156:     int                        parentcnt;      /* number of live parent arcs */
                    157:     struct nl          *cyclehead;     /* pointer to head of cycle */
                    158:     struct nl          *cnext;         /* pointer to next member of cycle */
                    159:     arctype            *parents;       /* list of caller arcs */
                    160:     arctype            *children;      /* list of callee arcs */
                    161: };
                    162: typedef struct nl      nltype;
                    163:
                    164: nltype *nl;                    /* the whole namelist */
                    165: nltype *npe;                   /* the virtual end of the namelist */
                    166: int    nname;                  /* the number of function names */
                    167:
                    168: #define        HASCYCLEXIT     0x08    /* node has arc exiting from cycle */
                    169: #define        CYCLEHEAD       0x10    /* node marked as head of a cycle */
                    170: #define        VISITED         0x20    /* node visited during a cycle */
                    171:
                    172:     /*
                    173:      * The cycle list.
                    174:      * for each subcycle within an identified cycle, we gather
                    175:      * its size and the list of included arcs.
                    176:      */
                    177: struct cl {
                    178:     int                size;           /* length of cycle */
                    179:     struct cl  *next;          /* next member of list */
                    180:     arctype    *list[1];       /* list of arcs in cycle */
                    181:     /* actually longer */
                    182: };
                    183: typedef struct cl cltype;
                    184:
                    185: arctype        *archead;               /* the head of arcs in current cycle list */
                    186: cltype *cyclehead;             /* the head of the list */
                    187: int    cyclecnt;               /* the number of cycles found */
                    188: #define        CYCLEMAX        100     /* maximum cycles before cutting one of them */
                    189:
                    190:     /*
                    191:      * flag which marks a nl entry as topologically ``busy''
                    192:      * flag which marks a nl entry as topologically ``not_numbered''
                    193:      */
                    194: #define        DFN_BUSY        -1
                    195: #define        DFN_NAN         0
                    196:
                    197:     /*
                    198:      * namelist entries for cycle headers.
                    199:      * the number of discovered cycles.
                    200:      */
                    201: nltype *cyclenl;               /* cycle header namelist */
                    202: int    ncycle;                 /* number of cycles discovered */
                    203:
                    204:     /*
                    205:      * The header on the gmon.out file.
                    206:      * gmon.out consists of a struct phdr (defined in gmon.h)
                    207:      * and then an array of ncnt samples representing the
                    208:      * discretized program counter values.
                    209:      *
                    210:      * Backward compatible old style header
                    211:      */
                    212: struct ophdr {
                    213:     UNIT       *lpc;
                    214:     UNIT       *hpc;
                    215:     int                ncnt;
                    216: };
                    217:
                    218: int    debug;
                    219:
                    220:     /*
                    221:      * Each discretized pc sample has
                    222:      * a count of the number of samples in its range
                    223:      */
                    224: UNIT   *samples;
                    225:
                    226: unsigned long  s_lowpc;        /* lowpc from the profile file */
                    227: unsigned long  s_highpc;       /* highpc from the profile file */
                    228: unsigned lowpc, highpc;                /* range profiled, in UNIT's */
                    229: unsigned sampbytes;            /* number of bytes of samples */
                    230: int    nsamples;               /* number of samples */
                    231: double actime;                 /* accumulated time thus far for putprofline */
                    232: double totime;                 /* total time for all routines */
                    233: double printtime;              /* total of time being printed */
                    234: double scale;                  /* scale factor converting samples to pc
                    235:                                   values: each sample covers scale bytes */
                    236: char   *strtab;                /* string table in core */
                    237: long   ssiz;                   /* size of the string table */
                    238: struct exec xbuf;              /* exec header of a.out */
                    239: unsigned char  *textspace;     /* text space of a.out in core */
                    240: int    cyclethreshold;         /* with -C, minimum cycle size to ignore */
                    241:
                    242:     /*
                    243:      * option flags, from a to z.
                    244:      */
                    245: bool   aflag;                          /* suppress static functions */
                    246: bool   bflag;                          /* blurbs, too */
                    247: bool   cflag;                          /* discovered call graph, too */
                    248: bool   Cflag;                          /* find cut-set to eliminate cycles */
                    249: bool   dflag;                          /* debugging options */
                    250: bool   eflag;                          /* specific functions excluded */
                    251: bool   Eflag;                          /* functions excluded with time */
                    252: bool   fflag;                          /* specific functions requested */
                    253: bool   Fflag;                          /* functions requested with time */
                    254: bool   kflag;                          /* arcs to be deleted */
                    255: bool   sflag;                          /* sum multiple gmon.out files */
                    256: bool   zflag;                          /* zero time/called functions, too */
                    257:
                    258:     /*
                    259:      * structure for various string lists
                    260:      */
                    261: struct stringlist {
                    262:     struct stringlist  *next;
                    263:     char               *string;
                    264: };
                    265: struct stringlist      *elist;
                    266: struct stringlist      *Elist;
                    267: struct stringlist      *flist;
                    268: struct stringlist      *Flist;
                    269: struct stringlist      *kfromlist;
                    270: struct stringlist      *ktolist;
                    271:
                    272:     /*
                    273:      * function declarations
                    274:      */
                    275: /*
                    276:                addarc();
                    277: */
                    278: int            arccmp();
                    279: arctype                *arclookup();
                    280: /*
                    281:                asgnsamples();
                    282:                printblurb();
                    283:                cyclelink();
                    284:                dfn();
                    285: */
                    286: bool           dfn_busy();
                    287: /*
                    288:                dfn_findcycle();
                    289: */
                    290: bool           dfn_numbered();
                    291: /*
                    292:                dfn_post_visit();
                    293:                dfn_pre_visit();
                    294:                dfn_self_cycle();
                    295: */
                    296: nltype         **doarcs();
                    297: /*
                    298:                done();
                    299:                findcalls();
                    300:                flatprofheader();
                    301:                flatprofline();
                    302: */
                    303: bool           funcsymbol();
                    304: /*
                    305:                getnfile();
                    306:                getpfile();
                    307:                getstrtab();
                    308:                getsymtab();
                    309:                gettextspace();
                    310:                gprofheader();
                    311:                gprofline();
                    312:                main();
                    313: */
                    314: unsigned long  max();
                    315: int            membercmp();
                    316: unsigned long  min();
                    317: nltype         *nllookup();
                    318: FILE           *openpfile();
                    319: long           operandlength();
                    320: operandenum    operandmode();
                    321: char           *operandname();
                    322: /*
                    323:                printchildren();
                    324:                printcycle();
                    325:                printgprof();
                    326:                printmembers();
                    327:                printname();
                    328:                printparents();
                    329:                printprof();
                    330:                readsamples();
                    331: */
                    332: unsigned long  reladdr();
                    333: /*
                    334:                sortchildren();
                    335:                sortmembers();
                    336:                sortparents();
                    337:                tally();
                    338:                timecmp();
                    339:                topcmp();
                    340: */
                    341: int            totalcmp();
                    342: /*
                    343:                valcmp();
                    344: */
                    345:
                    346: #define        LESSTHAN        -1
                    347: #define        EQUALTO         0
                    348: #define        GREATERTHAN     1
                    349:
                    350: #define        DFNDEBUG        1
                    351: #define        CYCLEDEBUG      2
                    352: #define        ARCDEBUG        4
                    353: #define        TALLYDEBUG      8
                    354: #define        TIMEDEBUG       16
                    355: #define        SAMPLEDEBUG     32
                    356: #define        AOUTDEBUG       64
                    357: #define        CALLDEBUG       128
                    358: #define        LOOKUPDEBUG     256
                    359: #define        PROPDEBUG       512
                    360: #define        BREAKCYCLE      1024
                    361: #define        SUBCYCLELIST    2048
                    362: #define        ANYDEBUG        4096