Improve documentation of -ticky a little
[ghc.git] / docs / users_guide / runtime_control.xml
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <sect1 id="runtime-control">
3 <title>Running a compiled program</title>
4
5 <indexterm><primary>runtime control of Haskell programs</primary></indexterm>
6 <indexterm><primary>running, compiled program</primary></indexterm>
7 <indexterm><primary>RTS options</primary></indexterm>
8
9 <para>To make an executable program, the GHC system compiles your
10 code and then links it with a non-trivial runtime system (RTS),
11 which handles storage management, thread scheduling, profiling, and
12 so on.</para>
13
14 <para>
15 The RTS has a lot of options to control its behaviour. For
16 example, you can change the context-switch interval, the default
17 size of the heap, and enable heap profiling. These options can be
18 passed to the runtime system in a variety of different ways; the
19 next section (<xref linkend="setting-rts-options" />) describes
20 the various methods, and the following sections describe the RTS
21 options themselves.
22 </para>
23
24 <sect2 id="setting-rts-options">
25 <title>Setting RTS options</title>
26 <indexterm><primary>RTS options, setting</primary></indexterm>
27
28 <para>
29 There are four ways to set RTS options:
30
31 <itemizedlist>
32 <listitem>
33 <para>
34 on the command line between <literal>+RTS ... -RTS</literal>, when running the program
35 (<xref linkend="rts-opts-cmdline" />)
36 </para>
37 </listitem>
38 <listitem>
39 <para>at compile-time, using <option>--with-rtsopts</option>
40 (<xref linkend="rts-opts-compile-time" />)
41 </para>
42 </listitem>
43 <listitem>
44 <para>with the environment variable <envar>GHCRTS</envar>
45 (<xref linkend="rts-options-environment" />)
46 </para>
47 </listitem>
48 <listitem>
49 <para>by overriding &ldquo;hooks&rdquo; in the runtime system
50 (<xref linkend="rts-hooks" />)
51 </para>
52 </listitem>
53 </itemizedlist>
54 </para>
55
56 <sect3 id="rts-opts-cmdline">
57 <title>Setting RTS options on the command line</title>
58
59 <para>
60 If you set the <literal>-rtsopts</literal> flag appropriately
61 when linking (see <xref linkend="options-linker" />), you can
62 give RTS options on the command line when running your
63 program.
64 </para>
65
66 <para>
67 When your Haskell program starts up, the RTS extracts
68 command-line arguments bracketed between
69 <option>+RTS</option><indexterm><primary><option>+RTS</option></primary></indexterm>
70 and
71 <option>-RTS</option><indexterm><primary><option>-RTS</option></primary></indexterm>
72 as its own. For example:
73 </para>
74
75 <screen>
76 $ ghc prog.hs -rtsopts
77 [1 of 1] Compiling Main ( prog.hs, prog.o )
78 Linking prog ...
79 $ ./prog -f +RTS -H32m -S -RTS -h foo bar
80 </screen>
81
82 <para>
83 The RTS will
84 snaffle <option>-H32m</option> <option>-S</option> for itself,
85 and the remaining arguments <literal>-f -h foo bar</literal>
86 will be available to your program if/when it calls
87 <function>System.Environment.getArgs</function>.
88 </para>
89
90 <para>
91 No <option>-RTS</option> option is required if the
92 runtime-system options extend to the end of the command line, as in
93 this example:
94 </para>
95
96 <screen>
97 % hls -ltr /usr/etc +RTS -A5m
98 </screen>
99
100 <para>
101 If you absolutely positively want all the rest of the options
102 in a command line to go to the program (and not the RTS), use a
103 <option>--RTS</option><indexterm><primary><option>--RTS</option></primary></indexterm>.
104 </para>
105
106 <para>
107 As always, for RTS options that take
108 <replaceable>size</replaceable>s: If the last character of
109 <replaceable>size</replaceable> is a K or k, multiply by 1000; if an
110 M or m, by 1,000,000; if a G or G, by 1,000,000,000. (And any
111 wraparound in the counters is <emphasis>your</emphasis>
112 fault!)
113 </para>
114
115 <para>
116 Giving a <literal>+RTS -?</literal>
117 <indexterm><primary><option>-?</option></primary><secondary>RTS option</secondary></indexterm> option
118 will print out the RTS options actually available in your program
119 (which vary, depending on how you compiled).</para>
120
121 <para>
122 NOTE: since GHC is itself compiled by GHC, you can change RTS
123 options in the compiler using the normal
124 <literal>+RTS ... -RTS</literal>
125 combination. eg. to set the maximum heap
126 size for a compilation to 128M, you would add
127 <literal>+RTS -M128m -RTS</literal>
128 to the command line.
129 </para>
130 </sect3>
131
132 <sect3 id="rts-opts-compile-time">
133 <title>Setting RTS options at compile time</title>
134
135 <para>
136 GHC lets you change the default RTS options for a program at
137 compile time, using the <literal>-with-rtsopts</literal>
138 flag (<xref linkend="options-linker" />). A common use for this is
139 to give your program a default heap and/or stack size that is
140 greater than the default. For example, to set <literal>-H128m
141 -K64m</literal>, link
142 with <literal>-with-rtsopts="-H128m -K64m"</literal>.
143 </para>
144 </sect3>
145
146 <sect3 id="rts-options-environment">
147 <title>Setting RTS options with the <envar>GHCRTS</envar>
148 environment variable</title>
149
150 <indexterm><primary>RTS options</primary><secondary>from the environment</secondary></indexterm>
151 <indexterm><primary>environment variable</primary><secondary>for
152 setting RTS options</secondary></indexterm>
153
154 <para>
155 If the <literal>-rtsopts</literal> flag is set to
156 something other than <literal>none</literal> when linking,
157 RTS options are also taken from the environment variable
158 <envar>GHCRTS</envar><indexterm><primary><envar>GHCRTS</envar></primary>
159 </indexterm>. For example, to set the maximum heap size
160 to 2G for all GHC-compiled programs (using an
161 <literal>sh</literal>-like shell):
162 </para>
163
164 <screen>
165 GHCRTS='-M2G'
166 export GHCRTS
167 </screen>
168
169 <para>
170 RTS options taken from the <envar>GHCRTS</envar> environment
171 variable can be overridden by options given on the command
172 line.
173 </para>
174
175 <para>
176 Tip: setting something like <literal>GHCRTS=-M2G</literal>
177 in your environment is a handy way to avoid Haskell programs
178 growing beyond the real memory in your machine, which is
179 easy to do by accident and can cause the machine to slow to
180 a crawl until the OS decides to kill the process (and you
181 hope it kills the right one).
182 </para>
183 </sect3>
184
185 <sect3 id="rts-hooks">
186 <title>&ldquo;Hooks&rdquo; to change RTS behaviour</title>
187
188 <indexterm><primary>hooks</primary><secondary>RTS</secondary></indexterm>
189 <indexterm><primary>RTS hooks</primary></indexterm>
190 <indexterm><primary>RTS behaviour, changing</primary></indexterm>
191
192 <para>GHC lets you exercise rudimentary control over certain RTS
193 settings for any given program, by compiling in a
194 &ldquo;hook&rdquo; that is called by the run-time system. The RTS
195 contains stub definitions for these hooks, but by writing your
196 own version and linking it on the GHC command line, you can
197 override the defaults.</para>
198
199 <para>Owing to the vagaries of DLL linking, these hooks don't work
200 under Windows when the program is built dynamically.</para>
201
202 <para>You can change the messages printed when the runtime
203 system &ldquo;blows up,&rdquo; e.g., on stack overflow. The hooks
204 for these are as follows:</para>
205
206 <variablelist>
207
208 <varlistentry>
209 <term>
210 <function>void OutOfHeapHook (unsigned long, unsigned long)</function>
211 <indexterm><primary><function>OutOfHeapHook</function></primary></indexterm>
212 </term>
213 <listitem>
214 <para>The heap-overflow message.</para>
215 </listitem>
216 </varlistentry>
217
218 <varlistentry>
219 <term>
220 <function>void StackOverflowHook (long int)</function>
221 <indexterm><primary><function>StackOverflowHook</function></primary></indexterm>
222 </term>
223 <listitem>
224 <para>The stack-overflow message.</para>
225 </listitem>
226 </varlistentry>
227
228 <varlistentry>
229 <term>
230 <function>void MallocFailHook (long int)</function>
231 <indexterm><primary><function>MallocFailHook</function></primary></indexterm>
232 </term>
233 <listitem>
234 <para>The message printed if <function>malloc</function>
235 fails.</para>
236 </listitem>
237 </varlistentry>
238 </variablelist>
239 </sect3>
240
241 </sect2>
242
243 <sect2 id="rts-options-misc">
244 <title>Miscellaneous RTS options</title>
245
246 <variablelist>
247 <varlistentry>
248 <term><option>-V<replaceable>secs</replaceable></option>
249 <indexterm><primary><option>-V</option></primary><secondary>RTS
250 option</secondary></indexterm></term>
251 <listitem>
252 <para>Sets the interval that the RTS clock ticks at. The
253 runtime uses a single timer signal to count ticks; this timer
254 signal is used to control the context switch timer (<xref
255 linkend="using-concurrent" />) and the heap profiling
256 timer <xref linkend="rts-options-heap-prof" />. Also, the
257 time profiler uses the RTS timer signal directly to record
258 time profiling samples.</para>
259
260 <para>Normally, setting the <option>-V</option> option
261 directly is not necessary: the resolution of the RTS timer is
262 adjusted automatically if a short interval is requested with
263 the <option>-C</option> or <option>-i</option> options.
264 However, setting <option>-V</option> is required in order to
265 increase the resolution of the time profiler.</para>
266
267 <para>Using a value of zero disables the RTS clock
268 completely, and has the effect of disabling timers that
269 depend on it: the context switch timer and the heap profiling
270 timer. Context switches will still happen, but
271 deterministically and at a rate much faster than normal.
272 Disabling the interval timer is useful for debugging, because
273 it eliminates a source of non-determinism at runtime.</para>
274 </listitem>
275 </varlistentry>
276
277 <varlistentry>
278 <term><option>--install-signal-handlers=<replaceable>yes|no</replaceable></option>
279 <indexterm><primary><option>--install-signal-handlers</option></primary><secondary>RTS
280 option</secondary></indexterm></term>
281 <listitem>
282 <para>If yes (the default), the RTS installs signal handlers to catch
283 things like ctrl-C. This option is primarily useful for when
284 you are using the Haskell code as a DLL, and want to set your
285 own signal handlers.</para>
286
287 <para>Note that even
288 with <option>--install-signal-handlers=no</option>, the RTS
289 interval timer signal is still enabled. The timer signal
290 is either SIGVTALRM or SIGALRM, depending on the RTS
291 configuration and OS capabilities. To disable the timer
292 signal, use the <literal>-V0</literal> RTS option (see
293 above).
294 </para>
295 </listitem>
296 </varlistentry>
297
298 <varlistentry>
299 <term><option>-xm<replaceable>address</replaceable></option>
300 <indexterm><primary><option>-xm</option></primary><secondary>RTS
301 option</secondary></indexterm></term>
302 <listitem>
303 <para>
304 WARNING: this option is for working around memory
305 allocation problems only. Do not use unless GHCi fails
306 with a message like &ldquo;<literal>failed to mmap() memory below 2Gb</literal>&rdquo;. If you need to use this option to get GHCi working
307 on your machine, please file a bug.
308 </para>
309
310 <para>
311 On 64-bit machines, the RTS needs to allocate memory in the
312 low 2Gb of the address space. Support for this across
313 different operating systems is patchy, and sometimes fails.
314 This option is there to give the RTS a hint about where it
315 should be able to allocate memory in the low 2Gb of the
316 address space. For example, <literal>+RTS -xm20000000
317 -RTS</literal> would hint that the RTS should allocate
318 starting at the 0.5Gb mark. The default is to use the OS's
319 built-in support for allocating memory in the low 2Gb if
320 available (e.g. <literal>mmap</literal>
321 with <literal>MAP_32BIT</literal> on Linux), or
322 otherwise <literal>-xm40000000</literal>.
323 </para>
324 </listitem>
325 </varlistentry>
326 </variablelist>
327 </sect2>
328
329 <sect2 id="rts-options-gc">
330 <title>RTS options to control the garbage collector</title>
331
332 <indexterm><primary>garbage collector</primary><secondary>options</secondary></indexterm>
333 <indexterm><primary>RTS options</primary><secondary>garbage collection</secondary></indexterm>
334
335 <para>There are several options to give you precise control over
336 garbage collection. Hopefully, you won't need any of these in
337 normal operation, but there are several things that can be tweaked
338 for maximum performance.</para>
339
340 <variablelist>
341
342 <varlistentry>
343 <term>
344 <option>-A</option><replaceable>size</replaceable>
345 <indexterm><primary><option>-A</option></primary><secondary>RTS option</secondary></indexterm>
346 <indexterm><primary>allocation area, size</primary></indexterm>
347 </term>
348 <listitem>
349 <para>&lsqb;Default: 512k&rsqb; Set the allocation area size
350 used by the garbage collector. The allocation area
351 (actually generation 0 step 0) is fixed and is never resized
352 (unless you use <option>-H</option>, below).</para>
353
354 <para>Increasing the allocation area size may or may not
355 give better performance (a bigger allocation area means
356 worse cache behaviour but fewer garbage collections and less
357 promotion).</para>
358
359 <para>With only 1 generation (<option>-G1</option>) the
360 <option>-A</option> option specifies the minimum allocation
361 area, since the actual size of the allocation area will be
362 resized according to the amount of data in the heap (see
363 <option>-F</option>, below).</para>
364 </listitem>
365 </varlistentry>
366
367 <varlistentry>
368 <term>
369 <option>-c</option>
370 <indexterm><primary><option>-c</option></primary><secondary>RTS option</secondary></indexterm>
371 <indexterm><primary>garbage collection</primary><secondary>compacting</secondary></indexterm>
372 <indexterm><primary>compacting garbage collection</primary></indexterm>
373 </term>
374 <listitem>
375 <para>Use a compacting algorithm for collecting the oldest
376 generation. By default, the oldest generation is collected
377 using a copying algorithm; this option causes it to be
378 compacted in-place instead. The compaction algorithm is
379 slower than the copying algorithm, but the savings in memory
380 use can be considerable.</para>
381
382 <para>For a given heap size (using the <option>-H</option>
383 option), compaction can in fact reduce the GC cost by
384 allowing fewer GCs to be performed. This is more likely
385 when the ratio of live data to heap size is high, say
386 &gt;30&percnt;.</para>
387
388 <para>NOTE: compaction doesn't currently work when a single
389 generation is requested using the <option>-G1</option>
390 option.</para>
391 </listitem>
392 </varlistentry>
393
394 <varlistentry>
395 <term><option>-c</option><replaceable>n</replaceable></term>
396
397 <listitem>
398 <para>&lsqb;Default: 30&rsqb; Automatically enable
399 compacting collection when the live data exceeds
400 <replaceable>n</replaceable>&percnt; of the maximum heap size
401 (see the <option>-M</option> option). Note that the maximum
402 heap size is unlimited by default, so this option has no
403 effect unless the maximum heap size is set with
404 <option>-M</option><replaceable>size</replaceable>. </para>
405 </listitem>
406 </varlistentry>
407
408 <varlistentry>
409 <term>
410 <option>-F</option><replaceable>factor</replaceable>
411 <indexterm><primary><option>-F</option></primary><secondary>RTS option</secondary></indexterm>
412 <indexterm><primary>heap size, factor</primary></indexterm>
413 </term>
414 <listitem>
415
416 <para>&lsqb;Default: 2&rsqb; This option controls the amount
417 of memory reserved for the older generations (and in the
418 case of a two space collector the size of the allocation
419 area) as a factor of the amount of live data. For example,
420 if there was 2M of live data in the oldest generation when
421 we last collected it, then by default we'll wait until it
422 grows to 4M before collecting it again.</para>
423
424 <para>The default seems to work well here. If you have
425 plenty of memory, it is usually better to use
426 <option>-H</option><replaceable>size</replaceable> than to
427 increase
428 <option>-F</option><replaceable>factor</replaceable>.</para>
429
430 <para>The <option>-F</option> setting will be automatically
431 reduced by the garbage collector when the maximum heap size
432 (the <option>-M</option><replaceable>size</replaceable>
433 setting) is approaching.</para>
434 </listitem>
435 </varlistentry>
436
437 <varlistentry>
438 <term>
439 <option>-G</option><replaceable>generations</replaceable>
440 <indexterm><primary><option>-G</option></primary><secondary>RTS option</secondary></indexterm>
441 <indexterm><primary>generations, number of</primary></indexterm>
442 </term>
443 <listitem>
444 <para>&lsqb;Default: 2&rsqb; Set the number of generations
445 used by the garbage collector. The default of 2 seems to be
446 good, but the garbage collector can support any number of
447 generations. Anything larger than about 4 is probably not a
448 good idea unless your program runs for a
449 <emphasis>long</emphasis> time, because the oldest
450 generation will hardly ever get collected.</para>
451
452 <para>Specifying 1 generation with <option>+RTS -G1</option>
453 gives you a simple 2-space collector, as you would expect.
454 In a 2-space collector, the <option>-A</option> option (see
455 above) specifies the <emphasis>minimum</emphasis> allocation
456 area size, since the allocation area will grow with the
457 amount of live data in the heap. In a multi-generational
458 collector the allocation area is a fixed size (unless you
459 use the <option>-H</option> option, see below).</para>
460 </listitem>
461 </varlistentry>
462
463 <varlistentry>
464 <term>
465 <option>-qg<optional><replaceable>gen</replaceable></optional></option>
466 <indexterm><primary><option>-qg</option><secondary>RTS
467 option</secondary></primary></indexterm>
468 </term>
469 <listitem>
470 <para>&lsqb;New in GHC 6.12.1&rsqb; &lsqb;Default: 0&rsqb;
471 Use parallel GC in
472 generation <replaceable>gen</replaceable> and higher.
473 Omitting <replaceable>gen</replaceable> turns off the
474 parallel GC completely, reverting to sequential GC.</para>
475
476 <para>The default parallel GC settings are usually suitable
477 for parallel programs (i.e. those
478 using <literal>par</literal>, Strategies, or with multiple
479 threads). However, it is sometimes beneficial to enable
480 the parallel GC for a single-threaded sequential program
481 too, especially if the program has a large amount of heap
482 data and GC is a significant fraction of runtime. To use
483 the parallel GC in a sequential program, enable the
484 parallel runtime with a suitable <literal>-N</literal>
485 option, and additionally it might be beneficial to
486 restrict parallel GC to the old generation
487 with <literal>-qg1</literal>.</para>
488 </listitem>
489 </varlistentry>
490
491 <varlistentry>
492 <term>
493 <option>-qb<optional><replaceable>gen</replaceable></optional></option>
494 <indexterm><primary><option>-qb</option><secondary>RTS
495 option</secondary></primary></indexterm>
496 </term>
497 <listitem>
498 <para>
499 &lsqb;New in GHC 6.12.1&rsqb; &lsqb;Default: 1&rsqb; Use
500 load-balancing in the parallel GC in
501 generation <replaceable>gen</replaceable> and higher.
502 Omitting <replaceable>gen</replaceable> disables
503 load-balancing entirely.</para>
504
505 <para>
506 Load-balancing shares out the work of GC between the
507 available cores. This is a good idea when the heap is
508 large and we need to parallelise the GC work, however it
509 is also pessimal for the short young-generation
510 collections in a parallel program, because it can harm
511 locality by moving data from the cache of the CPU where is
512 it being used to the cache of another CPU. Hence the
513 default is to do load-balancing only in the
514 old-generation. In fact, for a parallel program it is
515 sometimes beneficial to disable load-balancing entirely
516 with <literal>-qb</literal>.
517 </para>
518 </listitem>
519 </varlistentry>
520
521 <varlistentry>
522 <term>
523 <option>-H</option><optional><replaceable>size</replaceable></optional>
524 <indexterm><primary><option>-H</option></primary><secondary>RTS option</secondary></indexterm>
525 <indexterm><primary>heap size, suggested</primary></indexterm>
526 </term>
527 <listitem>
528 <para>&lsqb;Default: 0&rsqb; This option provides a
529 &ldquo;suggested heap size&rdquo; for the garbage
530 collector. Think
531 of <option>-H<replaceable>size</replaceable></option> as a
532 variable <option>-A</option> option. It says: I want to
533 use at least <replaceable>size</replaceable> bytes, so use
534 whatever is left over to increase the <option>-A</option>
535 value.</para>
536
537 <para>This option does not put
538 a <emphasis>limit</emphasis> on the heap size: the heap
539 may grow beyond the given size as usual.</para>
540
541 <para>If <replaceable>size</replaceable> is omitted, then
542 the garbage collector will take the size of the heap at
543 the previous GC as the <replaceable>size</replaceable>.
544 This has the effect of allowing for a
545 larger <option>-A</option> value but without increasing
546 the overall memory requirements of the program. It can be
547 useful when the default small <option>-A</option> value is
548 suboptimal, as it can be in programs that create large
549 amounts of long-lived data.</para>
550 </listitem>
551 </varlistentry>
552
553 <varlistentry>
554 <term>
555 <option>-I</option><replaceable>seconds</replaceable>
556 <indexterm><primary><option>-I</option></primary>
557 <secondary>RTS option</secondary>
558 </indexterm>
559 <indexterm><primary>idle GC</primary>
560 </indexterm>
561 </term>
562 <listitem>
563 <para>(default: 0.3) In the threaded and SMP versions of the RTS (see
564 <option>-threaded</option>, <xref linkend="options-linker" />), a
565 major GC is automatically performed if the runtime has been idle
566 (no Haskell computation has been running) for a period of time.
567 The amount of idle time which must pass before a GC is performed is
568 set by the <option>-I</option><replaceable>seconds</replaceable>
569 option. Specifying <option>-I0</option> disables the idle GC.</para>
570
571 <para>For an interactive application, it is probably a good idea to
572 use the idle GC, because this will allow finalizers to run and
573 deadlocked threads to be detected in the idle time when no Haskell
574 computation is happening. Also, it will mean that a GC is less
575 likely to happen when the application is busy, and so
576 responsiveness may be improved. However, if the amount of live data in
577 the heap is particularly large, then the idle GC can cause a
578 significant delay, and too small an interval could adversely affect
579 interactive responsiveness.</para>
580
581 <para>This is an experimental feature, please let us know if it
582 causes problems and/or could benefit from further tuning.</para>
583 </listitem>
584 </varlistentry>
585
586 <varlistentry>
587 <term>
588 <option>-ki</option><replaceable>size</replaceable>
589 <indexterm><primary><option>-k</option></primary><secondary>RTS option</secondary></indexterm>
590 <indexterm><primary>stack, initial size</primary></indexterm>
591 </term>
592 <listitem>
593 <para>
594 &lsqb;Default: 1k&rsqb; Set the initial stack size for new
595 threads. (Note: this flag used to be
596 simply <option>-k</option>, but was renamed
597 to <option>-ki</option> in GHC 7.2.1. The old name is
598 still accepted for backwards compatibility, but that may
599 be removed in a future version).
600 </para>
601
602 <para>
603 Thread stacks (including the main thread's stack) live on
604 the heap. As the stack grows, new stack chunks are added
605 as required; if the stack shrinks again, these extra stack
606 chunks are reclaimed by the garbage collector. The
607 default initial stack size is deliberately small, in order
608 to keep the time and space overhead for thread creation to
609 a minimum, and to make it practical to spawn threads for
610 even tiny pieces of work.
611 </para>
612 </listitem>
613 </varlistentry>
614
615 <varlistentry>
616 <term>
617 <option>-kc</option><replaceable>size</replaceable>
618 <indexterm><primary><option>-kc</option></primary><secondary>RTS
619 option</secondary></indexterm>
620 <indexterm><primary>stack</primary><secondary>chunk size</secondary></indexterm>
621 </term>
622 <listitem>
623 <para>
624 &lsqb;Default: 32k&rsqb; Set the size of &ldquo;stack
625 chunks&rdquo;. When a thread's current stack overflows, a
626 new stack chunk is created and added to the thread's
627 stack, until the limit set by <option>-K</option> is
628 reached.
629 </para>
630
631 <para>
632 The advantage of smaller stack chunks is that the garbage
633 collector can avoid traversing stack chunks if they are
634 known to be unmodified since the last collection, so
635 reducing the chunk size means that the garbage collector
636 can identify more stack as unmodified, and the GC overhead
637 might be reduced. On the other hand, making stack chunks
638 too small adds some overhead as there will be more
639 overflow/underflow between chunks. The default setting of
640 32k appears to be a reasonable compromise in most cases.
641 </para>
642 </listitem>
643 </varlistentry>
644
645 <varlistentry>
646 <term>
647 <option>-kb</option><replaceable>size</replaceable>
648 <indexterm><primary><option>-kc</option></primary><secondary>RTS
649 option</secondary></indexterm>
650 <indexterm><primary>stack</primary><secondary>chunk buffer size</secondary></indexterm>
651 </term>
652 <listitem>
653 <para>
654 &lsqb;Default: 1k&rsqb; Sets the stack chunk buffer size.
655 When a stack chunk overflows and a new stack chunk is
656 created, some of the data from the previous stack chunk is
657 moved into the new chunk, to avoid an immediate underflow
658 and repeated overflow/underflow at the boundary. The
659 amount of stack moved is set by the <option>-kb</option>
660 option.
661 </para>
662 <para>
663 Note that to avoid wasting space, this value should
664 typically be less than 10&percnt; of the size of a stack
665 chunk (<option>-kc</option>), because in a chain of stack
666 chunks, each chunk will have a gap of unused space of this
667 size.
668 </para>
669 </listitem>
670 </varlistentry>
671
672 <varlistentry>
673 <term>
674 <option>-K</option><replaceable>size</replaceable>
675 <indexterm><primary><option>-K</option></primary><secondary>RTS option</secondary></indexterm>
676 <indexterm><primary>stack, maximum size</primary></indexterm>
677 </term>
678 <listitem>
679 <para>&lsqb;Default: 80% physical memory size&rsqb; Set the
680 maximum stack size for an individual thread to
681 <replaceable>size</replaceable> bytes. If the thread
682 attempts to exceed this limit, it will be sent the
683 <literal>StackOverflow</literal> exception. The
684 limit can be disabled entirely by specifying a size of zero.
685 </para>
686 <para>
687 This option is there mainly to stop the program eating up
688 all the available memory in the machine if it gets into an
689 infinite loop.
690 </para>
691 </listitem>
692 </varlistentry>
693
694 <varlistentry>
695 <term>
696 <option>-m</option><replaceable>n</replaceable>
697 <indexterm><primary><option>-m</option></primary><secondary>RTS option</secondary></indexterm>
698 <indexterm><primary>heap, minimum free</primary></indexterm>
699 </term>
700 <listitem>
701 <para>Minimum &percnt; <replaceable>n</replaceable> of heap
702 which must be available for allocation. The default is
703 3&percnt;.</para>
704 </listitem>
705 </varlistentry>
706
707 <varlistentry>
708 <term>
709 <option>-M</option><replaceable>size</replaceable>
710 <indexterm><primary><option>-M</option></primary><secondary>RTS option</secondary></indexterm>
711 <indexterm><primary>heap size, maximum</primary></indexterm>
712 </term>
713 <listitem>
714 <para>&lsqb;Default: unlimited&rsqb; Set the maximum heap size to
715 <replaceable>size</replaceable> bytes. The heap normally
716 grows and shrinks according to the memory requirements of
717 the program. The only reason for having this option is to
718 stop the heap growing without bound and filling up all the
719 available swap space, which at the least will result in the
720 program being summarily killed by the operating
721 system.</para>
722
723 <para>The maximum heap size also affects other garbage
724 collection parameters: when the amount of live data in the
725 heap exceeds a certain fraction of the maximum heap size,
726 compacting collection will be automatically enabled for the
727 oldest generation, and the <option>-F</option> parameter
728 will be reduced in order to avoid exceeding the maximum heap
729 size.</para>
730 </listitem>
731 </varlistentry>
732
733 <varlistentry>
734 <term>
735 <option>-T</option>
736 <indexterm><primary><option>-T</option></primary><secondary>RTS option</secondary></indexterm>
737 </term>
738 <term>
739 <option>-t</option><optional><replaceable>file</replaceable></optional>
740 <indexterm><primary><option>-t</option></primary><secondary>RTS option</secondary></indexterm>
741 </term>
742 <term>
743 <option>-s</option><optional><replaceable>file</replaceable></optional>
744 <indexterm><primary><option>-s</option></primary><secondary>RTS option</secondary></indexterm>
745 </term>
746 <term>
747 <option>-S</option><optional><replaceable>file</replaceable></optional>
748 <indexterm><primary><option>-S</option></primary><secondary>RTS option</secondary></indexterm>
749 </term>
750 <term>
751 <option>--machine-readable</option>
752 <indexterm><primary><option>--machine-readable</option></primary><secondary>RTS option</secondary></indexterm>
753 </term>
754 <listitem>
755 <para>These options produce runtime-system statistics, such
756 as the amount of time spent executing the program and in the
757 garbage collector, the amount of memory allocated, the
758 maximum size of the heap, and so on. The three
759 variants give different levels of detail:
760 <option>-T</option> collects the data but produces no output
761 <option>-t</option> produces a single line of output in the
762 same format as GHC's <option>-Rghc-timing</option> option,
763 <option>-s</option> produces a more detailed summary at the
764 end of the program, and <option>-S</option> additionally
765 produces information about each and every garbage
766 collection.</para>
767
768 <para>The output is placed in
769 <replaceable>file</replaceable>. If
770 <replaceable>file</replaceable> is omitted, then the output
771 is sent to <constant>stderr</constant>.</para>
772
773 <para>
774 If you use the <literal>-T</literal> flag then, you should
775 access the statistics using
776 <ulink url="&libraryBaseLocation;/GHC-Stats.html">GHC.Stats</ulink>.
777 </para>
778
779 <para>
780 If you use the <literal>-t</literal> flag then, when your
781 program finishes, you will see something like this:
782 </para>
783
784 <programlisting>
785 &lt;&lt;ghc: 36169392 bytes, 69 GCs, 603392/1065272 avg/max bytes residency (2 samples), 3M in use, 0.00 INIT (0.00 elapsed), 0.02 MUT (0.02 elapsed), 0.07 GC (0.07 elapsed) :ghc&gt;&gt;
786 </programlisting>
787
788 <para>
789 This tells you:
790 </para>
791
792 <itemizedlist>
793 <listitem>
794 <para>
795 The total number of bytes allocated by the program over the
796 whole run.
797 </para>
798 </listitem>
799 <listitem>
800 <para>
801 The total number of garbage collections performed.
802 </para>
803 </listitem>
804 <listitem>
805 <para>
806 The average and maximum "residency", which is the amount of
807 live data in bytes. The runtime can only determine the
808 amount of live data during a major GC, which is why the
809 number of samples corresponds to the number of major GCs
810 (and is usually relatively small). To get a better picture
811 of the heap profile of your program, use
812 the <option>-hT</option> RTS option
813 (<xref linkend="rts-profiling" />).
814 </para>
815 </listitem>
816 <listitem>
817 <para>
818 The peak memory the RTS has allocated from the OS.
819 </para>
820 </listitem>
821 <listitem>
822 <para>
823 The amount of CPU time and elapsed wall clock time while
824 initialising the runtime system (INIT), running the program
825 itself (MUT, the mutator), and garbage collecting (GC).
826 </para>
827 </listitem>
828 </itemizedlist>
829
830 <para>
831 You can also get this in a more future-proof, machine readable
832 format, with <literal>-t --machine-readable</literal>:
833 </para>
834
835 <programlisting>
836 [("bytes allocated", "36169392")
837 ,("num_GCs", "69")
838 ,("average_bytes_used", "603392")
839 ,("max_bytes_used", "1065272")
840 ,("num_byte_usage_samples", "2")
841 ,("peak_megabytes_allocated", "3")
842 ,("init_cpu_seconds", "0.00")
843 ,("init_wall_seconds", "0.00")
844 ,("mutator_cpu_seconds", "0.02")
845 ,("mutator_wall_seconds", "0.02")
846 ,("GC_cpu_seconds", "0.07")
847 ,("GC_wall_seconds", "0.07")
848 ]
849 </programlisting>
850
851 <para>
852 If you use the <literal>-s</literal> flag then, when your
853 program finishes, you will see something like this (the exact
854 details will vary depending on what sort of RTS you have, e.g.
855 you will only see profiling data if your RTS is compiled for
856 profiling):
857 </para>
858
859 <programlisting>
860 36,169,392 bytes allocated in the heap
861 4,057,632 bytes copied during GC
862 1,065,272 bytes maximum residency (2 sample(s))
863 54,312 bytes maximum slop
864 3 MB total memory in use (0 MB lost due to fragmentation)
865
866 Generation 0: 67 collections, 0 parallel, 0.04s, 0.03s elapsed
867 Generation 1: 2 collections, 0 parallel, 0.03s, 0.04s elapsed
868
869 SPARKS: 359207 (557 converted, 149591 pruned)
870
871 INIT time 0.00s ( 0.00s elapsed)
872 MUT time 0.01s ( 0.02s elapsed)
873 GC time 0.07s ( 0.07s elapsed)
874 EXIT time 0.00s ( 0.00s elapsed)
875 Total time 0.08s ( 0.09s elapsed)
876
877 %GC time 89.5% (75.3% elapsed)
878
879 Alloc rate 4,520,608,923 bytes per MUT second
880
881 Productivity 10.5% of total user, 9.1% of total elapsed
882 </programlisting>
883
884 <itemizedlist>
885 <listitem>
886 <para>
887 The "bytes allocated in the heap" is the total bytes allocated
888 by the program over the whole run.
889 </para>
890 </listitem>
891 <listitem>
892 <para>
893 GHC uses a copying garbage collector by default. "bytes copied
894 during GC" tells you how many bytes it had to copy during
895 garbage collection.
896 </para>
897 </listitem>
898 <listitem>
899 <para>
900 The maximum space actually used by your program is the
901 "bytes maximum residency" figure. This is only checked during
902 major garbage collections, so it is only an approximation;
903 the number of samples tells you how many times it is checked.
904 </para>
905 </listitem>
906 <listitem>
907 <para>
908 The "bytes maximum slop" tells you the most space that is ever
909 wasted due to the way GHC allocates memory in blocks. Slop is
910 memory at the end of a block that was wasted. There's no way
911 to control this; we just like to see how much memory is being
912 lost this way.
913 </para>
914 </listitem>
915 <listitem>
916 <para>
917 The "total memory in use" tells you the peak memory the RTS has
918 allocated from the OS.
919 </para>
920 </listitem>
921 <listitem>
922 <para>
923 Next there is information about the garbage collections done.
924 For each generation it says how many garbage collections were
925 done, how many of those collections were done in parallel,
926 the total CPU time used for garbage collecting that generation,
927 and the total wall clock time elapsed while garbage collecting
928 that generation.
929 </para>
930 </listitem>
931 <listitem>
932 <para>The <literal>SPARKS</literal> statistic refers to the
933 use of <literal>Control.Parallel.par</literal> and related
934 functionality in the program. Each spark represents a call
935 to <literal>par</literal>; a spark is "converted" when it is
936 executed in parallel; and a spark is "pruned" when it is
937 found to be already evaluated and is discarded from the pool
938 by the garbage collector. Any remaining sparks are
939 discarded at the end of execution, so "converted" plus
940 "pruned" does not necessarily add up to the total.</para>
941 </listitem>
942 <listitem>
943 <para>
944 Next there is the CPU time and wall clock time elapsed broken
945 down by what the runtime system was doing at the time.
946 INIT is the runtime system initialisation.
947 MUT is the mutator time, i.e. the time spent actually running
948 your code.
949 GC is the time spent doing garbage collection.
950 RP is the time spent doing retainer profiling.
951 PROF is the time spent doing other profiling.
952 EXIT is the runtime system shutdown time.
953 And finally, Total is, of course, the total.
954 </para>
955 <para>
956 %GC time tells you what percentage GC is of Total.
957 "Alloc rate" tells you the "bytes allocated in the heap" divided
958 by the MUT CPU time.
959 "Productivity" tells you what percentage of the Total CPU and wall
960 clock elapsed times are spent in the mutator (MUT).
961 </para>
962 </listitem>
963 </itemizedlist>
964
965 <para>
966 The <literal>-S</literal> flag, as well as giving the same
967 output as the <literal>-s</literal> flag, prints information
968 about each GC as it happens:
969 </para>
970
971 <programlisting>
972 Alloc Copied Live GC GC TOT TOT Page Flts
973 bytes bytes bytes user elap user elap
974 528496 47728 141512 0.01 0.02 0.02 0.02 0 0 (Gen: 1)
975 [...]
976 524944 175944 1726384 0.00 0.00 0.08 0.11 0 0 (Gen: 0)
977 </programlisting>
978
979 <para>
980 For each garbage collection, we print:
981 </para>
982
983 <itemizedlist>
984 <listitem>
985 <para>
986 How many bytes we allocated this garbage collection.
987 </para>
988 </listitem>
989 <listitem>
990 <para>
991 How many bytes we copied this garbage collection.
992 </para>
993 </listitem>
994 <listitem>
995 <para>
996 How many bytes are currently live.
997 </para>
998 </listitem>
999 <listitem>
1000 <para>
1001 How long this garbage collection took (CPU time and elapsed
1002 wall clock time).
1003 </para>
1004 </listitem>
1005 <listitem>
1006 <para>
1007 How long the program has been running (CPU time and elapsed
1008 wall clock time).
1009 </para>
1010 </listitem>
1011 <listitem>
1012 <para>
1013 How many page faults occurred this garbage collection.
1014 </para>
1015 </listitem>
1016 <listitem>
1017 <para>
1018 How many page faults occurred since the end of the last garbage
1019 collection.
1020 </para>
1021 </listitem>
1022 <listitem>
1023 <para>
1024 Which generation is being garbage collected.
1025 </para>
1026 </listitem>
1027 </itemizedlist>
1028
1029 </listitem>
1030 </varlistentry>
1031 </variablelist>
1032
1033 </sect2>
1034
1035 <sect2>
1036 <title>RTS options for concurrency and parallelism</title>
1037
1038 <para>The RTS options related to concurrency are described in
1039 <xref linkend="using-concurrent" />, and those for parallelism in
1040 <xref linkend="parallel-options"/>.</para>
1041 </sect2>
1042
1043 <sect2 id="rts-profiling">
1044 <title>RTS options for profiling</title>
1045
1046 <para>Most profiling runtime options are only available when you
1047 compile your program for profiling (see
1048 <xref linkend="prof-compiler-options" />, and
1049 <xref linkend="rts-options-heap-prof" /> for the runtime options).
1050 However, there is one profiling option that is available
1051 for ordinary non-profiled executables:</para>
1052
1053 <variablelist>
1054 <varlistentry>
1055 <term>
1056 <option>-hT</option>
1057 <indexterm><primary><option>-hT</option></primary><secondary>RTS
1058 option</secondary></indexterm>
1059 </term>
1060 <listitem>
1061 <para>(can be shortened to <option>-h</option>.) Generates a basic heap profile, in the
1062 file <literal><replaceable>prog</replaceable>.hp</literal>.
1063 To produce the heap profile graph,
1064 use <command>hp2ps</command> (see <xref linkend="hp2ps"
1065 />). The basic heap profile is broken down by data
1066 constructor, with other types of closures (functions, thunks,
1067 etc.) grouped into broad categories
1068 (e.g. <literal>FUN</literal>, <literal>THUNK</literal>). To
1069 get a more detailed profile, use the full profiling
1070 support (<xref linkend="profiling" />).</para>
1071 </listitem>
1072 </varlistentry>
1073 </variablelist>
1074 </sect2>
1075
1076 <sect2 id="rts-eventlog">
1077 <title>Tracing</title>
1078
1079 <indexterm><primary>tracing</primary></indexterm>
1080 <indexterm><primary>events</primary></indexterm>
1081 <indexterm><primary>eventlog files</primary></indexterm>
1082
1083 <para>
1084 When the program is linked with the <option>-eventlog</option>
1085 option (<xref linkend="options-linker" />), runtime events can
1086 be logged in two ways:
1087 </para>
1088
1089 <itemizedlist>
1090 <listitem>
1091 <para>
1092 In binary format to a file for later analysis by a
1093 variety of tools. One such tool
1094 is <ulink url="http://www.haskell.org/haskellwiki/ThreadScope">ThreadScope</ulink><indexterm><primary>ThreadScope</primary></indexterm>,
1095 which interprets the event log to produce a visual parallel
1096 execution profile of the program.
1097 </para>
1098 </listitem>
1099 <listitem>
1100 <para>
1101 As text to standard output, for debugging purposes.
1102 </para>
1103 </listitem>
1104 </itemizedlist>
1105
1106 <variablelist>
1107 <varlistentry>
1108 <term>
1109 <option>-l<optional><replaceable>flags</replaceable></optional></option>
1110 <indexterm><primary><option>-l</option></primary><secondary>RTS option</secondary></indexterm>
1111 </term>
1112 <listitem>
1113 <para>
1114 Log events in binary format to the
1115 file <filename><replaceable>program</replaceable>.eventlog</filename>.
1116 Without any <replaceable>flags</replaceable> specified, this logs a
1117 default set of events, suitable for use with tools like ThreadScope.
1118 </para>
1119
1120 <para>
1121 For some special use cases you may want more control over which
1122 events are included. The <replaceable>flags</replaceable> is a
1123 sequence of zero or more characters indicating which classes of
1124 events to log. Currently these the classes of events that can
1125 be enabled/disabled:
1126 <simplelist>
1127 <member>
1128 <option>s</option> &#8212; scheduler events, including Haskell
1129 thread creation and start/stop events. Enabled by default.
1130 </member>
1131 <member>
1132 <option>g</option> &#8212; GC events, including GC start/stop.
1133 Enabled by default.
1134 </member>
1135 <member>
1136 <option>p</option> &#8212; parallel sparks (sampled).
1137 Enabled by default.
1138 </member>
1139 <member>
1140 <option>f</option> &#8212; parallel sparks (fully accurate).
1141 Disabled by default.
1142 </member>
1143 <member>
1144 <option>u</option> &#8212; user events. These are events emitted
1145 from Haskell code using functions such as
1146 <literal>Debug.Trace.traceEvent</literal>. Enabled by default.
1147 </member>
1148 </simplelist>
1149 </para>
1150
1151 <para>
1152 You can disable specific classes, or enable/disable all classes at
1153 once:
1154 <simplelist>
1155 <member>
1156 <option>a</option> &#8212; enable all event classes listed above
1157 </member>
1158 <member>
1159 <option>-<replaceable>x</replaceable></option> &#8212; disable the
1160 given class of events, for any event class listed above or
1161 <option>-a</option> for all classes
1162 </member>
1163 </simplelist>
1164 For example, <option>-l-ag</option> would disable all event classes
1165 (<option>-a</option>) except for GC events (<option>g</option>).
1166 </para>
1167
1168 <para>
1169 For spark events there are two modes: sampled and fully accurate.
1170 There are various events in the life cycle of each spark, usually
1171 just creating and running, but there are some more exceptional
1172 possibilities. In the sampled mode the number of occurrences of each
1173 kind of spark event is sampled at frequent intervals. In the fully
1174 accurate mode every spark event is logged individually. The latter
1175 has a higher runtime overhead and is not enabled by default.
1176 </para>
1177
1178 <para>
1179 The format of the log file is described by the header
1180 <filename>EventLogFormat.h</filename> that comes with
1181 GHC, and it can be parsed in Haskell using
1182 the <ulink url="http://hackage.haskell.org/package/ghc-events">ghc-events</ulink>
1183 library. To dump the contents of
1184 a <literal>.eventlog</literal> file as text, use the
1185 tool <literal>ghc-events show</literal> that comes with
1186 the <ulink url="http://hackage.haskell.org/package/ghc-events">ghc-events</ulink>
1187 package.
1188 </para>
1189 </listitem>
1190 </varlistentry>
1191
1192 <varlistentry>
1193 <term>
1194 <option>-v</option><optional><replaceable>flags</replaceable></optional>
1195 <indexterm><primary><option>-v</option></primary><secondary>RTS option</secondary></indexterm>
1196 </term>
1197 <listitem>
1198 <para>
1199 Log events as text to standard output, instead of to
1200 the <literal>.eventlog</literal> file.
1201 The <replaceable>flags</replaceable> are the same as
1202 for <option>-l</option>, with the additional
1203 option <literal>t</literal> which indicates that the
1204 each event printed should be preceded by a timestamp value
1205 (in the binary <literal>.eventlog</literal> file, all
1206 events are automatically associated with a timestamp).
1207 </para>
1208 </listitem>
1209 </varlistentry>
1210
1211 </variablelist>
1212
1213 <para>
1214 The debugging
1215 options <option>-D<replaceable>x</replaceable></option> also
1216 generate events which are logged using the tracing framework.
1217 By default those events are dumped as text to stdout
1218 (<option>-D<replaceable>x</replaceable></option>
1219 implies <option>-v</option>), but they may instead be stored in
1220 the binary eventlog file by using the <option>-l</option>
1221 option.
1222 </para>
1223 </sect2>
1224
1225 <sect2 id="rts-options-debugging">
1226 <title>RTS options for hackers, debuggers, and over-interested
1227 souls</title>
1228
1229 <indexterm><primary>RTS options, hacking/debugging</primary></indexterm>
1230
1231 <para>These RTS options might be used (a)&nbsp;to avoid a GHC bug,
1232 (b)&nbsp;to see &ldquo;what's really happening&rdquo;, or
1233 (c)&nbsp;because you feel like it. Not recommended for everyday
1234 use!</para>
1235
1236 <variablelist>
1237
1238 <varlistentry>
1239 <term>
1240 <option>-B</option>
1241 <indexterm><primary><option>-B</option></primary><secondary>RTS option</secondary></indexterm>
1242 </term>
1243 <listitem>
1244 <para>Sound the bell at the start of each (major) garbage
1245 collection.</para>
1246
1247 <para>Oddly enough, people really do use this option! Our
1248 pal in Durham (England), Paul Callaghan, writes: &ldquo;Some
1249 people here use it for a variety of
1250 purposes&mdash;honestly!&mdash;e.g., confirmation that the
1251 code/machine is doing something, infinite loop detection,
1252 gauging cost of recently added code. Certain people can even
1253 tell what stage &lsqb;the program&rsqb; is in by the beep
1254 pattern. But the major use is for annoying others in the
1255 same office&hellip;&rdquo;</para>
1256 </listitem>
1257 </varlistentry>
1258
1259 <varlistentry>
1260 <term>
1261 <option>-D</option><replaceable>x</replaceable>
1262 <indexterm><primary>-D</primary><secondary>RTS option</secondary></indexterm>
1263 </term>
1264 <listitem>
1265 <para>
1266 An RTS debugging flag; only available if the program was
1267 linked with the <option>-debug</option> option. Various
1268 values of <replaceable>x</replaceable> are provided to
1269 enable debug messages and additional runtime sanity checks
1270 in different subsystems in the RTS, for
1271 example <literal>+RTS -Ds -RTS</literal> enables debug
1272 messages from the scheduler.
1273 Use <literal>+RTS&nbsp;-?</literal> to find out which
1274 debug flags are supported.
1275 </para>
1276
1277 <para>
1278 Debug messages will be sent to the binary event log file
1279 instead of stdout if the <option>-l</option> option is
1280 added. This might be useful for reducing the overhead of
1281 debug tracing.
1282 </para>
1283 </listitem>
1284 </varlistentry>
1285
1286 <varlistentry>
1287 <term>
1288 <option>-r</option><replaceable>file</replaceable>
1289 <indexterm><primary><option>-r</option></primary><secondary>RTS option</secondary></indexterm>
1290 <indexterm><primary>ticky ticky profiling</primary></indexterm>
1291 <indexterm><primary>profiling</primary><secondary>ticky ticky</secondary></indexterm>
1292 </term>
1293 <listitem>
1294 <para>Produce &ldquo;ticky-ticky&rdquo; statistics at the
1295 end of the program run (only available if the program was
1296 linked with <option>-debug</option>).
1297 The <replaceable>file</replaceable> business works just like
1298 on the <option>-S</option> RTS option, above.</para>
1299
1300 <para>For more information on ticky-ticky profiling, see
1301 <xref linkend="ticky-ticky"/>.</para>
1302 </listitem>
1303 </varlistentry>
1304
1305 <varlistentry>
1306 <term>
1307 <option>-xc</option>
1308 <indexterm><primary><option>-xc</option></primary><secondary>RTS option</secondary></indexterm>
1309 </term>
1310 <listitem>
1311 <para>(Only available when the program is compiled for
1312 profiling.) When an exception is raised in the program,
1313 this option causes a stack trace to be
1314 dumped to <literal>stderr</literal>.</para>
1315
1316 <para>This can be particularly useful for debugging: if your
1317 program is complaining about a <literal>head []</literal>
1318 error and you haven't got a clue which bit of code is
1319 causing it, compiling with <literal>-prof
1320 -fprof-auto</literal> and running with <literal>+RTS -xc
1321 -RTS</literal> will tell you exactly the call stack at the
1322 point the error was raised.</para>
1323
1324 <para>The output contains one report for each exception
1325 raised in the program (the program might raise and catch
1326 several exceptions during its execution), where each report
1327 looks something like this:
1328 </para>
1329
1330 <screen>
1331 *** Exception raised (reporting due to +RTS -xc), stack trace:
1332 GHC.List.CAF
1333 --> evaluated by: Main.polynomial.table_search,
1334 called from Main.polynomial.theta_index,
1335 called from Main.polynomial,
1336 called from Main.zonal_pressure,
1337 called from Main.make_pressure.p,
1338 called from Main.make_pressure,
1339 called from Main.compute_initial_state.p,
1340 called from Main.compute_initial_state,
1341 called from Main.CAF
1342 ...
1343 </screen>
1344 <para>The stack trace may often begin with something
1345 uninformative like <literal>GHC.List.CAF</literal>; this is
1346 an artifact of GHC's optimiser, which lifts out exceptions
1347 to the top-level where the profiling system assigns them to
1348 the cost centre "CAF". However, <literal>+RTS -xc</literal>
1349 doesn't just print the current stack, it looks deeper and
1350 reports the stack at the time the CAF was evaluated, and it
1351 may report further stacks until a non-CAF stack is found. In
1352 the example above, the next stack (after <literal>-->
1353 evaluated by</literal>) contains plenty of information about
1354 what the program was doing when it evaluated <literal>head
1355 []</literal>.</para>
1356
1357 <para>Implementation details aside, the function names in
1358 the stack should hopefully give you enough clues to track
1359 down the bug.</para>
1360
1361 <para>
1362 See also the function <literal>traceStack</literal> in the
1363 module <literal>Debug.Trace</literal> for another way to
1364 view call stacks.
1365 </para>
1366 </listitem>
1367 </varlistentry>
1368
1369 <varlistentry>
1370 <term>
1371 <option>-Z</option>
1372 <indexterm><primary><option>-Z</option></primary><secondary>RTS option</secondary></indexterm>
1373 </term>
1374 <listitem>
1375 <para>Turn <emphasis>off</emphasis> &ldquo;update-frame
1376 squeezing&rdquo; at garbage-collection time. (There's no
1377 particularly good reason to turn it off, except to ensure
1378 the accuracy of certain data collected regarding thunk entry
1379 counts.)</para>
1380 </listitem>
1381 </varlistentry>
1382 </variablelist>
1383
1384 </sect2>
1385
1386 <sect2 id="ghc-info">
1387 <title>Getting information about the RTS</title>
1388
1389 <indexterm><primary>RTS</primary></indexterm>
1390
1391 <para>It is possible to ask the RTS to give some information about
1392 itself. To do this, use the <option>--info</option> flag, e.g.</para>
1393 <screen>
1394 $ ./a.out +RTS --info
1395 [("GHC RTS", "YES")
1396 ,("GHC version", "6.7")
1397 ,("RTS way", "rts_p")
1398 ,("Host platform", "x86_64-unknown-linux")
1399 ,("Host architecture", "x86_64")
1400 ,("Host OS", "linux")
1401 ,("Host vendor", "unknown")
1402 ,("Build platform", "x86_64-unknown-linux")
1403 ,("Build architecture", "x86_64")
1404 ,("Build OS", "linux")
1405 ,("Build vendor", "unknown")
1406 ,("Target platform", "x86_64-unknown-linux")
1407 ,("Target architecture", "x86_64")
1408 ,("Target OS", "linux")
1409 ,("Target vendor", "unknown")
1410 ,("Word size", "64")
1411 ,("Compiler unregisterised", "NO")
1412 ,("Tables next to code", "YES")
1413 ]
1414 </screen>
1415 <para>The information is formatted such that it can be read as a
1416 of type <literal>[(String, String)]</literal>. Currently the following
1417 fields are present:</para>
1418
1419 <variablelist>
1420
1421 <varlistentry>
1422 <term><literal>GHC RTS</literal></term>
1423 <listitem>
1424 <para>Is this program linked against the GHC RTS? (always
1425 "YES").</para>
1426 </listitem>
1427 </varlistentry>
1428
1429 <varlistentry>
1430 <term><literal>GHC version</literal></term>
1431 <listitem>
1432 <para>The version of GHC used to compile this program.</para>
1433 </listitem>
1434 </varlistentry>
1435
1436 <varlistentry>
1437 <term><literal>RTS way</literal></term>
1438 <listitem>
1439 <para>The variant (&ldquo;way&rdquo;) of the runtime. The
1440 most common values are <literal>rts_v</literal> (vanilla),
1441 <literal>rts_thr</literal> (threaded runtime, i.e. linked using the
1442 <literal>-threaded</literal> option) and <literal>rts_p</literal>
1443 (profiling runtime, i.e. linked using the <literal>-prof</literal>
1444 option). Other variants include <literal>debug</literal>
1445 (linked using <literal>-debug</literal>), and
1446 <literal>dyn</literal> (the RTS is
1447 linked in dynamically, i.e. a shared library, rather than statically
1448 linked into the executable itself). These can be combined,
1449 e.g. you might have <literal>rts_thr_debug_p</literal>.</para>
1450 </listitem>
1451 </varlistentry>
1452
1453 <varlistentry>
1454 <term>
1455 <literal>Target platform</literal>,
1456 <literal>Target architecture</literal>,
1457 <literal>Target OS</literal>,
1458 <literal>Target vendor</literal>
1459 </term>
1460 <listitem>
1461 <para>These are the platform the program is compiled to run on.</para>
1462 </listitem>
1463 </varlistentry>
1464
1465 <varlistentry>
1466 <term>
1467 <literal>Build platform</literal>,
1468 <literal>Build architecture</literal>,
1469 <literal>Build OS</literal>,
1470 <literal>Build vendor</literal>
1471 </term>
1472 <listitem>
1473 <para>These are the platform where the program was built
1474 on. (That is, the target platform of GHC itself.) Ordinarily
1475 this is identical to the target platform. (It could potentially
1476 be different if cross-compiling.)</para>
1477 </listitem>
1478 </varlistentry>
1479
1480 <varlistentry>
1481 <term>
1482 <literal>Host platform</literal>,
1483 <literal>Host architecture</literal>
1484 <literal>Host OS</literal>
1485 <literal>Host vendor</literal>
1486 </term>
1487 <listitem>
1488 <para>These are the platform where GHC itself was compiled.
1489 Again, this would normally be identical to the build and
1490 target platforms.</para>
1491 </listitem>
1492 </varlistentry>
1493
1494 <varlistentry>
1495 <term><literal>Word size</literal></term>
1496 <listitem>
1497 <para>Either <literal>"32"</literal> or <literal>"64"</literal>,
1498 reflecting the word size of the target platform.</para>
1499 </listitem>
1500 </varlistentry>
1501
1502 <varlistentry>
1503 <term><literal>Compiler unregistered</literal></term>
1504 <listitem>
1505 <para>Was this program compiled with an
1506 <link linkend="unreg">&ldquo;unregistered&rdquo;</link>
1507 version of GHC? (I.e., a version of GHC that has no platform-specific
1508 optimisations compiled in, usually because this is a currently
1509 unsupported platform.) This value will usually be no, unless you're
1510 using an experimental build of GHC.</para>
1511 </listitem>
1512 </varlistentry>
1513
1514 <varlistentry>
1515 <term><literal>Tables next to code</literal></term>
1516 <listitem>
1517 <para>Putting info tables directly next to entry code is a useful
1518 performance optimisation that is not available on all platforms.
1519 This field tells you whether the program has been compiled with
1520 this optimisation. (Usually yes, except on unusual platforms.)</para>
1521 </listitem>
1522 </varlistentry>
1523
1524 </variablelist>
1525
1526 </sect2>
1527 </sect1>
1528
1529 <!-- Emacs stuff:
1530 ;;; Local Variables: ***
1531 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***
1532 ;;; End: ***
1533 -->