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