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

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