[project @ 2004-08-15 20:37:22 by panne]
[ghc-hetmet.git] / ghc / docs / users_guide / profiling.xml
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <chapter id="profiling">
3   <title>Profiling</title>
4   <indexterm><primary>profiling</primary>
5   </indexterm>
6   <indexterm><primary>cost-centre profiling</primary></indexterm>
7
8   <para> Glasgow Haskell comes with a time and space profiling
9   system. Its purpose is to help you improve your understanding of
10   your program's execution behaviour, so you can improve it.</para>
11   
12   <para> Any comments, suggestions and/or improvements you have are
13   welcome.  Recommended &ldquo;profiling tricks&rdquo; would be
14   especially cool! </para>
15
16   <para>Profiling a program is a three-step process:</para>
17
18   <orderedlist>
19     <listitem>
20       <para> Re-compile your program for profiling with the
21       <literal>-prof</literal> option, and probably one of the
22       <literal>-auto</literal> or <literal>-auto-all</literal>
23       options.  These options are described in more detail in <xref
24       linkend="prof-compiler-options"/> </para>
25       <indexterm><primary><literal>-prof</literal></primary>
26       </indexterm>
27       <indexterm><primary><literal>-auto</literal></primary>
28       </indexterm>
29       <indexterm><primary><literal>-auto-all</literal></primary>
30       </indexterm>
31     </listitem>
32
33     <listitem>
34       <para> Run your program with one of the profiling options, eg.
35       <literal>+RTS -p -RTS</literal>.  This generates a file of
36       profiling information.</para>
37       <indexterm><primary><option>-p</option></primary><secondary>RTS
38       option</secondary></indexterm>
39     </listitem>
40       
41     <listitem>
42       <para> Examine the generated profiling information, using one of
43       GHC's profiling tools.  The tool to use will depend on the kind
44       of profiling information generated.</para>
45     </listitem>
46     
47   </orderedlist>
48   
49   <sect1 id="cost-centres">
50     <title>Cost centres and cost-centre stacks</title>
51     
52     <para>GHC's profiling system assigns <firstterm>costs</firstterm>
53     to <firstterm>cost centres</firstterm>.  A cost is simply the time
54     or space required to evaluate an expression.  Cost centres are
55     program annotations around expressions; all costs incurred by the
56     annotated expression are assigned to the enclosing cost centre.
57     Furthermore, GHC will remember the stack of enclosing cost centres
58     for any given expression at run-time and generate a call-graph of
59     cost attributions.</para>
60
61     <para>Let's take a look at an example:</para>
62
63     <programlisting>
64 main = print (nfib 25)
65 nfib n = if n &lt; 2 then 1 else nfib (n-1) + nfib (n-2)
66 </programlisting>
67
68     <para>Compile and run this program as follows:</para>
69
70     <screen>
71 $ ghc -prof -auto-all -o Main Main.hs
72 $ ./Main +RTS -p
73 121393
74 $
75 </screen>
76
77     <para>When a GHC-compiled program is run with the
78     <option>-p</option> RTS option, it generates a file called
79     <filename>&lt;prog&gt;.prof</filename>.  In this case, the file
80     will contain something like this:</para>
81
82 <screen>
83           Fri May 12 14:06 2000 Time and Allocation Profiling Report  (Final)
84
85            Main +RTS -p -RTS
86
87         total time  =        0.14 secs   (7 ticks @ 20 ms)
88         total alloc =   8,741,204 bytes  (excludes profiling overheads)
89
90 COST CENTRE          MODULE     %time %alloc
91
92 nfib                 Main       100.0  100.0
93
94
95                                               individual     inherited
96 COST CENTRE              MODULE      entries %time %alloc   %time %alloc
97
98 MAIN                     MAIN             0    0.0   0.0    100.0 100.0
99  main                    Main             0    0.0   0.0      0.0   0.0
100  CAF                     PrelHandle       3    0.0   0.0      0.0   0.0
101  CAF                     PrelAddr         1    0.0   0.0      0.0   0.0
102  CAF                     Main             6    0.0   0.0    100.0 100.0
103   main                   Main             1    0.0   0.0    100.0 100.0
104    nfib                  Main        242785  100.0 100.0    100.0 100.0
105 </screen>
106
107
108     <para>The first part of the file gives the program name and
109     options, and the total time and total memory allocation measured
110     during the run of the program (note that the total memory
111     allocation figure isn't the same as the amount of
112     <emphasis>live</emphasis> memory needed by the program at any one
113     time; the latter can be determined using heap profiling, which we
114     will describe shortly).</para>
115
116     <para>The second part of the file is a break-down by cost centre
117     of the most costly functions in the program.  In this case, there
118     was only one significant function in the program, namely
119     <function>nfib</function>, and it was responsible for 100&percnt;
120     of both the time and allocation costs of the program.</para>
121
122     <para>The third and final section of the file gives a profile
123     break-down by cost-centre stack.  This is roughly a call-graph
124     profile of the program.  In the example above, it is clear that
125     the costly call to <function>nfib</function> came from
126     <function>main</function>.</para>
127
128     <para>The time and allocation incurred by a given part of the
129     program is displayed in two ways: &ldquo;individual&rdquo;, which
130     are the costs incurred by the code covered by this cost centre
131     stack alone, and &ldquo;inherited&rdquo;, which includes the costs
132     incurred by all the children of this node.</para>
133
134     <para>The usefulness of cost-centre stacks is better demonstrated
135     by  modifying the example slightly:</para>
136
137     <programlisting>
138 main = print (f 25 + g 25)
139 f n  = nfib n
140 g n  = nfib (n `div` 2)
141 nfib n = if n &lt; 2 then 1 else nfib (n-1) + nfib (n-2)
142 </programlisting>
143
144     <para>Compile and run this program as before, and take a look at
145     the new profiling results:</para>
146
147 <screen>
148 COST CENTRE              MODULE         scc  %time %alloc   %time %alloc
149
150 MAIN                     MAIN             0    0.0   0.0    100.0 100.0
151  main                    Main             0    0.0   0.0      0.0   0.0
152  CAF                     PrelHandle       3    0.0   0.0      0.0   0.0
153  CAF                     PrelAddr         1    0.0   0.0      0.0   0.0
154  CAF                     Main             9    0.0   0.0    100.0 100.0
155   main                   Main             1    0.0   0.0    100.0 100.0
156    g                     Main             1    0.0   0.0      0.0   0.2
157     nfib                 Main           465    0.0   0.2      0.0   0.2
158    f                     Main             1    0.0   0.0    100.0  99.8
159     nfib                 Main        242785  100.0  99.8    100.0  99.8
160 </screen>
161
162     <para>Now although we had two calls to <function>nfib</function>
163     in the program, it is immediately clear that it was the call from
164     <function>f</function> which took all the time.</para>
165
166     <para>The actual meaning of the various columns in the output is:</para>
167
168     <variablelist>
169       <varlistentry>
170         <term>entries</term>
171         <listitem>
172           <para>The number of times this particular point in the call
173           graph was entered.</para>
174         </listitem>
175       </varlistentry>
176
177       <varlistentry>
178         <term>individual &percnt;time</term>
179         <listitem>
180           <para>The percentage of the total run time of the program
181           spent at this point in the call graph.</para>
182         </listitem>
183       </varlistentry>
184
185       <varlistentry>
186         <term>individual &percnt;alloc</term>
187         <listitem>
188           <para>The percentage of the total memory allocations
189           (excluding profiling overheads) of the program made by this
190           call.</para>
191         </listitem>
192       </varlistentry>
193
194       <varlistentry>
195         <term>inherited &percnt;time</term>
196         <listitem>
197           <para>The percentage of the total run time of the program
198           spent below this point in the call graph.</para>
199         </listitem>
200       </varlistentry>
201
202       <varlistentry>
203         <term>inherited &percnt;alloc</term>
204         <listitem>
205           <para>The percentage of the total memory allocations
206           (excluding profiling overheads) of the program made by this
207           call and all of its sub-calls.</para>
208         </listitem>
209       </varlistentry>
210     </variablelist>
211
212     <para>In addition you can use the <option>-P</option> RTS option
213     <indexterm><primary><option>-P</option></primary></indexterm> to
214     get the following additional information:</para>
215
216     <variablelist>
217       <varlistentry>
218         <term><literal>ticks</literal></term>
219         <listitem>
220           <para>The raw number of time &ldquo;ticks&rdquo; which were
221           attributed to this cost-centre; from this, we get the
222           <literal>&percnt;time</literal> figure mentioned
223           above.</para>
224         </listitem>
225       </varlistentry>
226
227       <varlistentry>
228         <term><literal>bytes</literal></term>
229         <listitem>
230           <para>Number of bytes allocated in the heap while in this
231           cost-centre; again, this is the raw number from which we get
232           the <literal>&percnt;alloc</literal> figure mentioned
233           above.</para>
234         </listitem>
235       </varlistentry>
236     </variablelist>
237
238     <para>What about recursive functions, and mutually recursive
239     groups of functions?  Where are the costs attributed?  Well,
240     although GHC does keep information about which groups of functions
241     called each other recursively, this information isn't displayed in
242     the basic time and allocation profile, instead the call-graph is
243     flattened into a tree.  The XML profiling tool (described in <xref
244     linkend="prof-xml-tool"/>) will be able to display real loops in
245     the call-graph.</para>
246
247     <sect2><title>Inserting cost centres by hand</title>
248
249       <para>Cost centres are just program annotations.  When you say
250       <option>-auto-all</option> to the compiler, it automatically
251       inserts a cost centre annotation around every top-level function
252       in your program, but you are entirely free to add the cost
253       centre annotations yourself.</para>
254
255       <para>The syntax of a cost centre annotation is</para>
256
257       <programlisting>
258      {-# SCC "name" #-} &lt;expression&gt;
259 </programlisting>
260
261       <para>where <literal>"name"</literal> is an aribrary string,
262       that will become the name of your cost centre as it appears
263       in the profiling output, and
264       <literal>&lt;expression&gt;</literal> is any Haskell
265       expression.  An <literal>SCC</literal> annotation extends as
266       far to the right as possible when parsing.</para>
267
268     </sect2>
269
270     <sect2 id="prof-rules">
271       <title>Rules for attributing costs</title>
272
273       <para>The cost of evaluating any expression in your program is
274       attributed to a cost-centre stack using the following rules:</para>
275
276       <itemizedlist>
277         <listitem>
278           <para>If the expression is part of the
279           <firstterm>one-off</firstterm> costs of evaluating the
280           enclosing top-level definition, then costs are attributed to
281           the stack of lexically enclosing <literal>SCC</literal>
282           annotations on top of the special <literal>CAF</literal>
283           cost-centre. </para>
284         </listitem>
285
286         <listitem>
287           <para>Otherwise, costs are attributed to the stack of
288           lexically-enclosing <literal>SCC</literal> annotations,
289           appended to the cost-centre stack in effect at the
290           <firstterm>call site</firstterm> of the current top-level
291           definition<footnote> <para>The call-site is just the place
292           in the source code which mentions the particular function or
293           variable.</para></footnote>.  Notice that this is a recursive
294           definition.</para>
295         </listitem>
296
297         <listitem>
298           <para>Time spent in foreign code (see <xref linkend="ffi"/>)
299           is always attributed to the cost centre in force at the
300           Haskell call-site of the foreign function.</para>
301         </listitem>
302       </itemizedlist>
303
304       <para>What do we mean by one-off costs?  Well, Haskell is a lazy
305       language, and certain expressions are only ever evaluated once.
306       For example, if we write:</para>
307
308       <programlisting>
309 x = nfib 25
310 </programlisting>
311
312       <para>then <varname>x</varname> will only be evaluated once (if
313       at all), and subsequent demands for <varname>x</varname> will
314       immediately get to see the cached result.  The definition
315       <varname>x</varname> is called a CAF (Constant Applicative
316       Form), because it has no arguments.</para>
317
318       <para>For the purposes of profiling, we say that the expression
319       <literal>nfib 25</literal> belongs to the one-off costs of
320       evaluating <varname>x</varname>.</para>
321
322       <para>Since one-off costs aren't strictly speaking part of the
323       call-graph of the program, they are attributed to a special
324       top-level cost centre, <literal>CAF</literal>.  There may be one
325       <literal>CAF</literal> cost centre for each module (the
326       default), or one for each top-level definition with any one-off
327       costs (this behaviour can be selected by giving GHC the
328       <option>-caf-all</option> flag).</para>
329
330       <indexterm><primary><literal>-caf-all</literal></primary>
331       </indexterm>
332
333       <para>If you think you have a weird profile, or the call-graph
334       doesn't look like you expect it to, feel free to send it (and
335       your program) to us at
336       <email>glasgow-haskell-bugs@haskell.org</email>.</para>
337     </sect2>
338   </sect1>
339
340   <sect1 id="prof-compiler-options">
341     <title>Compiler options for profiling</title>
342
343     <indexterm><primary>profiling</primary><secondary>options</secondary></indexterm>
344     <indexterm><primary>options</primary><secondary>for profiling</secondary></indexterm>
345
346     <variablelist>
347       <varlistentry>
348         <term><option>-prof</option>:</term>
349         <indexterm><primary><option>-prof</option></primary></indexterm>
350         <listitem>
351           <para> To make use of the profiling system
352           <emphasis>all</emphasis> modules must be compiled and linked
353           with the <option>-prof</option> option. Any
354           <literal>SCC</literal> annotations you've put in your source
355           will spring to life.</para>
356
357           <para> Without a <option>-prof</option> option, your
358           <literal>SCC</literal>s are ignored; so you can compile
359           <literal>SCC</literal>-laden code without changing
360           it.</para>
361         </listitem>
362       </varlistentry>
363     </variablelist>
364       
365     <para>There are a few other profiling-related compilation options.
366     Use them <emphasis>in addition to</emphasis>
367     <option>-prof</option>.  These do not have to be used consistently
368     for all modules in a program.</para>
369
370     <variablelist>
371       <varlistentry>
372         <term><option>-auto</option>:</term>
373         <indexterm><primary><option>-auto</option></primary></indexterm>
374         <indexterm><primary>cost centres</primary><secondary>automatically inserting</secondary></indexterm>
375         <listitem>
376           <para> GHC will automatically add
377           <function>&lowbar;scc&lowbar;</function> constructs for all
378           top-level, exported functions.</para>
379         </listitem>
380       </varlistentry>
381       
382       <varlistentry>
383         <term><option>-auto-all</option>:</term>
384         <indexterm><primary><option>-auto-all</option></primary></indexterm>
385         <listitem>
386           <para> <emphasis>All</emphasis> top-level functions,
387           exported or not, will be automatically
388           <function>&lowbar;scc&lowbar;</function>'d.</para>
389         </listitem>
390       </varlistentry>
391
392       <varlistentry>
393         <term><option>-caf-all</option>:</term>
394         <indexterm><primary><option>-caf-all</option></primary></indexterm>
395         <listitem>
396           <para> The costs of all CAFs in a module are usually
397           attributed to one &ldquo;big&rdquo; CAF cost-centre. With
398           this option, all CAFs get their own cost-centre.  An
399           &ldquo;if all else fails&rdquo; option&hellip;</para>
400         </listitem>
401       </varlistentry>
402
403       <varlistentry>
404         <term><option>-ignore-scc</option>:</term>
405         <indexterm><primary><option>-ignore-scc</option></primary></indexterm>
406         <listitem>
407           <para>Ignore any <function>&lowbar;scc&lowbar;</function>
408           constructs, so a module which already has
409           <function>&lowbar;scc&lowbar;</function>s can be compiled
410           for profiling with the annotations ignored.</para>
411         </listitem>
412       </varlistentry>
413
414     </variablelist>
415
416   </sect1>
417
418   <sect1 id="prof-time-options">
419     <title>Time and allocation profiling</title>
420
421     <para>To generate a time and allocation profile, give one of the
422     following RTS options to the compiled program when you run it (RTS
423     options should be enclosed between <literal>+RTS...-RTS</literal>
424     as usual):</para>
425
426     <variablelist>
427       <varlistentry>
428         <term><option>-p</option> or <option>-P</option>:</term>
429         <indexterm><primary><option>-p</option></primary></indexterm>
430         <indexterm><primary><option>-P</option></primary></indexterm>
431         <indexterm><primary>time profile</primary></indexterm>
432         <listitem>
433           <para>The <option>-p</option> option produces a standard
434           <emphasis>time profile</emphasis> report.  It is written
435           into the file
436           <filename><replaceable>program</replaceable>.prof</filename>.</para>
437
438           <para>The <option>-P</option> option produces a more
439           detailed report containing the actual time and allocation
440           data as well.  (Not used much.)</para>
441         </listitem>
442       </varlistentry>
443
444       <varlistentry>
445         <term><option>-px</option>:</term>
446         <indexterm><primary><option>-px</option></primary></indexterm>
447         <listitem>
448           <para>The <option>-px</option> option generates profiling
449           information in the XML format understood by our new
450           profiling tool, see <xref linkend="prof-xml-tool"/>.</para>
451         </listitem>
452       </varlistentry>
453
454       <varlistentry>
455         <term><option>-xc</option></term>
456         <indexterm><primary><option>-xc</option></primary><secondary>RTS
457         option</secondary></indexterm>
458         <listitem>
459           <para>This option makes use of the extra information
460           maintained by the cost-centre-stack profiler to provide
461           useful information about the location of runtime errors.
462           See <xref linkend="rts-options-debugging"/>.</para>
463         </listitem>
464       </varlistentry>
465
466     </variablelist>
467     
468   </sect1>
469
470   <sect1 id="prof-heap">
471     <title>Profiling memory usage</title>
472
473     <para>In addition to profiling the time and allocation behaviour
474     of your program, you can also generate a graph of its memory usage
475     over time.  This is useful for detecting the causes of
476     <firstterm>space leaks</firstterm>, when your program holds on to
477     more memory at run-time that it needs to.  Space leaks lead to
478     longer run-times due to heavy garbage collector ativity, and may
479     even cause the program to run out of memory altogether.</para>
480
481     <para>To generate a heap profile from your program:</para>
482
483     <orderedlist>
484       <listitem>
485         <para>Compile the program for profiling (<xref
486         linkend="prof-compiler-options"/>).</para>
487       </listitem>
488       <listitem>
489         <para>Run it with one of the heap profiling options described
490         below (eg. <option>-hc</option> for a basic producer profile).
491         This generates the file
492         <filename><replaceable>prog</replaceable>.hp</filename>.</para>
493       </listitem>
494       <listitem>
495         <para>Run <command>hp2ps</command> to produce a Postscript
496         file,
497         <filename><replaceable>prog</replaceable>.ps</filename>.  The
498         <command>hp2ps</command> utility is described in detail in
499         <xref linkend="hp2ps"/>.</para> 
500       </listitem>
501       <listitem>
502         <para>Display the heap profile using a postscript viewer such
503         as <application>Ghostview</application>, or print it out on a
504         Postscript-capable printer.</para>
505       </listitem>
506     </orderedlist>
507
508     <sect2 id="rts-options-heap-prof">
509       <title>RTS options for heap profiling</title>
510
511       <para>There are several different kinds of heap profile that can
512       be generated.  All the different profile types yield a graph of
513       live heap against time, but they differ in how the live heap is
514       broken down into bands.  The following RTS options select which
515       break-down to use:</para>
516
517       <variablelist>
518         <varlistentry>
519           <term><option>-hc</option></term>
520           <indexterm><primary><option>-hc</option></primary><secondary>RTS
521           option</secondary></indexterm>
522           <listitem>
523             <para>Breaks down the graph by the cost-centre stack which
524             produced the data.</para>
525           </listitem>
526         </varlistentry>
527
528         <varlistentry>
529           <term><option>-hm</option></term>
530           <indexterm><primary><option>-hm</option></primary><secondary>RTS
531           option</secondary></indexterm>
532           <listitem>
533             <para>Break down the live heap by the module containing
534             the code which produced the data.</para>
535           </listitem>
536         </varlistentry>
537
538         <varlistentry>
539           <term><option>-hd</option></term>
540           <indexterm><primary><option>-hd</option></primary><secondary>RTS
541           option</secondary></indexterm>
542           <listitem>
543             <para>Breaks down the graph by <firstterm>closure
544             description</firstterm>.  For actual data, the description
545             is just the constructor name, for other closures it is a
546             compiler-generated string identifying the closure.</para>
547           </listitem>
548         </varlistentry>
549
550         <varlistentry>
551           <term><option>-hy</option></term>
552           <indexterm><primary><option>-hy</option></primary><secondary>RTS
553           option</secondary></indexterm>
554           <listitem>
555             <para>Breaks down the graph by
556             <firstterm>type</firstterm>.  For closures which have
557             function type or unknown/polymorphic type, the string will
558             represent an approximation to the actual type.</para>
559           </listitem>
560         </varlistentry>
561         
562         <varlistentry>
563           <term><option>-hr</option></term>
564           <indexterm><primary><option>-hr</option></primary><secondary>RTS
565           option</secondary></indexterm>
566           <listitem>
567             <para>Break down the graph by <firstterm>retainer
568             set</firstterm>.  Retainer profiling is described in more
569             detail below (<xref linkend="retainer-prof"/>).</para>
570           </listitem>
571         </varlistentry>
572
573         <varlistentry>
574           <term><option>-hb</option></term>
575           <indexterm><primary><option>-hb</option></primary><secondary>RTS
576           option</secondary></indexterm>
577           <listitem>
578             <para>Break down the graph by
579             <firstterm>biography</firstterm>.  Biographical profiling
580             is described in more detail below (<xref
581             linkend="biography-prof"/>).</para>
582           </listitem>
583         </varlistentry>
584       </variablelist>
585
586       <para>In addition, the profile can be restricted to heap data
587       which satisfies certain criteria - for example, you might want
588       to display a profile by type but only for data produced by a
589       certain module, or a profile by retainer for a certain type of
590       data.  Restrictions are specified as follows:</para>
591       
592       <variablelist>
593         <varlistentry>
594           <term><option>-hc</option><replaceable>name</replaceable>,...</term>
595           <indexterm><primary><option>-hc</option></primary><secondary>RTS
596           option</secondary></indexterm>
597           <listitem>
598             <para>Restrict the profile to closures produced by
599             cost-centre stacks with one of the specified cost centres
600             at the top.</para>
601           </listitem>
602         </varlistentry>
603
604         <varlistentry>
605           <term><option>-hC</option><replaceable>name</replaceable>,...</term>
606           <indexterm><primary><option>-hC</option></primary><secondary>RTS
607           option</secondary></indexterm>
608           <listitem>
609             <para>Restrict the profile to closures produced by
610             cost-centre stacks with one of the specified cost centres
611             anywhere in the stack.</para>
612           </listitem>
613         </varlistentry>
614
615         <varlistentry>
616           <term><option>-hm</option><replaceable>module</replaceable>,...</term>
617           <indexterm><primary><option>-hm</option></primary><secondary>RTS
618           option</secondary></indexterm>
619           <listitem>
620             <para>Restrict the profile to closures produced by the
621             specified modules.</para>
622           </listitem>
623         </varlistentry>
624
625         <varlistentry>
626           <term><option>-hd</option><replaceable>desc</replaceable>,...</term>
627           <indexterm><primary><option>-hd</option></primary><secondary>RTS
628           option</secondary></indexterm>
629           <listitem>
630             <para>Restrict the profile to closures with the specified
631             description strings.</para>
632           </listitem>
633         </varlistentry>
634
635         <varlistentry>
636           <term><option>-hy</option><replaceable>type</replaceable>,...</term>
637           <indexterm><primary><option>-hy</option></primary><secondary>RTS
638           option</secondary></indexterm>
639           <listitem>
640             <para>Restrict the profile to closures with the specified
641             types.</para>
642           </listitem>
643         </varlistentry>
644         
645         <varlistentry>
646           <term><option>-hr</option><replaceable>cc</replaceable>,...</term>
647           <indexterm><primary><option>-hr</option></primary><secondary>RTS
648           option</secondary></indexterm>
649           <listitem>
650             <para>Restrict the profile to closures with retainer sets
651             containing cost-centre stacks with one of the specified
652             cost centres at the top.</para>
653           </listitem>
654         </varlistentry>
655
656         <varlistentry>
657           <term><option>-hb</option><replaceable>bio</replaceable>,...</term>
658           <indexterm><primary><option>-hb</option></primary><secondary>RTS
659           option</secondary></indexterm>
660           <listitem>
661             <para>Restrict the profile to closures with one of the
662             specified biographies, where
663             <replaceable>bio</replaceable> is one of
664             <literal>lag</literal>, <literal>drag</literal>,
665             <literal>void</literal>, or <literal>use</literal>.</para>
666           </listitem>
667         </varlistentry>
668       </variablelist>
669
670       <para>For example, the following options will generate a
671       retainer profile restricted to <literal>Branch</literal> and
672       <literal>Leaf</literal> constructors:</para>
673
674 <screen>
675 <replaceable>prog</replaceable> +RTS -hr -hdBranch,Leaf
676 </screen>
677
678       <para>There can only be one "break-down" option
679       (eg. <option>-hr</option> in the example above), but there is no
680       limit on the number of further restrictions that may be applied.
681       All the options may be combined, with one exception: GHC doesn't
682       currently support mixing the <option>-hr</option> and
683       <option>-hb</option> options.</para>
684
685       <para>There are two more options which relate to heap
686       profiling:</para>
687
688       <variablelist>
689         <varlistentry>
690           <term><option>-i<replaceable>secs</replaceable></option>:</term>
691           <indexterm><primary><option>-i</option></primary></indexterm>
692           <listitem>
693             <para>Set the profiling (sampling) interval to
694             <replaceable>secs</replaceable> seconds (the default is
695             0.1&nbsp;second).  Fractions are allowed: for example
696             <option>-i0.2</option> will get 5 samples per second.
697             This only affects heap profiling; time profiles are always
698             sampled on a 1/50 second frequency.</para>
699           </listitem>
700         </varlistentry>
701
702         <varlistentry>
703           <term><option>-xt</option></term>
704           <indexterm><primary><option>-xt</option></primary><secondary>RTS option</secondary>
705           </indexterm>
706           <listitem>
707             <para>Include the memory occupied by threads in a heap
708             profile.  Each thread takes up a small area for its thread
709             state in addition to the space allocated for its stack
710             (stacks normally start small and then grow as
711             necessary).</para>
712             
713             <para>This includes the main thread, so using
714             <option>-xt</option> is a good way to see how much stack
715             space the program is using.</para>
716
717             <para>Memory occupied by threads and their stacks is
718             labelled as &ldquo;TSO&rdquo; when displaying the profile
719             by closure description or type description.</para>
720           </listitem>
721         </varlistentry>
722       </variablelist>
723
724     </sect2>
725     
726     <sect2 id="retainer-prof">
727       <title>Retainer Profiling</title>
728
729       <para>Retainer profiling is designed to help answer questions
730       like <quote>why is this data being retained?</quote>.  We start
731       by defining what we mean by a retainer:</para>
732
733       <blockquote>
734         <para>A retainer is either the system stack, or an unevaluated
735         closure (thunk).</para>
736       </blockquote>
737
738       <para>In particular, constructors are <emphasis>not</emphasis>
739       retainers.</para>
740
741       <para>An object A is retained by an object B if object A can be
742       reached by recursively following pointers starting from object
743       B but not meeting any other retainers on the way.  Each object
744       has one or more retainers, collectively called its
745       <firstterm>retainer set</firstterm>.</para>
746
747       <para>When retainer profiling is requested by giving the program
748       the <option>-hr</option> option, a graph is generated which is
749       broken down by retainer set.  A retainer set is displayed as a
750       set of cost-centre stacks; because this is usually too large to
751       fit on the profile graph, each retainer set is numbered and
752       shown abbreviated on the graph along with its number, and the
753       full list of retainer sets is dumped into the file
754       <filename><replaceable>prog</replaceable>.prof</filename>.</para>
755
756       <para>Retainer profiling requires multiple passes over the live
757       heap in order to discover the full retainer set for each
758       object, which can be quite slow.  So we set a limit on the
759       maximum size of a retainer set, where all retainer sets larger
760       than the maximum retainer set size are replaced by the special
761       set <literal>MANY</literal>.  The maximum set size defaults to 8
762       and can be altered with the <option>-R</option> RTS
763       option:</para>
764       
765       <variablelist>
766         <varlistentry>
767           <term><option>-R</option><replaceable>size</replaceable></term>
768           <listitem>
769             <para>Restrict the number of elements in a retainer set to
770             <replaceable>size</replaceable> (default 8).</para>
771           </listitem>
772         </varlistentry>
773       </variablelist>
774
775       <sect3>
776         <title>Hints for using retainer profiling</title>
777
778         <para>The definition of retainers is designed to reflect a
779         common cause of space leaks: a large structure is retained by
780         an unevaluated computation, and will be released once the
781         compuation is forced.  A good example is looking up a value in
782         a finite map, where unless the lookup is forced in a timely
783         manner the unevaluated lookup will cause the whole mapping to
784         be retained.  These kind of space leaks can often be
785         eliminated by forcing the relevant computations to be
786         performed eagerly, using <literal>seq</literal> or strictness
787         annotations on data constructor fields.</para>
788
789         <para>Often a particular data structure is being retained by a
790         chain of unevaluated closures, only the nearest of which will
791         be reported by retainer profiling - for example A retains B, B
792         retains C, and C retains a large structure.  There might be a
793         large number of Bs but only a single A, so A is really the one
794         we're interested in eliminating.  However, retainer profiling
795         will in this case report B as the retainer of the large
796         structure.  To move further up the chain of retainers, we can
797         ask for another retainer profile but this time restrict the
798         profile to B objects, so we get a profile of the retainers of
799         B:</para>
800
801 <screen>
802 <replaceable>prog</replaceable> +RTS -hr -hcB
803 </screen>
804         
805         <para>This trick isn't foolproof, because there might be other
806         B closures in the heap which aren't the retainers we are
807         interested in, but we've found this to be a useful technique
808         in most cases.</para>
809       </sect3>
810     </sect2>
811
812     <sect2 id="biography-prof">
813       <title>Biographical Profiling</title>
814
815       <para>A typical heap object may be in one of the following four
816       states at each point in its lifetime:</para>
817
818       <itemizedlist>
819         <listitem>
820           <para>The <firstterm>lag</firstterm> stage, which is the
821           time between creation and the first use of the
822           object,</para>
823         </listitem>
824         <listitem>
825           <para>the <firstterm>use</firstterm> stage, which lasts from
826           the first use until the last use of the object, and</para>
827         </listitem>
828         <listitem>
829           <para>The <firstterm>drag</firstterm> stage, which lasts
830           from the final use until the last reference to the object
831           is dropped.</para>
832         </listitem>
833         <listitem>
834           <para>An object which is never used is said to be in the
835           <firstterm>void</firstterm> state for its whole
836           lifetime.</para>
837         </listitem>
838       </itemizedlist>
839
840       <para>A biographical heap profile displays the portion of the
841       live heap in each of the four states listed above.  Usually the
842       most interesting states are the void and drag states: live heap
843       in these states is more likely to be wasted space than heap in
844       the lag or use states.</para>
845
846       <para>It is also possible to break down the heap in one or more
847       of these states by a different criteria, by restricting a
848       profile by biography.  For example, to show the portion of the
849       heap in the drag or void state by producer: </para>
850
851 <screen>
852 <replaceable>prog</replaceable> +RTS -hc -hbdrag,void
853 </screen>
854
855       <para>Once you know the producer or the type of the heap in the
856       drag or void states, the next step is usually to find the
857       retainer(s):</para>
858
859 <screen>
860 <replaceable>prog</replaceable> +RTS -hr -hc<replaceable>cc</replaceable>...
861 </screen>
862
863       <para>NOTE: this two stage process is required because GHC
864       cannot currently profile using both biographical and retainer
865       information simultaneously.</para>
866     </sect2>
867
868
869
870
871
872   </sect1>
873
874   <sect1 id="prof-xml-tool">
875     <title>Graphical time/allocation profile</title>
876
877     <para>You can view the time and allocation profiling graph of your
878     program graphically, using <command>ghcprof</command>.  This is a
879     new tool with GHC 4.08, and will eventually be the de-facto
880     standard way of viewing GHC profiles<footnote><para>Actually this
881     isn't true any more, we are working on a new tool for
882     displaying heap profiles using Gtk+HS, so
883     <command>ghcprof</command> may go away at some point in the future.</para>
884       </footnote></para>
885
886     <para>To run <command>ghcprof</command>, you need
887     <productname>daVinci</productname> installed, which can be
888     obtained from <ulink
889     url="http://www.informatik.uni-bremen.de/daVinci/"><citetitle>The Graph
890     Visualisation Tool daVinci</citetitle></ulink>.  Install one of
891     the binary
892     distributions<footnote><para><productname>daVinci</productname> is
893     sadly not open-source :-(.</para></footnote>, and set your
894     <envar>DAVINCIHOME</envar> environment variable to point to the
895     installation directory.</para>
896
897     <para><command>ghcprof</command> uses an XML-based profiling log
898     format, and you therefore need to run your program with a
899     different option: <option>-px</option>.  The file generated is
900     still called <filename>&lt;prog&gt;.prof</filename>.  To see the
901     profile, run <command>ghcprof</command> like this:</para>
902
903     <indexterm><primary><option>-px</option></primary></indexterm>
904
905 <screen>
906 $ ghcprof &lt;prog&gt;.prof
907 </screen>
908
909     <para>which should pop up a window showing the call-graph of your
910     program in glorious detail.  More information on using
911     <command>ghcprof</command> can be found at <ulink
912     url="http://www.dcs.warwick.ac.uk/people/academic/Stephen.Jarvis/profiler/index.html"><citetitle>The
913     Cost-Centre Stack Profiling Tool for
914     GHC</citetitle></ulink>.</para>
915
916   </sect1>
917
918   <sect1 id="hp2ps">
919     <title><command>hp2ps</command>&ndash;&ndash;heap profile to PostScript</title>
920
921     <indexterm><primary><command>hp2ps</command></primary></indexterm>
922     <indexterm><primary>heap profiles</primary></indexterm>
923     <indexterm><primary>postscript, from heap profiles</primary></indexterm>
924     <indexterm><primary><option>-h&lt;break-down&gt;</option></primary></indexterm>
925     
926     <para>Usage:</para>
927     
928 <screen>
929 hp2ps [flags] [&lt;file&gt;[.hp]]
930 </screen>
931
932     <para>The program
933     <command>hp2ps</command><indexterm><primary>hp2ps
934     program</primary></indexterm> converts a heap profile as produced
935     by the <option>-h&lt;break-down&gt;</option> runtime option into a
936     PostScript graph of the heap profile. By convention, the file to
937     be processed by <command>hp2ps</command> has a
938     <filename>.hp</filename> extension. The PostScript output is
939     written to <filename>&lt;file&gt;@.ps</filename>. If
940     <filename>&lt;file&gt;</filename> is omitted entirely, then the
941     program behaves as a filter.</para>
942
943     <para><command>hp2ps</command> is distributed in
944     <filename>ghc/utils/hp2ps</filename> in a GHC source
945     distribution. It was originally developed by Dave Wakeling as part
946     of the HBC/LML heap profiler.</para>
947
948     <para>The flags are:</para>
949
950     <variablelist>
951       
952       <varlistentry>
953         <term><option>-d</option></term>
954         <listitem>
955           <para>In order to make graphs more readable,
956           <command>hp2ps</command> sorts the shaded bands for each
957           identifier. The default sort ordering is for the bands with
958           the largest area to be stacked on top of the smaller ones.
959           The <option>-d</option> option causes rougher bands (those
960           representing series of values with the largest standard
961           deviations) to be stacked on top of smoother ones.</para>
962         </listitem>
963       </varlistentry>
964
965       <varlistentry>
966         <term><option>-b</option></term>
967         <listitem>
968           <para>Normally, <command>hp2ps</command> puts the title of
969           the graph in a small box at the top of the page. However, if
970           the JOB string is too long to fit in a small box (more than
971           35 characters), then <command>hp2ps</command> will choose to
972           use a big box instead.  The <option>-b</option> option
973           forces <command>hp2ps</command> to use a big box.</para>
974         </listitem>
975       </varlistentry>
976
977       <varlistentry>
978         <term><option>-e&lt;float&gt;[in&verbar;mm&verbar;pt]</option></term>
979         <listitem>
980           <para>Generate encapsulated PostScript suitable for
981           inclusion in LaTeX documents.  Usually, the PostScript graph
982           is drawn in landscape mode in an area 9 inches wide by 6
983           inches high, and <command>hp2ps</command> arranges for this
984           area to be approximately centred on a sheet of a4 paper.
985           This format is convenient of studying the graph in detail,
986           but it is unsuitable for inclusion in LaTeX documents.  The
987           <option>-e</option> option causes the graph to be drawn in
988           portrait mode, with float specifying the width in inches,
989           millimetres or points (the default).  The resulting
990           PostScript file conforms to the Encapsulated PostScript
991           (EPS) convention, and it can be included in a LaTeX document
992           using Rokicki's dvi-to-PostScript converter
993           <command>dvips</command>.</para>
994         </listitem>
995       </varlistentry>
996
997       <varlistentry>
998         <term><option>-g</option></term>
999         <listitem>
1000           <para>Create output suitable for the <command>gs</command>
1001           PostScript previewer (or similar). In this case the graph is
1002           printed in portrait mode without scaling. The output is
1003           unsuitable for a laser printer.</para>
1004         </listitem>
1005       </varlistentry>
1006
1007       <varlistentry>
1008         <term><option>-l</option></term>
1009         <listitem>
1010           <para>Normally a profile is limited to 20 bands with
1011           additional identifiers being grouped into an
1012           <literal>OTHER</literal> band. The <option>-l</option> flag
1013           removes this 20 band and limit, producing as many bands as
1014           necessary. No key is produced as it won't fit!. It is useful
1015           for creation time profiles with many bands.</para>
1016         </listitem>
1017       </varlistentry>
1018
1019       <varlistentry>
1020         <term><option>-m&lt;int&gt;</option></term>
1021         <listitem>
1022           <para>Normally a profile is limited to 20 bands with
1023           additional identifiers being grouped into an
1024           <literal>OTHER</literal> band. The <option>-m</option> flag
1025           specifies an alternative band limit (the maximum is
1026           20).</para>
1027
1028           <para><option>-m0</option> requests the band limit to be
1029           removed. As many bands as necessary are produced. However no
1030           key is produced as it won't fit! It is useful for displaying
1031           creation time profiles with many bands.</para>
1032         </listitem>
1033       </varlistentry>
1034
1035       <varlistentry>
1036         <term><option>-p</option></term>
1037         <listitem>
1038           <para>Use previous parameters. By default, the PostScript
1039           graph is automatically scaled both horizontally and
1040           vertically so that it fills the page.  However, when
1041           preparing a series of graphs for use in a presentation, it
1042           is often useful to draw a new graph using the same scale,
1043           shading and ordering as a previous one. The
1044           <option>-p</option> flag causes the graph to be drawn using
1045           the parameters determined by a previous run of
1046           <command>hp2ps</command> on <filename>file</filename>. These
1047           are extracted from <filename>file@.aux</filename>.</para>
1048         </listitem>
1049       </varlistentry>
1050
1051       <varlistentry>
1052         <term><option>-s</option></term>
1053         <listitem>
1054           <para>Use a small box for the title.</para>
1055         </listitem>
1056       </varlistentry>
1057       
1058       <varlistentry>
1059         <term><option>-t&lt;float&gt;</option></term>
1060         <listitem>
1061           <para>Normally trace elements which sum to a total of less
1062           than 1&percnt; of the profile are removed from the
1063           profile. The <option>-t</option> option allows this
1064           percentage to be modified (maximum 5&percnt;).</para>
1065
1066           <para><option>-t0</option> requests no trace elements to be
1067           removed from the profile, ensuring that all the data will be
1068           displayed.</para>
1069         </listitem>
1070       </varlistentry>
1071
1072       <varlistentry>
1073         <term><option>-c</option></term>
1074         <listitem>
1075           <para>Generate colour output.</para>
1076         </listitem>
1077       </varlistentry>
1078       
1079       <varlistentry>
1080         <term><option>-y</option></term>
1081         <listitem>
1082           <para>Ignore marks.</para>
1083         </listitem>
1084       </varlistentry>
1085       
1086       <varlistentry>
1087         <term><option>-?</option></term>
1088         <listitem>
1089           <para>Print out usage information.</para>
1090         </listitem>
1091       </varlistentry>
1092     </variablelist>
1093
1094
1095     <sect2 id="manipulating-hp">
1096       <title>Manipulating the hp file</title>
1097
1098 <para>(Notes kindly offered by Jan-Willhem Maessen.)</para>
1099
1100 <para>
1101 The <filename>FOO.hp</filename> file produced when you ask for the
1102 heap profile of a program <filename>FOO</filename> is a text file with a particularly
1103 simple structure. Here's a representative example, with much of the
1104 actual data omitted:
1105 <screen>
1106 JOB "FOO -hC"
1107 DATE "Thu Dec 26 18:17 2002"
1108 SAMPLE_UNIT "seconds"
1109 VALUE_UNIT "bytes"
1110 BEGIN_SAMPLE 0.00
1111 END_SAMPLE 0.00
1112 BEGIN_SAMPLE 15.07
1113   ... sample data ...
1114 END_SAMPLE 15.07
1115 BEGIN_SAMPLE 30.23
1116   ... sample data ...
1117 END_SAMPLE 30.23
1118 ... etc.
1119 BEGIN_SAMPLE 11695.47
1120 END_SAMPLE 11695.47
1121 </screen>
1122 The first four lines (<literal>JOB</literal>, <literal>DATE</literal>, <literal>SAMPLE_UNIT</literal>, <literal>VALUE_UNIT</literal>) form a
1123 header.  Each block of lines starting with <literal>BEGIN_SAMPLE</literal> and ending
1124 with <literal>END_SAMPLE</literal> forms a single sample (you can think of this as a
1125 vertical slice of your heap profile).  The hp2ps utility should accept
1126 any input with a properly-formatted header followed by a series of
1127 *complete* samples.
1128 </para>
1129 </sect2>
1130
1131     <sect2>
1132       <title>Zooming in on regions of your profile</title>
1133
1134 <para>
1135 You can look at particular regions of your profile simply by loading a
1136 copy of the <filename>.hp</filename> file into a text editor and deleting the unwanted
1137 samples.  The resulting <filename>.hp</filename> file can be run through <command>hp2ps</command> and viewed
1138 or printed.
1139 </para>
1140 </sect2>
1141
1142     <sect2>
1143       <title>Viewing the heap profile of a running program</title>
1144
1145 <para>
1146 The <filename>.hp</filename> file is generated incrementally as your
1147 program runs.  In principle, running <command>hp2ps</command> on the incomplete file
1148 should produce a snapshot of your program's heap usage.  However, the
1149 last sample in the file may be incomplete, causing <command>hp2ps</command> to fail.  If
1150 you are using a machine with UNIX utilities installed, it's not too
1151 hard to work around this problem (though the resulting command line
1152 looks rather Byzantine):
1153 <screen>
1154   head -`fgrep -n END_SAMPLE FOO.hp | tail -1 | cut -d : -f 1` FOO.hp \
1155     | hp2ps > FOO.ps
1156 </screen>
1157
1158 The command <command>fgrep -n END_SAMPLE FOO.hp</command> finds the
1159 end of every complete sample in <filename>FOO.hp</filename>, and labels each sample with
1160 its ending line number.  We then select the line number of the last
1161 complete sample using <command>tail</command> and <command>cut</command>.  This is used as a
1162 parameter to <command>head</command>; the result is as if we deleted the final
1163 incomplete sample from <filename>FOO.hp</filename>.  This results in a properly-formatted
1164 .hp file which we feed directly to <command>hp2ps</command>.
1165 </para>
1166 </sect2>
1167     <sect2>
1168       <title>Viewing a heap profile in real time</title>
1169
1170 <para>
1171 The <command>gv</command> and <command>ghostview</command> programs
1172 have a "watch file" option can be used to view an up-to-date heap
1173 profile of your program as it runs.  Simply generate an incremental
1174 heap profile as described in the previous section.  Run <command>gv</command> on your
1175 profile:
1176 <screen>
1177   gv -watch -seascape FOO.ps 
1178 </screen>
1179 If you forget the <literal>-watch</literal> flag you can still select
1180 "Watch file" from the "State" menu.  Now each time you generate a new
1181 profile <filename>FOO.ps</filename> the view will update automatically.
1182 </para>
1183
1184 <para>
1185 This can all be encapsulated in a little script:
1186 <screen>
1187   #!/bin/sh
1188   head -`fgrep -n END_SAMPLE FOO.hp | tail -1 | cut -d : -f 1` FOO.hp \
1189     | hp2ps > FOO.ps
1190   gv -watch -seascape FOO.ps &amp;
1191   while [ 1 ] ; do
1192     sleep 10 # We generate a new profile every 10 seconds.
1193     head -`fgrep -n END_SAMPLE FOO.hp | tail -1 | cut -d : -f 1` FOO.hp \
1194       | hp2ps > FOO.ps
1195   done
1196 </screen>
1197 Occasionally <command>gv</command> will choke as it tries to read an incomplete copy of
1198 <filename>FOO.ps</filename> (because <command>hp2ps</command> is still running as an update
1199 occurs).  A slightly more complicated script works around this
1200 problem, by using the fact that sending a SIGHUP to gv will cause it
1201 to re-read its input file:
1202 <screen>
1203   #!/bin/sh
1204   head -`fgrep -n END_SAMPLE FOO.hp | tail -1 | cut -d : -f 1` FOO.hp \
1205     | hp2ps > FOO.ps
1206   gv FOO.ps &amp;
1207   gvpsnum=$!
1208   while [ 1 ] ; do
1209     sleep 10
1210     head -`fgrep -n END_SAMPLE FOO.hp | tail -1 | cut -d : -f 1` FOO.hp \
1211       | hp2ps > FOO.ps
1212     kill -HUP $gvpsnum
1213   done    
1214 </screen>
1215 </para>
1216 </sect2>
1217
1218
1219   </sect1>
1220
1221   <sect1 id="ticky-ticky">
1222     <title>Using &ldquo;ticky-ticky&rdquo; profiling (for implementors)</title>
1223     <indexterm><primary>ticky-ticky profiling</primary></indexterm>
1224
1225     <para>(ToDo: document properly.)</para>
1226
1227     <para>It is possible to compile Glasgow Haskell programs so that
1228     they will count lots and lots of interesting things, e.g., number
1229     of updates, number of data constructors entered, etc., etc.  We
1230     call this &ldquo;ticky-ticky&rdquo;
1231     profiling,<indexterm><primary>ticky-ticky
1232     profiling</primary></indexterm> <indexterm><primary>profiling,
1233     ticky-ticky</primary></indexterm> because that's the sound a Sun4
1234     makes when it is running up all those counters
1235     (<emphasis>slowly</emphasis>).</para>
1236
1237     <para>Ticky-ticky profiling is mainly intended for implementors;
1238     it is quite separate from the main &ldquo;cost-centre&rdquo;
1239     profiling system, intended for all users everywhere.</para>
1240
1241     <para>To be able to use ticky-ticky profiling, you will need to
1242     have built appropriate libraries and things when you made the
1243     system.  See &ldquo;Customising what libraries to build,&rdquo; in
1244     the installation guide.</para>
1245
1246     <para>To get your compiled program to spit out the ticky-ticky
1247     numbers, use a <option>-r</option> RTS
1248     option<indexterm><primary>-r RTS option</primary></indexterm>.
1249     See <xref linkend="runtime-control"/>.</para>
1250
1251     <para>Compiling your program with the <option>-ticky</option>
1252     switch yields an executable that performs these counts.  Here is a
1253     sample ticky-ticky statistics file, generated by the invocation
1254     <command>foo +RTS -rfoo.ticky</command>.</para>
1255
1256 <screen>
1257  foo +RTS -rfoo.ticky
1258
1259
1260 ALLOCATIONS: 3964631 (11330900 words total: 3999476 admin, 6098829 goods, 1232595 slop)
1261                                 total words:        2     3     4     5    6+
1262   69647 (  1.8%) function values                 50.0  50.0   0.0   0.0   0.0
1263 2382937 ( 60.1%) thunks                           0.0  83.9  16.1   0.0   0.0
1264 1477218 ( 37.3%) data values                     66.8  33.2   0.0   0.0   0.0
1265       0 (  0.0%) big tuples
1266       2 (  0.0%) black holes                      0.0 100.0   0.0   0.0   0.0
1267       0 (  0.0%) prim things
1268   34825 (  0.9%) partial applications             0.0   0.0   0.0 100.0   0.0
1269       2 (  0.0%) thread state objects             0.0   0.0   0.0   0.0 100.0
1270
1271 Total storage-manager allocations: 3647137 (11882004 words)
1272         [551104 words lost to speculative heap-checks]
1273
1274 STACK USAGE:
1275
1276 ENTERS: 9400092  of which 2005772 (21.3%) direct to the entry code
1277                   [the rest indirected via Node's info ptr]
1278 1860318 ( 19.8%) thunks
1279 3733184 ( 39.7%) data values
1280 3149544 ( 33.5%) function values
1281                   [of which 1999880 (63.5%) bypassed arg-satisfaction chk]
1282  348140 (  3.7%) partial applications
1283  308906 (  3.3%) normal indirections
1284       0 (  0.0%) permanent indirections
1285
1286 RETURNS: 5870443
1287 2137257 ( 36.4%) from entering a new constructor
1288                   [the rest from entering an existing constructor]
1289 2349219 ( 40.0%) vectored [the rest unvectored]
1290
1291 RET_NEW:         2137257:  32.5% 46.2% 21.3%  0.0%  0.0%  0.0%  0.0%  0.0%  0.0%
1292 RET_OLD:         3733184:   2.8% 67.9% 29.3%  0.0%  0.0%  0.0%  0.0%  0.0%  0.0%
1293 RET_UNBOXED_TUP:       2:   0.0%  0.0%100.0%  0.0%  0.0%  0.0%  0.0%  0.0%  0.0%
1294
1295 RET_VEC_RETURN : 2349219:   0.0%  0.0%100.0%  0.0%  0.0%  0.0%  0.0%  0.0%  0.0%
1296
1297 UPDATE FRAMES: 2241725 (0 omitted from thunks)
1298 SEQ FRAMES:    1
1299 CATCH FRAMES:  1
1300 UPDATES: 2241725
1301       0 (  0.0%) data values
1302   34827 (  1.6%) partial applications
1303                   [2 in place, 34825 allocated new space]
1304 2206898 ( 98.4%) updates to existing heap objects (46 by squeezing)
1305 UPD_CON_IN_NEW:         0:       0      0      0      0      0      0      0      0      0
1306 UPD_PAP_IN_NEW:     34825:       0      0      0  34825      0      0      0      0      0
1307
1308 NEW GEN UPDATES: 2274700 ( 99.9%)
1309
1310 OLD GEN UPDATES: 1852 (  0.1%)
1311
1312 Total bytes copied during GC: 190096
1313
1314 **************************************************
1315 3647137 ALLOC_HEAP_ctr
1316 11882004 ALLOC_HEAP_tot
1317   69647 ALLOC_FUN_ctr
1318   69647 ALLOC_FUN_adm
1319   69644 ALLOC_FUN_gds
1320   34819 ALLOC_FUN_slp
1321   34831 ALLOC_FUN_hst_0
1322   34816 ALLOC_FUN_hst_1
1323       0 ALLOC_FUN_hst_2
1324       0 ALLOC_FUN_hst_3
1325       0 ALLOC_FUN_hst_4
1326 2382937 ALLOC_UP_THK_ctr
1327       0 ALLOC_SE_THK_ctr
1328  308906 ENT_IND_ctr
1329       0 E!NT_PERM_IND_ctr requires +RTS -Z
1330 [... lots more info omitted ...]
1331       0 GC_SEL_ABANDONED_ctr
1332       0 GC_SEL_MINOR_ctr
1333       0 GC_SEL_MAJOR_ctr
1334       0 GC_FAILED_PROMOTION_ctr
1335   47524 GC_WORDS_COPIED_ctr
1336 </screen>
1337
1338     <para>The formatting of the information above the row of asterisks
1339     is subject to change, but hopefully provides a useful
1340     human-readable summary.  Below the asterisks <emphasis>all
1341     counters</emphasis> maintained by the ticky-ticky system are
1342     dumped, in a format intended to be machine-readable: zero or more
1343     spaces, an integer, a space, the counter name, and a newline.</para>
1344
1345     <para>In fact, not <emphasis>all</emphasis> counters are
1346     necessarily dumped; compile- or run-time flags can render certain
1347     counters invalid.  In this case, either the counter will simply
1348     not appear, or it will appear with a modified counter name,
1349     possibly along with an explanation for the omission (notice
1350     <literal>ENT&lowbar;PERM&lowbar;IND&lowbar;ctr</literal> appears
1351     with an inserted <literal>!</literal> above).  Software analysing
1352     this output should always check that it has the counters it
1353     expects.  Also, beware: some of the counters can have
1354     <emphasis>large</emphasis> values!</para>
1355
1356   </sect1>
1357
1358 </chapter>
1359
1360 <!-- Emacs stuff:
1361      ;;; Local Variables: ***
1362      ;;; mode: xml ***
1363      ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter") ***
1364      ;;; End: ***
1365  -->