1 <chapter id="profiling">
2 <title>Profiling</Title>
3 <indexterm><primary>profiling</primary>
5 <indexterm><primary>cost-centre profiling</primary></indexterm>
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>
11 <Para> Any comments, suggestions and/or improvements you have are
12 welcome. Recommended “profiling tricks” would be
13 especially cool! </Para>
15 <para>Profiling a program is a three-step process:</para>
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>
26 <indexterm><primary><literal>-auto</literal></primary>
28 <indexterm><primary><literal>-auto-all</literal></primary>
33 <para> Run your program with one of the profiling options
34 <literal>-p</literal> or <literal>-h</literal>. This generates
35 a file of profiling information.</para>
36 <indexterm><primary><literal>-p</literal></primary><secondary>RTS
37 option</secondary></indexterm>
38 <indexterm><primary><literal>-h</literal></primary><secondary>RTS
39 option</secondary></indexterm>
43 <para> Examine the generated profiling information, using one of
44 GHC's profiling tools. The tool to use will depend on the kind
45 of profiling information generated.</para>
51 <title>Cost centres and cost-centre stacks</title>
53 <para>GHC's profiling system assigns <firstterm>costs</firstterm>
54 to <firstterm>cost centres</firstterm>. A cost is simply the time
55 or space required to evaluate an expression. Cost centres are
56 program annotations around expressions; all costs incurred by the
57 annotated expression are assigned to the enclosing cost centre.
58 Furthermore, GHC will remember the stack of enclosing cost centres
59 for any given expression at run-time and generate a call-graph of
60 cost attributions.</para>
62 <para>Let's take a look at an example:</para>
65 main = print (nfib 25)
66 nfib n = if n < 2 then 1 else nfib (n-1) + nfib (n-2)
69 <para>Compile and run this program as follows:</para>
72 $ ghc -prof -auto-all -o Main Main.hs
78 <para>When a GHC-compiled program is run with the
79 <option>-p</option> RTS option, it generates a file called
80 <filename><prog>.prof</filename>. In this case, the file
81 will contain something like this:</para>
84 Fri May 12 14:06 2000 Time and Allocation Profiling Report (Final)
88 total time = 0.14 secs (7 ticks @ 20 ms)
89 total alloc = 8,741,204 bytes (excludes profiling overheads)
91 COST CENTRE MODULE %time %alloc
97 COST CENTRE MODULE scc %time %alloc %time %alloc
99 MAIN MAIN 0 0.0 0.0 100.0 100.0
100 main Main 0 0.0 0.0 0.0 0.0
101 CAF PrelHandle 3 0.0 0.0 0.0 0.0
102 CAF PrelAddr 1 0.0 0.0 0.0 0.0
103 CAF Main 6 0.0 0.0 100.0 100.0
104 main Main 1 0.0 0.0 100.0 100.0
105 nfib Main 242785 100.0 100.0 100.0 100.0
109 <para>The first part of the file gives the program name and
110 options, and the total time and total memory allocation measured
111 during the run of the program (note that the total memory
112 allocation figure isn't the same as the amount of
113 <emphasis>live</emphasis> memory needed by the program at any one
114 time; the latter can be determined using heap profiling, which we
115 will describe shortly).</para>
117 <para>The second part of the file is a break-down by cost centre
118 of the most costly functions in the program. In this case, there
119 was only one significant function in the program, namely
120 <function>nfib</function>, and it was responsible for 100%
121 of both the time and allocation costs of the program.</para>
123 <para>The third and final section of the file gives a profile
124 break-down by cost-centre stack. This is roughly a call-graph
125 profile of the program. In the example above, it is clear that
126 the costly call to <function>nfib</function> came from
127 <function>main</function>.</para>
129 <para>The time and allocation incurred by a given part of the
130 program is displayed in two ways: “individual”, which
131 are the costs incurred by the code covered by this cost centre
132 stack alone, and “inherited”, which includes the costs
133 incurred by all the children of this node.</para>
135 <para>The usefulness of cost-centre stacks is better demonstrated
136 by modifying the example slightly:</para>
139 main = print (f 25 + g 25)
141 g n = nfib (n `div` 2)
142 nfib n = if n < 2 then 1 else nfib (n-1) + nfib (n-2)
145 <para>Compile and run this program as before, and take a look at
146 the new profiling results:</para>
149 COST CENTRE MODULE scc %time %alloc %time %alloc
151 MAIN MAIN 0 0.0 0.0 100.0 100.0
152 main Main 0 0.0 0.0 0.0 0.0
153 CAF PrelHandle 3 0.0 0.0 0.0 0.0
154 CAF PrelAddr 1 0.0 0.0 0.0 0.0
155 CAF Main 9 0.0 0.0 100.0 100.0
156 main Main 1 0.0 0.0 100.0 100.0
157 g Main 1 0.0 0.0 0.0 0.2
158 nfib Main 465 0.0 0.2 0.0 0.2
159 f Main 1 0.0 0.0 100.0 99.8
160 nfib Main 242785 100.0 99.8 100.0 99.8
163 <para>Now although we had two calls to <function>nfib</function>
164 in the program, it is immediately clear that it was the call from
165 <function>f</function> which took all the time.</para>
167 <para>The actual meaning of the various columns in the output is:</para>
173 <para>The number of times this particular point in the call
174 graph was entered.</para>
179 <term>individual %time</term>
181 <para>The percentage of the total run time of the program
182 spent at this point in the call graph.</para>
187 <term>individual %alloc</term>
189 <para>The percentage of the total memory allocations
190 (excluding profiling overheads) of the program made by this
196 <term>inherited %time</term>
198 <para>The percentage of the total run time of the program
199 spent below this point in the call graph.</para>
204 <term>inherited %alloc</term>
206 <para>The percentage of the total memory allocations
207 (excluding profiling overheads) of the program made by this
208 call and all of its sub-calls.</para>
213 <para>In addition you can use the <Option>-P</Option> RTS option
214 <indexterm><primary><option>-P</option></primary></indexterm> to
215 get the following additional information:</para>
219 <term><literal>ticks</literal></term>
221 <Para>The raw number of time “ticks” which were
222 attributed to this cost-centre; from this, we get the
223 <literal>%time</literal> figure mentioned
229 <term><literal>bytes</literal></term>
231 <Para>Number of bytes allocated in the heap while in this
232 cost-centre; again, this is the raw number from which we get
233 the <literal>%alloc</literal> figure mentioned
239 <para>What about recursive functions, and mutually recursive
240 groups of functions? Where are the costs attributed? Well,
241 although GHC does keep information about which groups of functions
242 called each other recursively, this information isn't displayed in
243 the basic time and allocation profile, instead the call-graph is
244 flattened into a tree. The XML profiling tool (described in <xref
245 linkend="prof-xml-tool">) will be able to display real loops in
246 the call-graph.</para>
248 <sect2><title>Inserting cost centres by hand</title>
250 <para>Cost centres are just program annotations. When you say
251 <option>-auto-all</option> to the compiler, it automatically
252 inserts a cost centre annotation around every top-level function
253 in your program, but you are entirely free to add the cost
254 centre annotations yourself.</para>
256 <para>The syntax of a cost centre annotation is</para>
259 {-# SCC "name" #-} <expression>
262 <para>where <literal>"name"</literal> is an aribrary string,
263 that will become the name of your cost centre as it appears
264 in the profiling output, and
265 <literal><expression></literal> is any Haskell
266 expression. An <literal>SCC</literal> annotation extends as
267 far to the right as possible when parsing.</para>
271 <sect2 id="prof-rules">
272 <title>Rules for attributing costs</title>
274 <para>The cost of evaluating any expression in your program is
275 attributed to a cost-centre stack using the following rules:</para>
279 <para>If the expression is part of the
280 <firstterm>one-off</firstterm> costs of evaluating the
281 enclosing top-level definition, then costs are attributed to
282 the stack of lexically enclosing <literal>SCC</literal>
283 annotations on top of the special <literal>CAF</literal>
288 <para>Otherwise, costs are attributed to the stack of
289 lexically-enclosing <literal>SCC</literal> annotations,
290 appended to the cost-centre stack in effect at the
291 <firstterm>call site</firstterm> of the current top-level
292 definition<footnote> <para>The call-site is just the place
293 in the source code which mentions the particular function or
294 variable.</para></footnote>. Notice that this is a recursive
299 <para>What do we mean by one-off costs? Well, Haskell is a lazy
300 language, and certain expressions are only ever evaluated once.
301 For example, if we write:</para>
307 <para>then <varname>x</varname> will only be evaluated once (if
308 at all), and subsequent demands for <varname>x</varname> will
309 immediately get to see the cached result. The definition
310 <varname>x</varname> is called a CAF (Constant Applicative
311 Form), because it has no arguments.</para>
313 <para>For the purposes of profiling, we say that the expression
314 <literal>nfib 25</literal> belongs to the one-off costs of
315 evaluating <varname>x</varname>.</para>
317 <para>Since one-off costs aren't strictly speaking part of the
318 call-graph of the program, they are attributed to a special
319 top-level cost centre, <literal>CAF</literal>. There may be one
320 <literal>CAF</literal> cost centre for each module (the
321 default), or one for each top-level definition with any one-off
322 costs (this behaviour can be selected by giving GHC the
323 <option>-caf-all</option> flag).</para>
325 <indexterm><primary><literal>-caf-all</literal></primary>
328 <para>If you think you have a weird profile, or the call-graph
329 doesn't look like you expect it to, feel free to send it (and
330 your program) to us at
331 <email>glasgow-haskell-bugs@haskell.org</email>.</para>
336 <sect1 id="prof-heap">
337 <title>Profiling memory usage</title>
339 <para>In addition to profiling the time and allocation behaviour
340 of your program, you can also generate a graph of its memory usage
341 over time. This is useful for detecting the causes of
342 <firstterm>space leaks</firstterm>, when your program holds on to
343 more memory at run-time that it needs to. Space leaks lead to
344 longer run-times due to heavy garbage collector ativity, and may
345 even cause the program to run out of memory altogether.</para>
347 <para>To generate a heap profile from your program, compile it as
348 before, but this time run it with the <option>-h</option> runtime
349 option. This generates a file
350 <filename><prog>.hp</filename> file, which you then process
351 with <command>hp2ps</command> to produce a Postscript file
352 <filename><prog>.ps</filename>. The Postscript file can be
353 viewed with something like <command>ghostview</command>, or
354 printed out on a Postscript-compatible printer.</para>
356 <para>For the RTS options that control the kind of heap profile
357 generated, see <xref linkend="prof-rts-options">. Details on the
358 usage of the <command>hp2ps</command> program are given in <xref
359 linkend="hp2ps"></para>
363 <sect1 id="prof-xml-tool">
364 <title>Graphical time/allocation profile</title>
366 <para>You can view the time and allocation profiling graph of your
367 program graphically, using <command>ghcprof</command>. This is a
368 new tool with GHC 4.08, and will eventually be the de-facto
369 standard way of viewing GHC profiles.</para>
371 <para>To run <command>ghcprof</command>, you need
372 <productname>daVinci</productname> installed, which can be
374 url="http://www.tzi.de/~davinci/"><citetitle>The Graph
375 Visualisation Tool daVinci</citetitle></ulink>. Install one of
377 distributions<footnote><para><productname>daVinci</productname> is
378 sadly not open-source :-(.</para></footnote>, and set your
379 <envar>DAVINCIHOME</envar> environment variable to point to the
380 installation directory.</para>
382 <para><command>ghcprof</command> uses an XML-based profiling log
383 format, and you therefore need to run your program with a
384 different option: <option>-px</option>. The file generated is
385 still called <filename><prog>.prof</filename>. To see the
386 profile, run <command>ghcprof</command> like this:</para>
388 <indexterm><primary><option>-px</option></primary></indexterm>
391 $ ghcprof <prog>.prof
394 <para>which should pop up a window showing the call-graph of your
395 program in glorious detail. More information on using
396 <command>ghcprof</command> can be found at <ulink
397 url="http://www.dcs.warwick.ac.uk/people/academic/Stephen.Jarvis/profiler/index.html"><citetitle>The
398 Cost-Centre Stack Profiling Tool for
399 GHC</citetitle></ulink>.</para>
403 <sect1 id="prof-compiler-options">
404 <title>Compiler options for profiling</title>
406 <indexterm><primary>profiling</primary><secondary>options</secondary></indexterm>
407 <indexterm><primary>options</primary><secondary>for profiling</secondary></indexterm>
409 <Para> To make use of the cost centre profiling system
410 <Emphasis>all</Emphasis> modules must be compiled and linked with
411 the <Option>-prof</Option> option. Any
412 <Function>_scc_</Function> constructs you've put in
413 your source will spring to life.</Para>
415 <indexterm><primary><literal>-prof</literal></primary></indexterm>
417 <Para> Without a <Option>-prof</Option> option, your
418 <Function>_scc_</Function>s are ignored; so you can
419 compiled <Function>_scc_</Function>-laden code
420 without changing it.</Para>
422 <Para>There are a few other profiling-related compilation options.
423 Use them <Emphasis>in addition to</Emphasis>
424 <Option>-prof</Option>. These do not have to be used consistently
425 for all modules in a program.</Para>
430 <term><Option>-auto</Option>:</Term>
431 <indexterm><primary><literal>-auto</literal></primary></indexterm>
432 <indexterm><primary>cost centres</primary><secondary>automatically inserting</secondary></indexterm>
434 <Para> GHC will automatically add
435 <Function>_scc_</Function> constructs for all
436 top-level, exported functions.</Para>
441 <term><Option>-auto-all</Option>:</Term>
442 <indexterm><primary><literal>-auto-all</literal></primary></indexterm>
444 <Para> <Emphasis>All</Emphasis> top-level functions,
445 exported or not, will be automatically
446 <Function>_scc_</Function>'d.</Para>
451 <term><Option>-caf-all</Option>:</Term>
452 <indexterm><primary><literal>-caf-all</literal></primary></indexterm>
454 <Para> The costs of all CAFs in a module are usually
455 attributed to one “big” CAF cost-centre. With
456 this option, all CAFs get their own cost-centre. An
457 “if all else fails” option…</Para>
462 <term><Option>-ignore-scc</Option>:</Term>
463 <indexterm><primary><literal>-ignore-scc</literal></primary></indexterm>
465 <Para>Ignore any <Function>_scc_</Function>
466 constructs, so a module which already has
467 <Function>_scc_</Function>s can be compiled
468 for profiling with the annotations ignored.</Para>
476 <sect1 id="prof-rts-options">
477 <title>Runtime options for profiling</Title>
479 <indexterm><primary>profiling RTS options</primary></indexterm>
480 <indexterm><primary>RTS options, for profiling</primary></indexterm>
482 <Para>It isn't enough to compile your program for profiling with
483 <Option>-prof</Option>!</Para>
485 <Para>When you <Emphasis>run</Emphasis> your profiled program, you
486 must tell the runtime system (RTS) what you want to profile (e.g.,
487 time and/or space), and how you wish the collected data to be
488 reported. You also may wish to set the sampling interval used in
489 time profiling.</Para>
491 <Para>Executive summary: <command>./a.out +RTS -pT</command>
492 produces a time profile in <Filename>a.out.prof</Filename>;
493 <command>./a.out +RTS -hC</command> produces space-profiling info
494 which can be mangled by <command>hp2ps</command> and viewed with
495 <command>ghostview</command> (or equivalent).</Para>
497 <Para>Profiling runtime flags are passed to your program between
498 the usual <Option>+RTS</Option> and <Option>-RTS</Option>
504 <term><Option>-p</Option> or <Option>-P</Option>:</Term>
505 <indexterm><primary><option>-p</option></primary></indexterm>
506 <indexterm><primary><option>-P</option></primary></indexterm>
507 <indexterm><primary>time profile</primary></indexterm>
509 <Para>The <Option>-p</Option> option produces a standard
510 <Emphasis>time profile</Emphasis> report. It is written
512 <Filename><program>.prof</Filename>.</Para>
514 <Para>The <Option>-P</Option> option produces a more
515 detailed report containing the actual time and allocation
516 data as well. (Not used much.)</Para>
521 <term><option>-px</option>:</term>
522 <indexterm><primary><option>-px</option></primary></indexterm>
524 <para>The <option>-px</option> option generates profiling
525 information in the XML format understood by our new
526 profiling tool, see <xref linkend="prof-xml-tool">.</para>
531 <term><Option>-i<secs></Option>:</Term>
532 <indexterm><primary><option>-i</option></primary></indexterm>
534 <Para> Set the profiling (sampling) interval to
535 <literal><secs></literal> seconds (the default is
536 1 second). Fractions are allowed: for example
537 <Option>-i0.2</Option> will get 5 samples per second. This
538 only affects heap profiling; time profiles are always
539 sampled on a 1/50 second frequency.</Para>
544 <term><Option>-h<break-down></Option>:</Term>
545 <indexterm><primary><option>-h<break-down></option></primary></indexterm>
546 <indexterm><primary>heap profile</primary></indexterm>
548 <Para>Produce a detailed <Emphasis>heap profile</Emphasis>
549 of the heap occupied by live closures. The profile is
550 written to the file <Filename><program>.hp</Filename>
551 from which a PostScript graph can be produced using
552 <command>hp2ps</command> (see <XRef
553 LinkEnd="hp2ps">).</Para>
555 <Para>The heap space profile may be broken down by different
561 <term><Option>-hC</Option>:</Term>
563 <Para>cost centre which produced the closure (the
569 <term><Option>-hM</Option>:</Term>
571 <Para>cost centre module which produced the
577 <term><Option>-hD</Option>:</Term>
579 <Para>closure description—a string describing
585 <term><Option>-hY</Option>:</Term>
587 <Para>closure type—a string describing the
588 closure's type.</Para>
597 <term><Option>-h<filtering-options></Option>:</Term>
598 <indexterm><primary><option>-h<filtering-options>
599 </option></primary></indexterm>
600 <indexterm><primary>heap profile filtering options</primary></indexterm>
602 <Para>It's often useful to select just some subset of the
603 heap when profiling. To do this, the following filters are
604 available. You may use multiple filters, in which case a
605 closure has to satisfy all filters to appear in the final
606 profile. Filtering criterion are independent of what it is
607 you ask to see. So, for example, you can specify a profile
608 by closure description (<Literal>-hD</literal>) but ask to
609 filter closures by producer module (<Literal>-hm{...}</literal>).
612 <Para>Available filters are:</para>
617 <term><Option>-hc{cc1, cc2 .. ccN}</Option>:</Term>
619 <Para>Restrict to one of the specified cost centers.
620 Since GHC deals in cost center stacks, the specified
621 cost centers pertain to the top stack element. For
622 example, <Literal>-hc{Wurble,Burble}</literal> selects
623 all cost center stacks whose top element is
624 <Literal>Wurble</literal> or
625 <Literal>Burble</literal>.
631 <term><Option>-hm{module1, module2 .. moduleN}</Option>:</Term>
633 <Para>Restrict to closures produced by functions in
634 one of the specified modules.
640 <term><Option>-hd{descr1, descr2 .. descrN}</Option>:</Term>
642 <Para>Restrict to closures whose description-string is
643 one of the specified descriptions. Description
644 strings are pretty arcane. An easy way to find
645 plausible strings to specify is to first do a
646 <Literal>-hD</literal> profile and then inspect the
647 description-strings which appear in the resulting profile.
653 <term><Option>-hy{type1, type2 .. typeN}</Option>:</Term>
655 <Para>Restrict to closures having one of the specified
666 <term><option>-hx</option>:</term>
667 <indexterm><primary><option>-hx</option></primary></indexterm>
669 <para>The <option>-hx</option> option generates heap
670 profiling information in the XML format understood by our
671 new profiling tool (NOTE: heap profiling with the new tool
672 is not yet working! Use <command>hp2ps</command>-style heap
673 profiling for the time being).</para>
682 <title><command>hp2ps</command>--heap profile to PostScript</title>
684 <indexterm><primary><command>hp2ps</command></primary></indexterm>
685 <indexterm><primary>heap profiles</primary></indexterm>
686 <indexterm><primary>postscript, from heap profiles</primary></indexterm>
687 <indexterm><primary><option>-h<break-down></option></primary></indexterm>
692 hp2ps [flags] [<file>[.hp]]
696 <command>hp2ps</command><indexterm><primary>hp2ps
697 program</primary></indexterm> converts a heap profile as produced
698 by the <Option>-h<break-down></Option> runtime option into a
699 PostScript graph of the heap profile. By convention, the file to
700 be processed by <command>hp2ps</command> has a
701 <filename>.hp</filename> extension. The PostScript output is
702 written to <filename><file>@.ps</filename>. If
703 <filename><file></filename> is omitted entirely, then the
704 program behaves as a filter.</para>
706 <para><command>hp2ps</command> is distributed in
707 <filename>ghc/utils/hp2ps</filename> in a GHC source
708 distribution. It was originally developed by Dave Wakeling as part
709 of the HBC/LML heap profiler.</para>
711 <para>The flags are:</para>
716 <term><Option>-d</Option></Term>
718 <para>In order to make graphs more readable,
719 <command>hp2ps</command> sorts the shaded bands for each
720 identifier. The default sort ordering is for the bands with
721 the largest area to be stacked on top of the smaller ones.
722 The <Option>-d</Option> option causes rougher bands (those
723 representing series of values with the largest standard
724 deviations) to be stacked on top of smoother ones.</para>
729 <term><Option>-b</Option></Term>
731 <para>Normally, <command>hp2ps</command> puts the title of
732 the graph in a small box at the top of the page. However, if
733 the JOB string is too long to fit in a small box (more than
734 35 characters), then <command>hp2ps</command> will choose to
735 use a big box instead. The <Option>-b</Option> option
736 forces <command>hp2ps</command> to use a big box.</para>
741 <term><Option>-e<float>[in|mm|pt]</Option></Term>
743 <para>Generate encapsulated PostScript suitable for
744 inclusion in LaTeX documents. Usually, the PostScript graph
745 is drawn in landscape mode in an area 9 inches wide by 6
746 inches high, and <command>hp2ps</command> arranges for this
747 area to be approximately centred on a sheet of a4 paper.
748 This format is convenient of studying the graph in detail,
749 but it is unsuitable for inclusion in LaTeX documents. The
750 <Option>-e</Option> option causes the graph to be drawn in
751 portrait mode, with float specifying the width in inches,
752 millimetres or points (the default). The resulting
753 PostScript file conforms to the Encapsulated PostScript
754 (EPS) convention, and it can be included in a LaTeX document
755 using Rokicki's dvi-to-PostScript converter
756 <command>dvips</command>.</para>
761 <term><Option>-g</Option></Term>
763 <para>Create output suitable for the <command>gs</command>
764 PostScript previewer (or similar). In this case the graph is
765 printed in portrait mode without scaling. The output is
766 unsuitable for a laser printer.</para>
771 <term><Option>-l</Option></Term>
773 <para>Normally a profile is limited to 20 bands with
774 additional identifiers being grouped into an
775 <literal>OTHER</literal> band. The <Option>-l</Option> flag
776 removes this 20 band and limit, producing as many bands as
777 necessary. No key is produced as it won't fit!. It is useful
778 for creation time profiles with many bands.</para>
783 <term><Option>-m<int></Option></Term>
785 <para>Normally a profile is limited to 20 bands with
786 additional identifiers being grouped into an
787 <literal>OTHER</literal> band. The <Option>-m</Option> flag
788 specifies an alternative band limit (the maximum is
791 <para><Option>-m0</Option> requests the band limit to be
792 removed. As many bands as necessary are produced. However no
793 key is produced as it won't fit! It is useful for displaying
794 creation time profiles with many bands.</para>
799 <term><Option>-p</Option></Term>
801 <para>Use previous parameters. By default, the PostScript
802 graph is automatically scaled both horizontally and
803 vertically so that it fills the page. However, when
804 preparing a series of graphs for use in a presentation, it
805 is often useful to draw a new graph using the same scale,
806 shading and ordering as a previous one. The
807 <Option>-p</Option> flag causes the graph to be drawn using
808 the parameters determined by a previous run of
809 <command>hp2ps</command> on <filename>file</filename>. These
810 are extracted from <filename>file@.aux</filename>.</para>
815 <term><Option>-s</Option></Term>
817 <para>Use a small box for the title.</para>
822 <term><Option>-t<float></Option></Term>
824 <para>Normally trace elements which sum to a total of less
825 than 1% of the profile are removed from the
826 profile. The <option>-t</option> option allows this
827 percentage to be modified (maximum 5%).</para>
829 <para><Option>-t0</Option> requests no trace elements to be
830 removed from the profile, ensuring that all the data will be
836 <term><Option>-c</Option></Term>
838 <para>Generate colour output.</para>
843 <term><Option>-y</Option></Term>
845 <para>Ignore marks.</para>
850 <term><Option>-?</Option></Term>
852 <para>Print out usage information.</para>
858 <sect1 id="ticky-ticky">
859 <title>Using “ticky-ticky” profiling (for implementors)</Title>
860 <indexterm><primary>ticky-ticky profiling</primary></indexterm>
862 <para>(ToDo: document properly.)</para>
864 <para>It is possible to compile Glasgow Haskell programs so that
865 they will count lots and lots of interesting things, e.g., number
866 of updates, number of data constructors entered, etc., etc. We
867 call this “ticky-ticky”
868 profiling,<indexterm><primary>ticky-ticky
869 profiling</primary></indexterm> <indexterm><primary>profiling,
870 ticky-ticky</primary></indexterm> because that's the sound a Sun4
871 makes when it is running up all those counters
872 (<Emphasis>slowly</Emphasis>).</para>
874 <para>Ticky-ticky profiling is mainly intended for implementors;
875 it is quite separate from the main “cost-centre”
876 profiling system, intended for all users everywhere.</para>
878 <para>To be able to use ticky-ticky profiling, you will need to
879 have built appropriate libraries and things when you made the
880 system. See “Customising what libraries to build,” in
881 the installation guide.</para>
883 <para>To get your compiled program to spit out the ticky-ticky
884 numbers, use a <Option>-r</Option> RTS
885 option<indexterm><primary>-r RTS option</primary></indexterm>.
886 See <XRef LinkEnd="runtime-control">.</para>
888 <para>Compiling your program with the <Option>-ticky</Option>
889 switch yields an executable that performs these counts. Here is a
890 sample ticky-ticky statistics file, generated by the invocation
891 <command>foo +RTS -rfoo.ticky</command>.</para>
897 ALLOCATIONS: 3964631 (11330900 words total: 3999476 admin, 6098829 goods, 1232595 slop)
898 total words: 2 3 4 5 6+
899 69647 ( 1.8%) function values 50.0 50.0 0.0 0.0 0.0
900 2382937 ( 60.1%) thunks 0.0 83.9 16.1 0.0 0.0
901 1477218 ( 37.3%) data values 66.8 33.2 0.0 0.0 0.0
903 2 ( 0.0%) black holes 0.0 100.0 0.0 0.0 0.0
904 0 ( 0.0%) prim things
905 34825 ( 0.9%) partial applications 0.0 0.0 0.0 100.0 0.0
906 2 ( 0.0%) thread state objects 0.0 0.0 0.0 0.0 100.0
908 Total storage-manager allocations: 3647137 (11882004 words)
909 [551104 words lost to speculative heap-checks]
913 ENTERS: 9400092 of which 2005772 (21.3%) direct to the entry code
914 [the rest indirected via Node's info ptr]
915 1860318 ( 19.8%) thunks
916 3733184 ( 39.7%) data values
917 3149544 ( 33.5%) function values
918 [of which 1999880 (63.5%) bypassed arg-satisfaction chk]
919 348140 ( 3.7%) partial applications
920 308906 ( 3.3%) normal indirections
921 0 ( 0.0%) permanent indirections
924 2137257 ( 36.4%) from entering a new constructor
925 [the rest from entering an existing constructor]
926 2349219 ( 40.0%) vectored [the rest unvectored]
928 RET_NEW: 2137257: 32.5% 46.2% 21.3% 0.0% 0.0% 0.0% 0.0% 0.0% 0.0%
929 RET_OLD: 3733184: 2.8% 67.9% 29.3% 0.0% 0.0% 0.0% 0.0% 0.0% 0.0%
930 RET_UNBOXED_TUP: 2: 0.0% 0.0%100.0% 0.0% 0.0% 0.0% 0.0% 0.0% 0.0%
932 RET_VEC_RETURN : 2349219: 0.0% 0.0%100.0% 0.0% 0.0% 0.0% 0.0% 0.0% 0.0%
934 UPDATE FRAMES: 2241725 (0 omitted from thunks)
938 0 ( 0.0%) data values
939 34827 ( 1.6%) partial applications
940 [2 in place, 34825 allocated new space]
941 2206898 ( 98.4%) updates to existing heap objects (46 by squeezing)
942 UPD_CON_IN_NEW: 0: 0 0 0 0 0 0 0 0 0
943 UPD_PAP_IN_NEW: 34825: 0 0 0 34825 0 0 0 0 0
945 NEW GEN UPDATES: 2274700 ( 99.9%)
947 OLD GEN UPDATES: 1852 ( 0.1%)
949 Total bytes copied during GC: 190096
951 **************************************************
952 3647137 ALLOC_HEAP_ctr
953 11882004 ALLOC_HEAP_tot
958 34831 ALLOC_FUN_hst_0
959 34816 ALLOC_FUN_hst_1
963 2382937 ALLOC_UP_THK_ctr
966 0 E!NT_PERM_IND_ctr requires +RTS -Z
967 [... lots more info omitted ...]
968 0 GC_SEL_ABANDONED_ctr
971 0 GC_FAILED_PROMOTION_ctr
972 47524 GC_WORDS_COPIED_ctr
975 <para>The formatting of the information above the row of asterisks
976 is subject to change, but hopefully provides a useful
977 human-readable summary. Below the asterisks <Emphasis>all
978 counters</Emphasis> maintained by the ticky-ticky system are
979 dumped, in a format intended to be machine-readable: zero or more
980 spaces, an integer, a space, the counter name, and a newline.</para>
982 <para>In fact, not <Emphasis>all</Emphasis> counters are
983 necessarily dumped; compile- or run-time flags can render certain
984 counters invalid. In this case, either the counter will simply
985 not appear, or it will appear with a modified counter name,
986 possibly along with an explanation for the omission (notice
987 <literal>ENT_PERM_IND_ctr</literal> appears
988 with an inserted <literal>!</literal> above). Software analysing
989 this output should always check that it has the counters it
990 expects. Also, beware: some of the counters can have
991 <Emphasis>large</Emphasis> values!</para>
998 ;;; Local Variables: ***
1000 ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***