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

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