1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 2004
5 * Macros for profiling operations in STG code
7 * ---------------------------------------------------------------------------*/
12 /* -----------------------------------------------------------------------------
14 * ---------------------------------------------------------------------------*/
15 typedef struct _CostCentre {
21 /* used for accumulating costs at the end of the run... */
27 struct _CostCentre *link;
31 typedef struct _CostCentreStack {
35 struct _CostCentreStack *prevStack;
36 struct _IndexTable *indexTable;
42 StgWord inherited_ticks;
43 StgWord64 inherited_alloc;
49 /* -----------------------------------------------------------------------------
50 * The rest is PROFILING only...
51 * ---------------------------------------------------------------------------*/
53 #if defined(PROFILING)
55 /* -----------------------------------------------------------------------------
57 * ---------------------------------------------------------------------------*/
59 #define EMPTY_STACK NULL
60 #define EMPTY_TABLE NULL
62 /* Constants used to set sumbsumed flag on CostCentres */
64 #define CC_IS_CAF 'c' /* 'c' => *is* a CAF cc */
65 #define CC_IS_BORING 'B' /* 'B' => *not* a CAF/sub cc */
68 /* -----------------------------------------------------------------------------
70 * ---------------------------------------------------------------------------*/
72 typedef struct _IndexTable {
75 struct _IndexTable *next;
76 unsigned int back_edge;
80 /* -----------------------------------------------------------------------------
81 Pre-defined cost centres and cost centre stacks
82 -------------------------------------------------------------------------- */
84 extern CostCentreStack * RTS_VAR(CCCS); /* current CCS */
88 extern StgWord CC_MAIN[];
89 extern StgWord CCS_MAIN[]; /* Top CCS */
91 extern StgWord CC_SYSTEM[];
92 extern StgWord CCS_SYSTEM[]; /* RTS costs */
94 extern StgWord CC_GC[];
95 extern StgWord CCS_GC[]; /* Garbage collector costs */
97 extern StgWord CC_SUBSUMED[];
98 extern StgWord CCS_SUBSUMED[]; /* Costs are subsumed by caller */
100 extern StgWord CC_OVERHEAD[];
101 extern StgWord CCS_OVERHEAD[]; /* Profiling overhead */
103 extern StgWord CC_DONT_CARE[];
104 extern StgWord CCS_DONT_CARE[]; /* shouldn't ever get set */
108 extern CostCentre CC_MAIN[];
109 extern CostCentreStack CCS_MAIN[]; /* Top CCS */
111 extern CostCentre CC_SYSTEM[];
112 extern CostCentreStack CCS_SYSTEM[]; /* RTS costs */
114 extern CostCentre CC_GC[];
115 extern CostCentreStack CCS_GC[]; /* Garbage collector costs */
117 extern CostCentre CC_SUBSUMED[];
118 extern CostCentreStack CCS_SUBSUMED[]; /* Costs are subsumed by caller */
120 extern CostCentre CC_OVERHEAD[];
121 extern CostCentreStack CCS_OVERHEAD[]; /* Profiling overhead */
123 extern CostCentre CC_DONT_CARE[];
124 extern CostCentreStack CCS_DONT_CARE[]; /* shouldn't ever get set */
126 #endif // IN_STG_CODE
128 extern unsigned int RTS_VAR(CC_ID); /* global ids */
129 extern unsigned int RTS_VAR(CCS_ID);
130 extern unsigned int RTS_VAR(HP_ID);
132 extern unsigned int RTS_VAR(era);
134 /* -----------------------------------------------------------------------------
136 * ---------------------------------------------------------------------------*/
138 void EnterFunCCS ( CostCentreStack *ccsfn );
139 CostCentreStack *PushCostCentre ( CostCentreStack *, CostCentre * );
140 CostCentreStack *AppendCCS ( CostCentreStack *ccs1, CostCentreStack *ccs2 );
142 extern unsigned int RTS_VAR(entering_PAP);
144 /* -----------------------------------------------------------------------------
147 Cost centres are registered at startup by calling a registering
148 routine in each module. Each module registers its cost centres and
149 calls the registering routine for all imported modules. The RTS calls
150 the registering routine for the module Main. This registering must be
151 done before initialisation since the evaluation required for
152 initialisation may use the cost centres.
154 As the code for each module uses tail calls we use an auxiliary stack
155 (in the heap) to record imported modules still to be registered. At
156 the bottom of the stack is NULL which indicates that
157 @miniInterpretEnd@ should be resumed.
159 @START_REGISTER@ and @END_REGISTER@ are special macros used to
160 delimit the function. @END_REGISTER@ pops the next registering
161 routine off the stack and jumps to it. @REGISTER_CC@ registers a cost
162 centre. @REGISTER_IMPORT@ pushes a modules registering routine onto
165 -------------------------------------------------------------------------- */
167 extern CostCentre * RTS_VAR(CC_LIST); /* registered CC list */
168 extern CostCentreStack * RTS_VAR(CCS_LIST); /* registered CCS list */
170 #define REGISTER_CC(cc) \
172 extern CostCentre cc[]; \
173 if ((cc)->link == (CostCentre *)0) { \
174 (cc)->link = CC_LIST; \
176 (cc)->ccID = CC_ID++; \
179 #define REGISTER_CCS(ccs) \
181 extern CostCentreStack ccs[]; \
182 if ((ccs)->prevStack == (CostCentreStack *)0) { \
183 (ccs)->prevStack = CCS_LIST; \
185 (ccs)->ccsID = CCS_ID++; \
188 /* -----------------------------------------------------------------------------
189 * Declaring Cost Centres & Cost Centre Stacks.
190 * -------------------------------------------------------------------------- */
192 # define CC_DECLARE(cc_ident,name,module,caf,is_local) \
193 is_local CostCentre cc_ident[1] \
202 # define CCS_DECLARE(ccs_ident,cc_ident,is_local) \
203 is_local CostCentreStack ccs_ident[1] \
212 inherited_ticks : 0, \
213 inherited_alloc : 0, \
217 /* -----------------------------------------------------------------------------
218 * Time / Allocation Macros
219 * ---------------------------------------------------------------------------*/
221 /* eliminate profiling overhead from allocation costs */
222 #define CCS_ALLOC(ccs, size) (ccs)->mem_alloc += ((size)-sizeofW(StgProfHeader))
224 #else /* !PROFILING */
226 #define CCS_ALLOC(ccs, amount) doNothing()
228 #endif /* PROFILING */
230 #endif /* STGPROF_H */