since times are stored in arcs, calloc instead of malloc them.
[unix-history] / usr / src / usr.bin / gprof / gprof.h
CommitLineData
29da1d26 1 /* sccsid: @(#)gprof.h 1.3 (Berkeley) %G% */
a8242a8d
PK
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
15typedef short UNIT; /* unit of profiling */
16char *a_outname;
17#define A_OUTNAME "a.out"
18
31f0a970
PK
19char *gmonname;
20#define GMONNAME "gmon.out"
a8242a8d
PK
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 */
29struct 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};
38typedef 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 */
45struct 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 */
55struct nl {
56 char *name; /* the name */
57 unsigned long value; /* the pc entry point */
58 double time; /* ticks in this routine */
31f0a970 59 double childtime; /* cumulative ticks in children */
a8242a8d
PK
60 long ncall; /* how many times called */
61 long selfcalls; /* how many calls to self */
31f0a970
PK
62 int index; /* index in the graph list */
63 int toporder; /* graph call chain top-sort order */
a8242a8d
PK
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};
70typedef struct nl nltype;
71
72nltype *nl; /* the whole namelist */
73nltype *npe; /* the virtual end of the namelist */
74int 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 )
87int ncycles; /* maximum allocated cycle headers */
88int cyclemax; /* number of cycles discovered */
89
90/*
31f0a970
PK
91 * The header on the gmon.out file.
92 * gmon.out consists of one of these headers,
a8242a8d
PK
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 */
98struct hdr {
99 UNIT *lowpc;
100 UNIT *highpc;
101 int ncnt;
102};
103
104struct hdr h;
105
106int debug;
107
108/*
109 * Each discretized pc sample has
110 * a count of the number of samples in its range
111 */
112unsigned UNIT *samples;
113
114unsigned lowpc, highpc; /* range profiled */
115unsigned sampbytes; /* number of bytes of samples */
116int nsamples; /* number of samples */
117double actime; /* accumulated time thus far for putprofline */
118double totime; /* total time for all routines */
119double scale; /* scale factor converting samples to pc
120 values: each sample covers scale bytes */
121char *strtab; /* string table in core */
122off_t ssiz; /* size of the string table */
123struct exec xbuf; /* exec header of a.out */
29da1d26 124unsigned char *textspace; /* text space of a.out in core */
a8242a8d
PK
125
126int zflg;
29da1d26 127int cflag;
a8242a8d
PK
128
129 /*
130 * booleans
131 */
132typedef int bool;
133#define FALSE 0
134#define TRUE 1
135
136int timecmp();
137int valcmp();
138int totalcmp();
139
140nltype *nllookup();
141arctype *arclookup();
142bool 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
29da1d26
PK
155#define CALLSDEBUG 128
156#define LOOKUPDEBUG 256
157#define ANYDEBUG 512