Adding TcGadt.lhs
[ghc-hetmet.git] / rts / Ticky.c
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The AQUA project, Glasgow University, 1992-1997
4  * (c) The GHC Team, 1998-1999
5  *
6  * Ticky-ticky profiling
7  *-------------------------------------------------------------------------- */
8
9 #if defined(TICKY_TICKY)
10
11 #define TICKY_C                 /* define those variables */
12 #include "PosixSource.h"
13 #include "Rts.h"
14 #include "RtsFlags.h"
15 #include "Ticky.h"
16
17 /* -----------------------------------------------------------------------------
18    Print out all the counters
19    -------------------------------------------------------------------------- */
20
21 static void printRegisteredCounterInfo (FILE *); /* fwd decl */
22
23 #define INTAVG(a,b) ((b == 0) ? 0.0 : ((double) (a) / (double) (b)))
24 #define PC(a)       (100.0 * a)
25
26 #define AVG(thing) \
27         StgDouble avg##thing  = INTAVG(tot##thing,ctr##thing)
28
29 void
30 PrintTickyInfo(void)
31 {
32   unsigned long i;
33   unsigned long tot_allocs = /* total number of things allocated */
34         ALLOC_FUN_ctr + ALLOC_SE_THK_ctr + ALLOC_UP_THK_ctr + ALLOC_CON_ctr + ALLOC_TUP_ctr +
35         + ALLOC_TSO_ctr + ALLOC_BH_ctr  + ALLOC_PAP_ctr + ALLOC_PRIM_ctr
36 #ifdef PAR
37         + ALLOC_FMBQ_ctr + ALLOC_FME_ctr + ALLOC_BF_ctr
38 #endif
39       ; 
40
41   unsigned long tot_adm_wds = /* total number of admin words allocated */
42         ALLOC_FUN_adm + ALLOC_THK_adm + ALLOC_CON_adm + ALLOC_TUP_adm
43         + ALLOC_TSO_adm + ALLOC_BH_adm  + ALLOC_PAP_adm + ALLOC_PRIM_adm
44 #ifdef PAR
45         + ALLOC_FMBQ_adm + ALLOC_FME_adm + ALLOC_BF_adm
46 #endif
47       ;
48
49   unsigned long tot_gds_wds = /* total number of words of ``good stuff'' allocated */
50         ALLOC_FUN_gds + ALLOC_THK_gds + ALLOC_CON_gds + ALLOC_TUP_gds
51         + ALLOC_TSO_gds + ALLOC_BH_gds  + ALLOC_PAP_gds + ALLOC_PRIM_gds
52 #ifdef PAR
53         + ALLOC_FMBQ_gds + ALLOC_FME_gds + ALLOC_BF_gds
54 #endif
55       ;
56
57   unsigned long tot_slp_wds = /* total number of ``slop'' words allocated */
58         ALLOC_FUN_slp + ALLOC_THK_slp + ALLOC_CON_slp + ALLOC_TUP_slp
59         + ALLOC_TSO_slp + ALLOC_BH_slp  + ALLOC_PAP_slp + ALLOC_PRIM_slp
60 #ifdef PAR
61         + ALLOC_FMBQ_slp + ALLOC_FME_slp + ALLOC_BF_slp
62 #endif
63       ;
64
65   unsigned long tot_wds = /* total words */
66         tot_adm_wds + tot_gds_wds + tot_slp_wds;
67
68   unsigned long tot_thk_enters = ENT_STATIC_THK_ctr + ENT_DYN_THK_ctr;
69   unsigned long tot_con_enters = ENT_STATIC_CON_ctr + ENT_DYN_CON_ctr;
70   unsigned long tot_fun_direct_enters = ENT_STATIC_FUN_DIRECT_ctr + ENT_DYN_FUN_DIRECT_ctr;
71   unsigned long tot_ind_enters = ENT_STATIC_IND_ctr + ENT_DYN_IND_ctr;
72   
73   // This is the number of times we entered a function via some kind
74   // of slow call.  It amounts to all the slow applications, not
75   // counting those that were to too few arguments.
76   unsigned long tot_fun_slow_enters = 
77       SLOW_CALL_ctr - 
78       SLOW_CALL_FUN_TOO_FEW_ctr -
79       SLOW_CALL_PAP_TOO_FEW_ctr;
80
81   unsigned long tot_known_calls =
82       KNOWN_CALL_ctr + KNOWN_CALL_TOO_FEW_ARGS_ctr + 
83       + KNOWN_CALL_EXTRA_ARGS_ctr;
84   unsigned long tot_tail_calls =
85       UNKNOWN_CALL_ctr + tot_known_calls;
86
87   unsigned long tot_enters =
88         tot_con_enters + tot_fun_direct_enters +
89         tot_ind_enters + ENT_PERM_IND_ctr + ENT_PAP_ctr + tot_thk_enters;
90   unsigned long jump_direct_enters =
91         tot_enters - ENT_VIA_NODE_ctr;
92
93   unsigned long tot_returns =
94       RET_NEW_ctr + RET_OLD_ctr + RET_UNBOXED_TUP_ctr;
95
96   unsigned long tot_returns_of_new = RET_NEW_ctr;
97
98   unsigned long con_updates = UPD_CON_IN_NEW_ctr + UPD_CON_IN_PLACE_ctr;
99   unsigned long pap_updates = UPD_PAP_IN_NEW_ctr + UPD_PAP_IN_PLACE_ctr;
100
101   unsigned long tot_updates = UPD_SQUEEZED_ctr + pap_updates + con_updates;
102
103   unsigned long tot_new_updates   = UPD_NEW_IND_ctr + UPD_NEW_PERM_IND_ctr;
104   unsigned long tot_old_updates   = UPD_OLD_IND_ctr + UPD_OLD_PERM_IND_ctr;
105   unsigned long tot_gengc_updates = tot_new_updates + tot_old_updates;
106
107   FILE *tf = RtsFlags.TickyFlags.tickyFile;
108
109   fprintf(tf,"\n\nALLOCATIONS: %ld (%ld words total: %ld admin, %ld goods, %ld slop)\n",
110           tot_allocs, tot_wds, tot_adm_wds, tot_gds_wds, tot_slp_wds);
111   fprintf(tf,"\t\t\t\ttotal words:\t    2     3     4     5    6+\n");
112
113 #define ALLOC_HISTO_MAGIC(categ) \
114         (PC(INTAVG(ALLOC_##categ##_hst[0], ALLOC_##categ##_ctr))), \
115         (PC(INTAVG(ALLOC_##categ##_hst[1], ALLOC_##categ##_ctr))), \
116         (PC(INTAVG(ALLOC_##categ##_hst[2], ALLOC_##categ##_ctr))), \
117         (PC(INTAVG(ALLOC_##categ##_hst[3], ALLOC_##categ##_ctr))), \
118         (PC(INTAVG(ALLOC_##categ##_hst[4], ALLOC_##categ##_ctr)))
119
120   fprintf(tf,"%7ld (%5.1f%%) function values",
121         ALLOC_FUN_ctr,
122         PC(INTAVG(ALLOC_FUN_ctr, tot_allocs)));
123   if (ALLOC_FUN_ctr != 0)
124       fprintf(tf,"\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(FUN));
125
126   fprintf(tf,"\n%7ld (%5.1f%%) thunks",
127         ALLOC_SE_THK_ctr + ALLOC_UP_THK_ctr,
128         PC(INTAVG(ALLOC_SE_THK_ctr + ALLOC_UP_THK_ctr, tot_allocs)));
129
130 #define ALLOC_THK_ctr (ALLOC_UP_THK_ctr + ALLOC_SE_THK_ctr)
131   /* hack to make ALLOC_HISTO_MAGIC still work for THK */
132   if ((ALLOC_SE_THK_ctr + ALLOC_UP_THK_ctr) != 0)
133       fprintf(tf,"\t\t\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(THK));
134 #undef ALLOC_THK_ctr
135
136   fprintf(tf,"\n%7ld (%5.1f%%) data values",
137         ALLOC_CON_ctr,
138         PC(INTAVG(ALLOC_CON_ctr, tot_allocs)));
139   if (ALLOC_CON_ctr != 0)
140       fprintf(tf,"\t\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(CON));
141
142   fprintf(tf,"\n%7ld (%5.1f%%) big tuples",
143         ALLOC_TUP_ctr,
144         PC(INTAVG(ALLOC_TUP_ctr, tot_allocs)));
145   if (ALLOC_TUP_ctr != 0)
146       fprintf(tf,"\t\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(TUP));
147
148   fprintf(tf,"\n%7ld (%5.1f%%) black holes",
149         ALLOC_BH_ctr,
150         PC(INTAVG(ALLOC_BH_ctr, tot_allocs)));
151   if (ALLOC_BH_ctr != 0)
152       fprintf(tf,"\t\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(BH));
153
154   fprintf(tf,"\n%7ld (%5.1f%%) prim things",
155         ALLOC_PRIM_ctr,
156         PC(INTAVG(ALLOC_PRIM_ctr, tot_allocs)));
157   if (ALLOC_PRIM_ctr != 0)
158       fprintf(tf,"\t\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(PRIM));
159
160   fprintf(tf,"\n%7ld (%5.1f%%) partial applications",
161         ALLOC_PAP_ctr,
162         PC(INTAVG(ALLOC_PAP_ctr, tot_allocs)));
163   if (ALLOC_PAP_ctr != 0)
164       fprintf(tf,"\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(PAP));
165
166   fprintf(tf,"\n%7ld (%5.1f%%) thread state objects",
167         ALLOC_TSO_ctr,
168         PC(INTAVG(ALLOC_TSO_ctr, tot_allocs)));
169   if (ALLOC_TSO_ctr != 0)
170       fprintf(tf,"\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(TSO));
171 #ifdef PAR
172   fprintf(tf,"\n%7ld (%5.1f%%) thread state objects",
173         ALLOC_FMBQ_ctr,
174         PC(INTAVG(ALLOC_FMBQ_ctr, tot_allocs)));
175   if (ALLOC_FMBQ_ctr != 0)
176       fprintf(tf,"\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(FMBQ));
177   fprintf(tf,"\n%7ld (%5.1f%%) thread state objects",
178         ALLOC_FME_ctr,
179         PC(INTAVG(ALLOC_FME_ctr, tot_allocs)));
180   if (ALLOC_FME_ctr != 0)
181       fprintf(tf,"\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(FME));
182   fprintf(tf,"\n%7ld (%5.1f%%) thread state objects",
183         ALLOC_BF_ctr,
184         PC(INTAVG(ALLOC_BF_ctr, tot_allocs)));
185   if (ALLOC_BF_ctr != 0)
186       fprintf(tf,"\t\t%5.1f %5.1f %5.1f %5.1f %5.1f", ALLOC_HISTO_MAGIC(BF));
187 #endif
188   fprintf(tf,"\n");
189
190   fprintf(tf,"\nTotal storage-manager allocations: %ld (%ld words)\n\t[%ld words lost to speculative heap-checks]\n", ALLOC_HEAP_ctr, ALLOC_HEAP_tot, ALLOC_HEAP_tot - tot_wds);
191
192   fprintf(tf,"\nSTACK USAGE:\n"); /* NB: some bits are direction sensitive */
193
194   fprintf(tf,"\nENTERS: %ld  of which %ld (%.1f%%) direct to the entry code\n\t\t  [the rest indirected via Node's info ptr]\n",
195         tot_enters,
196         jump_direct_enters,
197         PC(INTAVG(jump_direct_enters,tot_enters)));
198   fprintf(tf,"%7ld (%5.1f%%) thunks\n",
199         tot_thk_enters,
200         PC(INTAVG(tot_thk_enters,tot_enters)));
201   fprintf(tf,"%7ld (%5.1f%%) data values\n",
202         tot_con_enters,
203         PC(INTAVG(tot_con_enters,tot_enters)));
204   fprintf(tf,"%7ld (%5.1f%%) normal indirections\n",
205         tot_ind_enters,
206         PC(INTAVG(tot_ind_enters,tot_enters)));
207   fprintf(tf,"%7ld (%5.1f%%) permanent indirections\n",
208         ENT_PERM_IND_ctr,
209         PC(INTAVG(ENT_PERM_IND_ctr,tot_enters)));
210
211   fprintf(tf,"\nFUNCTION ENTRIES: %ld\n", tot_fun_direct_enters);
212
213   fprintf(tf, "\nTAIL CALLS: %ld, of which %ld (%.lf%%) were to known functions\n", 
214           tot_tail_calls, tot_known_calls,
215           PC(INTAVG(tot_known_calls,tot_tail_calls)));
216
217   fprintf(tf, "\nSLOW APPLICATIONS: %ld evaluated, %ld unevaluated\n",
218           SLOW_CALL_ctr, SLOW_CALL_UNEVALD_ctr);
219   fprintf(tf, "\n");
220   fprintf(tf, "         Too few args   Correct args   Too many args\n");
221   fprintf(tf, "   FUN     %8ld       %8ld        %8ld\n", 
222           SLOW_CALL_FUN_TOO_FEW_ctr, SLOW_CALL_FUN_CORRECT_ctr, SLOW_CALL_FUN_TOO_MANY_ctr);
223   fprintf(tf, "   PAP     %8ld       %8ld        %8ld\n", 
224           SLOW_CALL_PAP_TOO_FEW_ctr, SLOW_CALL_PAP_CORRECT_ctr, SLOW_CALL_PAP_TOO_MANY_ctr);
225   fprintf(tf, "\n");
226
227   fprintf(tf,"\nRETURNS: %ld\n", tot_returns);
228   fprintf(tf,"%7ld (%5.1f%%) from entering a new constructor\n\t\t  [the rest from entering an existing constructor]\n",
229         tot_returns_of_new,
230         PC(INTAVG(tot_returns_of_new,tot_returns)));
231   fprintf(tf,"%7ld (%5.1f%%) vectored [the rest unvectored]\n",
232         VEC_RETURN_ctr,
233         PC(INTAVG(VEC_RETURN_ctr,tot_returns)));
234
235   fprintf(tf, "\nRET_NEW:         %7ld: ", RET_NEW_ctr);
236   for (i = 0; i < 9; i++) { fprintf(tf, "%5.1f%%",
237                                 PC(INTAVG(RET_NEW_hst[i],RET_NEW_ctr))); }
238   fprintf(tf, "\n");
239   fprintf(tf, "RET_OLD:         %7ld: ", RET_OLD_ctr);
240   for (i = 0; i < 9; i++) { fprintf(tf, "%5.1f%%",
241                                 PC(INTAVG(RET_OLD_hst[i],RET_OLD_ctr))); }
242   fprintf(tf, "\n");
243   fprintf(tf, "RET_UNBOXED_TUP: %7ld: ", RET_UNBOXED_TUP_ctr);
244   for (i = 0; i < 9; i++) { fprintf(tf, "%5.1f%%",
245                                     PC(INTAVG(RET_UNBOXED_TUP_hst[i],
246                                               RET_UNBOXED_TUP_ctr))); }
247   fprintf(tf, "\n");
248   fprintf(tf, "\nRET_VEC_RETURN : %7ld: ", VEC_RETURN_ctr);
249   for (i = 0; i < 9; i++) { fprintf(tf, "%5.1f%%",
250                                 PC(INTAVG(RET_VEC_RETURN_hst[i],VEC_RETURN_ctr))); }
251   fprintf(tf, "\n");
252
253   fprintf(tf,"\nUPDATE FRAMES: %ld (%ld omitted from thunks)",
254         UPDF_PUSHED_ctr,
255         UPDF_OMITTED_ctr);
256
257   fprintf(tf,"\nCATCH FRAMES:  %ld", CATCHF_PUSHED_ctr);
258
259   if (UPDF_RCC_PUSHED_ctr != 0)
260      fprintf(tf,"%7ld restore cost centre frames (%ld omitted)\n",
261         UPDF_RCC_PUSHED_ctr,
262         UPDF_RCC_OMITTED_ctr);
263
264   fprintf(tf,"\nUPDATES: %ld\n", tot_updates);
265   fprintf(tf,"%7ld (%5.1f%%) data values\n\t\t  [%ld in place, %ld allocated new space]\n",
266         con_updates,
267         PC(INTAVG(con_updates,tot_updates)),
268         UPD_CON_IN_PLACE_ctr, UPD_CON_IN_NEW_ctr);
269   fprintf(tf,"%7ld (%5.1f%%) partial applications\n\t\t  [%ld in place, %ld allocated new space]\n",
270         pap_updates,
271         PC(INTAVG(pap_updates,tot_updates)),
272         UPD_PAP_IN_PLACE_ctr, UPD_PAP_IN_NEW_ctr);
273   fprintf(tf,"%7ld (%5.1f%%) updates by squeezing\n",
274         UPD_SQUEEZED_ctr,
275         PC(INTAVG(UPD_SQUEEZED_ctr, tot_updates)));
276
277   fprintf(tf, "\nUPD_CON_IN_NEW:   %7ld: ", UPD_CON_IN_NEW_ctr);
278   for (i = 0; i < 9; i++) { fprintf(tf, "%7ld", UPD_CON_IN_NEW_hst[i]); }
279   fprintf(tf, "\n");
280   fprintf(tf, "UPD_CON_IN_PLACE: %7ld: ", UPD_CON_IN_PLACE_ctr);
281   for (i = 0; i < 9; i++) { fprintf(tf, "%7ld", UPD_CON_IN_PLACE_hst[i]); }
282   fprintf(tf, "\n");
283   fprintf(tf, "UPD_PAP_IN_NEW:   %7ld: ", UPD_PAP_IN_NEW_ctr);
284   for (i = 0; i < 9; i++) { fprintf(tf, "%7ld", UPD_PAP_IN_NEW_hst[i]); }
285   fprintf(tf, "\n");
286
287   if (tot_gengc_updates != 0) {
288       fprintf(tf,"\nNEW GEN UPDATES: %9ld (%5.1f%%)\n",
289               tot_new_updates,
290               PC(INTAVG(tot_new_updates,tot_gengc_updates)));
291       fprintf(tf,"OLD GEN UPDATES: %9ld (%5.1f%%)\n",
292               tot_old_updates,
293               PC(INTAVG(tot_old_updates,tot_gengc_updates)));
294   }
295
296   fprintf(tf,"\nTotal bytes copied during GC: %ld\n",
297           GC_WORDS_COPIED_ctr * sizeof(W_));
298
299   printRegisteredCounterInfo(tf);
300
301   fprintf(tf,"\n**************************************************\n");
302
303   /* here, we print out all the raw numbers; these are really
304     more useful when we want to snag them for subsequent
305     rdb-etc processing. WDP 95/11
306   */
307
308 #define PR_CTR(ctr) \
309   do { fprintf(tf,"%7ld " #ctr "\n", ctr); } while(0)
310 /* COND_PR_CTR takes a boolean; if false then msg is the printname rather than ctr */
311 #define COND_PR_CTR(ctr,b,msg) \
312     if (b) { fprintf(tf,"%7ld " #ctr "\n", ctr); } else { fprintf(tf,"%7ld " msg "\n", ctr); }
313 #define PR_HST(hst,i) \
314   do { fprintf(tf,"%7ld " #hst "_" #i "\n", hst[i]); } while(0)
315
316   PR_CTR(ALLOC_HEAP_ctr);
317   PR_CTR(ALLOC_HEAP_tot);
318
319   PR_CTR(ALLOC_FUN_ctr);
320   PR_CTR(ALLOC_FUN_adm);
321   PR_CTR(ALLOC_FUN_gds);
322   PR_CTR(ALLOC_FUN_slp);
323   PR_HST(ALLOC_FUN_hst,0);
324   PR_HST(ALLOC_FUN_hst,1);
325   PR_HST(ALLOC_FUN_hst,2);
326   PR_HST(ALLOC_FUN_hst,3);
327   PR_HST(ALLOC_FUN_hst,4);
328   PR_CTR(ALLOC_UP_THK_ctr);
329   PR_CTR(ALLOC_SE_THK_ctr);
330   PR_CTR(ALLOC_THK_adm);
331   PR_CTR(ALLOC_THK_gds);
332   PR_CTR(ALLOC_THK_slp);
333   PR_HST(ALLOC_THK_hst,0);
334   PR_HST(ALLOC_THK_hst,1);
335   PR_HST(ALLOC_THK_hst,2);
336   PR_HST(ALLOC_THK_hst,3);
337   PR_HST(ALLOC_THK_hst,4);
338   PR_CTR(ALLOC_CON_ctr);
339   PR_CTR(ALLOC_CON_adm);
340   PR_CTR(ALLOC_CON_gds);
341   PR_CTR(ALLOC_CON_slp);
342   PR_HST(ALLOC_CON_hst,0);
343   PR_HST(ALLOC_CON_hst,1);
344   PR_HST(ALLOC_CON_hst,2);
345   PR_HST(ALLOC_CON_hst,3);
346   PR_HST(ALLOC_CON_hst,4);
347   PR_CTR(ALLOC_TUP_ctr);
348   PR_CTR(ALLOC_TUP_adm);
349   PR_CTR(ALLOC_TUP_gds);
350   PR_CTR(ALLOC_TUP_slp);
351   PR_HST(ALLOC_TUP_hst,0);
352   PR_HST(ALLOC_TUP_hst,1);
353   PR_HST(ALLOC_TUP_hst,2);
354   PR_HST(ALLOC_TUP_hst,3);
355   PR_HST(ALLOC_TUP_hst,4);
356   PR_CTR(ALLOC_BH_ctr);
357   PR_CTR(ALLOC_BH_adm);
358   PR_CTR(ALLOC_BH_gds);
359   PR_CTR(ALLOC_BH_slp);
360   PR_HST(ALLOC_BH_hst,0);
361   PR_HST(ALLOC_BH_hst,1);
362   PR_HST(ALLOC_BH_hst,2);
363   PR_HST(ALLOC_BH_hst,3);
364   PR_HST(ALLOC_BH_hst,4);
365   PR_CTR(ALLOC_PRIM_ctr);
366   PR_CTR(ALLOC_PRIM_adm);
367   PR_CTR(ALLOC_PRIM_gds);
368   PR_CTR(ALLOC_PRIM_slp);
369   PR_HST(ALLOC_PRIM_hst,0);
370   PR_HST(ALLOC_PRIM_hst,1);
371   PR_HST(ALLOC_PRIM_hst,2);
372   PR_HST(ALLOC_PRIM_hst,3);
373   PR_HST(ALLOC_PRIM_hst,4);
374   PR_CTR(ALLOC_PAP_ctr);
375   PR_CTR(ALLOC_PAP_adm);
376   PR_CTR(ALLOC_PAP_gds);
377   PR_CTR(ALLOC_PAP_slp);
378   PR_HST(ALLOC_PAP_hst,0);
379   PR_HST(ALLOC_PAP_hst,1);
380   PR_HST(ALLOC_PAP_hst,2);
381   PR_HST(ALLOC_PAP_hst,3);
382   PR_HST(ALLOC_PAP_hst,4);
383
384   PR_CTR(ALLOC_TSO_ctr);
385   PR_CTR(ALLOC_TSO_adm);
386   PR_CTR(ALLOC_TSO_gds);
387   PR_CTR(ALLOC_TSO_slp);
388   PR_HST(ALLOC_TSO_hst,0);
389   PR_HST(ALLOC_TSO_hst,1);
390   PR_HST(ALLOC_TSO_hst,2);
391   PR_HST(ALLOC_TSO_hst,3);
392   PR_HST(ALLOC_TSO_hst,4);
393
394 #ifdef PAR
395   PR_CTR(ALLOC_FMBQ_ctr);
396   PR_CTR(ALLOC_FMBQ_adm);
397   PR_CTR(ALLOC_FMBQ_gds);
398   PR_CTR(ALLOC_FMBQ_slp);
399   PR_HST(ALLOC_FMBQ_hst,0);
400   PR_HST(ALLOC_FMBQ_hst,1);
401   PR_HST(ALLOC_FMBQ_hst,2);
402   PR_HST(ALLOC_FMBQ_hst,3);
403   PR_HST(ALLOC_FMBQ_hst,4);
404   PR_CTR(ALLOC_FME_ctr);
405   PR_CTR(ALLOC_FME_adm);
406   PR_CTR(ALLOC_FME_gds);
407   PR_CTR(ALLOC_FME_slp);
408   PR_HST(ALLOC_FME_hst,0);
409   PR_HST(ALLOC_FME_hst,1);
410   PR_HST(ALLOC_FME_hst,2);
411   PR_HST(ALLOC_FME_hst,3);
412   PR_HST(ALLOC_FME_hst,4);
413   PR_CTR(ALLOC_BF_ctr);
414   PR_CTR(ALLOC_BF_adm);
415   PR_CTR(ALLOC_BF_gds);
416   PR_CTR(ALLOC_BF_slp);
417   PR_HST(ALLOC_BF_hst,0);
418   PR_HST(ALLOC_BF_hst,1);
419   PR_HST(ALLOC_BF_hst,2);
420   PR_HST(ALLOC_BF_hst,3);
421   PR_HST(ALLOC_BF_hst,4);
422 #endif
423
424   PR_CTR(ENT_VIA_NODE_ctr);
425   PR_CTR(ENT_STATIC_CON_ctr);
426   PR_CTR(ENT_DYN_CON_ctr);
427   PR_CTR(ENT_STATIC_FUN_DIRECT_ctr);
428   PR_CTR(ENT_DYN_FUN_DIRECT_ctr);
429   PR_CTR(ENT_STATIC_IND_ctr);
430   PR_CTR(ENT_DYN_IND_ctr);
431
432 /* The counters ENT_PERM_IND and UPD_{NEW,OLD}_PERM_IND are not dumped
433  * at the end of execution unless update squeezing is turned off (+RTS
434  * -Z =RtsFlags.GcFlags.squeezeUpdFrames), as they will be wrong
435  * otherwise.  Why?  Because for each update frame squeezed out, we
436  * count an UPD_NEW_PERM_IND *at GC time* (i.e., too early).  And
437  * further, when we enter the closure that has been updated, we count
438  * the ENT_PERM_IND, but we then enter the PERM_IND that was built for
439  * the next update frame below, and so on down the chain until we
440  * finally reach the value.  Thus we count many new ENT_PERM_INDs too
441  * early.  
442  * 
443  * This of course refers to the -ticky version that uses PERM_INDs to
444  * determine the number of closures entered 0/1/>1.  KSW 1999-04.  */
445   COND_PR_CTR(ENT_PERM_IND_ctr,RtsFlags.GcFlags.squeezeUpdFrames == rtsFalse,"E!NT_PERM_IND_ctr requires +RTS -Z");
446
447   PR_CTR(ENT_AP_ctr);
448   PR_CTR(ENT_PAP_ctr);
449   PR_CTR(ENT_AP_STACK_ctr);
450   PR_CTR(ENT_BH_ctr);
451   PR_CTR(ENT_STATIC_THK_ctr);
452   PR_CTR(ENT_DYN_THK_ctr);
453
454   PR_CTR(SLOW_CALL_v_ctr);
455   PR_CTR(SLOW_CALL_f_ctr);
456   PR_CTR(SLOW_CALL_d_ctr);
457   PR_CTR(SLOW_CALL_l_ctr);
458   PR_CTR(SLOW_CALL_n_ctr);
459   PR_CTR(SLOW_CALL_p_ctr);
460   PR_CTR(SLOW_CALL_pv_ctr);
461   PR_CTR(SLOW_CALL_pp_ctr);
462   PR_CTR(SLOW_CALL_ppv_ctr);
463   PR_CTR(SLOW_CALL_ppp_ctr);
464   PR_CTR(SLOW_CALL_pppv_ctr);
465   PR_CTR(SLOW_CALL_pppp_ctr);
466   PR_CTR(SLOW_CALL_ppppp_ctr);
467   PR_CTR(SLOW_CALL_pppppp_ctr);
468   PR_CTR(SLOW_CALL_OTHER_ctr);
469
470   PR_CTR(UNKNOWN_CALL_ctr);
471   PR_CTR(KNOWN_CALL_ctr);
472   PR_CTR(KNOWN_CALL_TOO_FEW_ARGS_ctr);
473   PR_CTR(KNOWN_CALL_EXTRA_ARGS_ctr);
474   PR_CTR(MULTI_CHUNK_SLOW_CALL_ctr);
475   PR_CTR(MULTI_CHUNK_SLOW_CALL_CHUNKS_ctr);
476   PR_CTR(SLOW_CALL_ctr);
477   PR_CTR(SLOW_CALL_FUN_TOO_FEW_ctr);
478   PR_CTR(SLOW_CALL_FUN_CORRECT_ctr);
479   PR_CTR(SLOW_CALL_FUN_TOO_MANY_ctr);
480   PR_CTR(SLOW_CALL_PAP_TOO_FEW_ctr);
481   PR_CTR(SLOW_CALL_PAP_CORRECT_ctr);
482   PR_CTR(SLOW_CALL_PAP_TOO_MANY_ctr);
483   PR_CTR(SLOW_CALL_UNEVALD_ctr);
484   PR_HST(SLOW_CALL_hst,0);
485   PR_HST(SLOW_CALL_hst,1);
486   PR_HST(SLOW_CALL_hst,2);
487   PR_HST(SLOW_CALL_hst,3);
488   PR_HST(SLOW_CALL_hst,4);
489   PR_HST(SLOW_CALL_hst,5);
490   PR_HST(SLOW_CALL_hst,6);
491   PR_HST(SLOW_CALL_hst,7);
492
493   PR_CTR(RET_NEW_ctr);
494   PR_CTR(RET_OLD_ctr);
495   PR_CTR(RET_UNBOXED_TUP_ctr);
496   PR_CTR(VEC_RETURN_ctr);
497
498   PR_HST(RET_NEW_hst,0);
499   PR_HST(RET_NEW_hst,1);
500   PR_HST(RET_NEW_hst,2);
501   PR_HST(RET_NEW_hst,3);
502   PR_HST(RET_NEW_hst,4);
503   PR_HST(RET_NEW_hst,5);
504   PR_HST(RET_NEW_hst,6);
505   PR_HST(RET_NEW_hst,7);
506   PR_HST(RET_NEW_hst,8);
507   PR_HST(RET_OLD_hst,0);
508   PR_HST(RET_OLD_hst,1);
509   PR_HST(RET_OLD_hst,2);
510   PR_HST(RET_OLD_hst,3);
511   PR_HST(RET_OLD_hst,4);
512   PR_HST(RET_OLD_hst,5);
513   PR_HST(RET_OLD_hst,6);
514   PR_HST(RET_OLD_hst,7);
515   PR_HST(RET_OLD_hst,8);
516   PR_HST(RET_UNBOXED_TUP_hst,0);
517   PR_HST(RET_UNBOXED_TUP_hst,1);
518   PR_HST(RET_UNBOXED_TUP_hst,2);
519   PR_HST(RET_UNBOXED_TUP_hst,3);
520   PR_HST(RET_UNBOXED_TUP_hst,4);
521   PR_HST(RET_UNBOXED_TUP_hst,5);
522   PR_HST(RET_UNBOXED_TUP_hst,6);
523   PR_HST(RET_UNBOXED_TUP_hst,7);
524   PR_HST(RET_UNBOXED_TUP_hst,8);
525   PR_HST(RET_VEC_RETURN_hst,0);
526   PR_HST(RET_VEC_RETURN_hst,1);
527   PR_HST(RET_VEC_RETURN_hst,2);
528   PR_HST(RET_VEC_RETURN_hst,3);
529   PR_HST(RET_VEC_RETURN_hst,4);
530   PR_HST(RET_VEC_RETURN_hst,5);
531   PR_HST(RET_VEC_RETURN_hst,6);
532   PR_HST(RET_VEC_RETURN_hst,7);
533   PR_HST(RET_VEC_RETURN_hst,8);
534
535   PR_CTR(UPDF_OMITTED_ctr);
536   PR_CTR(UPDF_PUSHED_ctr);
537   PR_CTR(CATCHF_PUSHED_ctr);
538
539   PR_CTR(UPDF_RCC_PUSHED_ctr);
540   PR_CTR(UPDF_RCC_OMITTED_ctr);
541
542   PR_CTR(UPD_SQUEEZED_ctr);
543   PR_CTR(UPD_CON_IN_NEW_ctr);
544   PR_CTR(UPD_CON_IN_PLACE_ctr);
545   PR_CTR(UPD_PAP_IN_NEW_ctr);
546   PR_CTR(UPD_PAP_IN_PLACE_ctr);
547
548   PR_CTR(UPD_BH_UPDATABLE_ctr);
549   PR_CTR(UPD_BH_SINGLE_ENTRY_ctr);
550   PR_CTR(UPD_CAF_BH_UPDATABLE_ctr);
551   PR_CTR(UPD_CAF_BH_SINGLE_ENTRY_ctr);
552
553   PR_HST(UPD_CON_IN_NEW_hst,0);
554   PR_HST(UPD_CON_IN_NEW_hst,1);
555   PR_HST(UPD_CON_IN_NEW_hst,2);
556   PR_HST(UPD_CON_IN_NEW_hst,3);
557   PR_HST(UPD_CON_IN_NEW_hst,4);
558   PR_HST(UPD_CON_IN_NEW_hst,5);
559   PR_HST(UPD_CON_IN_NEW_hst,6);
560   PR_HST(UPD_CON_IN_NEW_hst,7);
561   PR_HST(UPD_CON_IN_NEW_hst,8);
562   PR_HST(UPD_PAP_IN_NEW_hst,0);
563   PR_HST(UPD_PAP_IN_NEW_hst,1);
564   PR_HST(UPD_PAP_IN_NEW_hst,2);
565   PR_HST(UPD_PAP_IN_NEW_hst,3);
566   PR_HST(UPD_PAP_IN_NEW_hst,4);
567   PR_HST(UPD_PAP_IN_NEW_hst,5);
568   PR_HST(UPD_PAP_IN_NEW_hst,6);
569   PR_HST(UPD_PAP_IN_NEW_hst,7);
570   PR_HST(UPD_PAP_IN_NEW_hst,8);
571
572   PR_CTR(UPD_NEW_IND_ctr);
573   /* see comment on ENT_PERM_IND_ctr */
574   COND_PR_CTR(UPD_NEW_PERM_IND_ctr,RtsFlags.GcFlags.squeezeUpdFrames == rtsFalse,"U!PD_NEW_PERM_IND_ctr requires +RTS -Z");
575   PR_CTR(UPD_OLD_IND_ctr);
576   /* see comment on ENT_PERM_IND_ctr */
577   COND_PR_CTR(UPD_OLD_PERM_IND_ctr,RtsFlags.GcFlags.squeezeUpdFrames == rtsFalse,"U!PD_OLD_PERM_IND_ctr requires +RTS -Z");
578
579   PR_CTR(GC_SEL_ABANDONED_ctr);
580   PR_CTR(GC_SEL_MINOR_ctr);
581   PR_CTR(GC_SEL_MAJOR_ctr);
582   PR_CTR(GC_FAILED_PROMOTION_ctr);
583   PR_CTR(GC_WORDS_COPIED_ctr);
584 }
585
586 /* Data structure used in ``registering'' one of these counters. */
587
588 StgEntCounter *ticky_entry_ctrs = NULL; /* root of list of them */
589
590 /* To print out all the registered-counter info: */
591
592 static void
593 printRegisteredCounterInfo (FILE *tf)
594 {
595     StgEntCounter *p;
596
597     if ( ticky_entry_ctrs != NULL ) {
598       fprintf(tf,"\n**************************************************\n\n");
599     }
600     fprintf(tf, "%11s%11s %6s%6s    %-11s%-30s\n",
601             "Entries", "Allocs", "Arity", "Stack", "Kinds", "Function");
602     fprintf(tf, "--------------------------------------------------------------------------------\n");
603     /* Function name at the end so it doesn't mess up the tabulation */
604
605     for (p = ticky_entry_ctrs; p != NULL; p = p->link) {
606         fprintf(tf, "%11ld%11ld %6u%6u    %-11s%-30s",
607                 p->entry_count,
608                 p->allocs,
609                 p->arity,
610                 p->stk_args,
611                 p->arg_kinds,
612                 p->str);
613
614         fprintf(tf, "\n");
615
616     }
617 }
618
619 /* Catch-all top-level counter struct.  Allocations from CAFs will go
620  * here.
621  */
622 StgEntCounter top_ct
623         = { 0, 0, 0,
624             "TOP", "",
625             0, 0, NULL };
626
627 #endif /* TICKY_TICKY */
628