home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / gprof / gprof.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-24  |  8.2 KB  |  304 lines

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