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