| 1 | /* sccsid: @(#)gprof.h 1.3 (Berkeley) %G% */ |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <sys/stat.h> |
| 6 | #include <a.out.h> |
| 7 | #include <pagsiz.h> |
| 8 | #include "monitor.h" |
| 9 | |
| 10 | /* |
| 11 | * ticks per second |
| 12 | */ |
| 13 | #define HZ 60 |
| 14 | |
| 15 | typedef short UNIT; /* unit of profiling */ |
| 16 | char *a_outname; |
| 17 | #define A_OUTNAME "a.out" |
| 18 | |
| 19 | char *gmonname; |
| 20 | #define GMONNAME "gmon.out" |
| 21 | |
| 22 | /* |
| 23 | * a constructed arc, |
| 24 | * with pointers to the namelist entry of the parent and the child, |
| 25 | * a count of how many times this arc was traversed, |
| 26 | * and pointers to the next parent of this child and |
| 27 | * the next child of this parent. |
| 28 | */ |
| 29 | struct arcstruct { |
| 30 | struct nl *arc_parentp; /* pointer to parent's nl entry */ |
| 31 | struct nl *arc_childp; /* pointer to child's nl entry */ |
| 32 | long arc_count; /* how calls from parent to child */ |
| 33 | double arc_time; /* time inherited along arc */ |
| 34 | double arc_childtime; /* childtime inherited along arc */ |
| 35 | struct arcstruct *arc_parentlist; /* parents-of-this-child list */ |
| 36 | struct arcstruct *arc_childlist; /* children-of-this-parent list */ |
| 37 | }; |
| 38 | typedef struct arcstruct arctype; |
| 39 | |
| 40 | /* |
| 41 | * a raw arc, |
| 42 | * with pointers to the calling site and the called site |
| 43 | * and a count. |
| 44 | */ |
| 45 | struct rawarc { |
| 46 | unsigned long raw_frompc; |
| 47 | unsigned long raw_selfpc; |
| 48 | long raw_count; |
| 49 | }; |
| 50 | /* |
| 51 | * The symbol table; |
| 52 | * for each external in the specified file we gather |
| 53 | * its address, the number of calls and compute its share of cpu time. |
| 54 | */ |
| 55 | struct nl { |
| 56 | char *name; /* the name */ |
| 57 | unsigned long value; /* the pc entry point */ |
| 58 | double time; /* ticks in this routine */ |
| 59 | double childtime; /* cumulative ticks in children */ |
| 60 | long ncall; /* how many times called */ |
| 61 | long selfcalls; /* how many calls to self */ |
| 62 | int index; /* index in the graph list */ |
| 63 | int toporder; /* graph call chain top-sort order */ |
| 64 | int cycleno; /* internal number of cycle on */ |
| 65 | struct nl *cyclehead; /* pointer to head of cycle */ |
| 66 | struct nl *cnext; /* pointer to next member of cycle */ |
| 67 | arctype *parents; /* list of caller arcs */ |
| 68 | arctype *children; /* list of callee arcs */ |
| 69 | }; |
| 70 | typedef struct nl nltype; |
| 71 | |
| 72 | nltype *nl; /* the whole namelist */ |
| 73 | nltype *npe; /* the virtual end of the namelist */ |
| 74 | int nname; /* the number of function names */ |
| 75 | |
| 76 | /* |
| 77 | * flag which marks a nl entry as topologically ``busy'' |
| 78 | */ |
| 79 | #define DFN_BUSY -1 |
| 80 | |
| 81 | /* |
| 82 | * the number of cycles is estimated as this fraction of nnames |
| 83 | * ncycles, the number of allocated cycle namelist entries, |
| 84 | * not to be confused with cyclemax, the number of discovered cycles. |
| 85 | */ |
| 86 | #define CYCLEFRACTION ( 0.10 ) |
| 87 | int ncycles; /* maximum allocated cycle headers */ |
| 88 | int cyclemax; /* number of cycles discovered */ |
| 89 | |
| 90 | /* |
| 91 | * The header on the gmon.out file. |
| 92 | * gmon.out consists of one of these headers, |
| 93 | * and then an array of ncnt samples |
| 94 | * representing the discretized program counter values. |
| 95 | * this should be a struct phdr, but since everything is done |
| 96 | * as UNITs, this is in UNITs too. |
| 97 | */ |
| 98 | struct hdr { |
| 99 | UNIT *lowpc; |
| 100 | UNIT *highpc; |
| 101 | int ncnt; |
| 102 | }; |
| 103 | |
| 104 | struct hdr h; |
| 105 | |
| 106 | int debug; |
| 107 | |
| 108 | /* |
| 109 | * Each discretized pc sample has |
| 110 | * a count of the number of samples in its range |
| 111 | */ |
| 112 | unsigned UNIT *samples; |
| 113 | |
| 114 | unsigned lowpc, highpc; /* range profiled */ |
| 115 | unsigned sampbytes; /* number of bytes of samples */ |
| 116 | int nsamples; /* number of samples */ |
| 117 | double actime; /* accumulated time thus far for putprofline */ |
| 118 | double totime; /* total time for all routines */ |
| 119 | double scale; /* scale factor converting samples to pc |
| 120 | values: each sample covers scale bytes */ |
| 121 | char *strtab; /* string table in core */ |
| 122 | off_t ssiz; /* size of the string table */ |
| 123 | struct exec xbuf; /* exec header of a.out */ |
| 124 | unsigned char *textspace; /* text space of a.out in core */ |
| 125 | |
| 126 | int zflg; |
| 127 | int cflag; |
| 128 | |
| 129 | /* |
| 130 | * booleans |
| 131 | */ |
| 132 | typedef int bool; |
| 133 | #define FALSE 0 |
| 134 | #define TRUE 1 |
| 135 | |
| 136 | int timecmp(); |
| 137 | int valcmp(); |
| 138 | int totalcmp(); |
| 139 | |
| 140 | nltype *nllookup(); |
| 141 | arctype *arclookup(); |
| 142 | bool dfn_busy(); |
| 143 | |
| 144 | #define LESSTHAN -1 |
| 145 | #define EQUALTO 0 |
| 146 | #define GREATERTHAN 1 |
| 147 | |
| 148 | #define DFNDEBUG 1 |
| 149 | #define CYCLEDEBUG 2 |
| 150 | #define ARCDEBUG 4 |
| 151 | #define TALLYDEBUG 8 |
| 152 | #define TIMEDEBUG 16 |
| 153 | #define SAMPLEDEBUG 32 |
| 154 | #define AOUTDEBUG 64 |
| 155 | #define CALLSDEBUG 128 |
| 156 | #define LOOKUPDEBUG 256 |
| 157 | #define ANYDEBUG 512 |