Merge branch 'master' of http://darcs.haskell.org/ghc
[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>&ndash;&ndash;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: 8M&rsqb; Set the maximum stack size for
680 an individual thread to <replaceable>size</replaceable>
681 bytes. If the thread attempts to exceed this limit, it will
682 be send the <literal>StackOverflow</literal> exception.
683 </para>
684 <para>
685 This option is there mainly to stop the program eating up
686 all the available memory in the machine if it gets into an
687 infinite loop.
688 </para>
689 </listitem>
690 </varlistentry>
691
692 <varlistentry>
693 <term>
694 <option>-m</option><replaceable>n</replaceable>
695 <indexterm><primary><option>-m</option></primary><secondary>RTS option</secondary></indexterm>
696 <indexterm><primary>heap, minimum free</primary></indexterm>
697 </term>
698 <listitem>
699 <para>Minimum &percnt; <replaceable>n</replaceable> of heap
700 which must be available for allocation. The default is
701 3&percnt;.</para>
702 </listitem>
703 </varlistentry>
704
705 <varlistentry>
706 <term>
707 <option>-M</option><replaceable>size</replaceable>
708 <indexterm><primary><option>-M</option></primary><secondary>RTS option</secondary></indexterm>
709 <indexterm><primary>heap size, maximum</primary></indexterm>
710 </term>
711 <listitem>
712 <para>&lsqb;Default: unlimited&rsqb; Set the maximum heap size to
713 <replaceable>size</replaceable> bytes. The heap normally
714 grows and shrinks according to the memory requirements of
715 the program. The only reason for having this option is to
716 stop the heap growing without bound and filling up all the
717 available swap space, which at the least will result in the
718 program being summarily killed by the operating
719 system.</para>
720
721 <para>The maximum heap size also affects other garbage
722 collection parameters: when the amount of live data in the
723 heap exceeds a certain fraction of the maximum heap size,
724 compacting collection will be automatically enabled for the
725 oldest generation, and the <option>-F</option> parameter
726 will be reduced in order to avoid exceeding the maximum heap
727 size.</para>
728 </listitem>
729 </varlistentry>
730
731 <varlistentry>
732 <term>
733 <option>-t</option><optional><replaceable>file</replaceable></optional>
734 <indexterm><primary><option>-t</option></primary><secondary>RTS option</secondary></indexterm>
735 </term>
736 <term>
737 <option>-s</option><optional><replaceable>file</replaceable></optional>
738 <indexterm><primary><option>-s</option></primary><secondary>RTS option</secondary></indexterm>
739 </term>
740 <term>
741 <option>-S</option><optional><replaceable>file</replaceable></optional>
742 <indexterm><primary><option>-S</option></primary><secondary>RTS option</secondary></indexterm>
743 </term>
744 <term>
745 <option>--machine-readable</option>
746 <indexterm><primary><option>--machine-readable</option></primary><secondary>RTS option</secondary></indexterm>
747 </term>
748 <listitem>
749 <para>These options produce runtime-system statistics, such
750 as the amount of time spent executing the program and in the
751 garbage collector, the amount of memory allocated, the
752 maximum size of the heap, and so on. The three
753 variants give different levels of detail:
754 <option>-t</option> produces a single line of output in the
755 same format as GHC's <option>-Rghc-timing</option> option,
756 <option>-s</option> produces a more detailed summary at the
757 end of the program, and <option>-S</option> additionally
758 produces information about each and every garbage
759 collection.</para>
760
761 <para>The output is placed in
762 <replaceable>file</replaceable>. If
763 <replaceable>file</replaceable> is omitted, then the output
764 is sent to <constant>stderr</constant>.</para>
765
766 <para>
767 If you use the <literal>-t</literal> flag then, when your
768 program finishes, you will see something like this:
769 </para>
770
771 <programlisting>
772 &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;
773 </programlisting>
774
775 <para>
776 This tells you:
777 </para>
778
779 <itemizedlist>
780 <listitem>
781 <para>
782 The total number of bytes allocated by the program over the
783 whole run.
784 </para>
785 </listitem>
786 <listitem>
787 <para>
788 The total number of garbage collections performed.
789 </para>
790 </listitem>
791 <listitem>
792 <para>
793 The average and maximum "residency", which is the amount of
794 live data in bytes. The runtime can only determine the
795 amount of live data during a major GC, which is why the
796 number of samples corresponds to the number of major GCs
797 (and is usually relatively small). To get a better picture
798 of the heap profile of your program, use
799 the <option>-hT</option> RTS option
800 (<xref linkend="rts-profiling" />).
801 </para>
802 </listitem>
803 <listitem>
804 <para>
805 The peak memory the RTS has allocated from the OS.
806 </para>
807 </listitem>
808 <listitem>
809 <para>
810 The amount of CPU time and elapsed wall clock time while
811 initialising the runtime system (INIT), running the program
812 itself (MUT, the mutator), and garbage collecting (GC).
813 </para>
814 </listitem>
815 </itemizedlist>
816
817 <para>
818 You can also get this in a more future-proof, machine readable
819 format, with <literal>-t --machine-readable</literal>:
820 </para>
821
822 <programlisting>
823 [("bytes allocated", "36169392")
824 ,("num_GCs", "69")
825 ,("average_bytes_used", "603392")
826 ,("max_bytes_used", "1065272")
827 ,("num_byte_usage_samples", "2")
828 ,("peak_megabytes_allocated", "3")
829 ,("init_cpu_seconds", "0.00")
830 ,("init_wall_seconds", "0.00")
831 ,("mutator_cpu_seconds", "0.02")
832 ,("mutator_wall_seconds", "0.02")
833 ,("GC_cpu_seconds", "0.07")
834 ,("GC_wall_seconds", "0.07")
835 ]
836 </programlisting>
837
838 <para>
839 If you use the <literal>-s</literal> flag then, when your
840 program finishes, you will see something like this (the exact
841 details will vary depending on what sort of RTS you have, e.g.
842 you will only see profiling data if your RTS is compiled for
843 profiling):
844 </para>
845
846 <programlisting>
847 36,169,392 bytes allocated in the heap
848 4,057,632 bytes copied during GC
849 1,065,272 bytes maximum residency (2 sample(s))
850 54,312 bytes maximum slop
851 3 MB total memory in use (0 MB lost due to fragmentation)
852
853 Generation 0: 67 collections, 0 parallel, 0.04s, 0.03s elapsed
854 Generation 1: 2 collections, 0 parallel, 0.03s, 0.04s elapsed
855
856 SPARKS: 359207 (557 converted, 149591 pruned)
857
858 INIT time 0.00s ( 0.00s elapsed)
859 MUT time 0.01s ( 0.02s elapsed)
860 GC time 0.07s ( 0.07s elapsed)
861 EXIT time 0.00s ( 0.00s elapsed)
862 Total time 0.08s ( 0.09s elapsed)
863
864 %GC time 89.5% (75.3% elapsed)
865
866 Alloc rate 4,520,608,923 bytes per MUT second
867
868 Productivity 10.5% of total user, 9.1% of total elapsed
869 </programlisting>
870
871 <itemizedlist>
872 <listitem>
873 <para>
874 The "bytes allocated in the heap" is the total bytes allocated
875 by the program over the whole run.
876 </para>
877 </listitem>
878 <listitem>
879 <para>
880 GHC uses a copying garbage collector by default. "bytes copied
881 during GC" tells you how many bytes it had to copy during
882 garbage collection.
883 </para>
884 </listitem>
885 <listitem>
886 <para>
887 The maximum space actually used by your program is the
888 "bytes maximum residency" figure. This is only checked during
889 major garbage collections, so it is only an approximation;
890 the number of samples tells you how many times it is checked.
891 </para>
892 </listitem>
893 <listitem>
894 <para>
895 The "bytes maximum slop" tells you the most space that is ever
896 wasted due to the way GHC allocates memory in blocks. Slop is
897 memory at the end of a block that was wasted. There's no way
898 to control this; we just like to see how much memory is being
899 lost this way.
900 </para>
901 </listitem>
902 <listitem>
903 <para>
904 The "total memory in use" tells you the peak memory the RTS has
905 allocated from the OS.
906 </para>
907 </listitem>
908 <listitem>
909 <para>
910 Next there is information about the garbage collections done.
911 For each generation it says how many garbage collections were
912 done, how many of those collections were done in parallel,
913 the total CPU time used for garbage collecting that generation,
914 and the total wall clock time elapsed while garbage collecting
915 that generation.
916 </para>
917 </listitem>
918 <listitem>
919 <para>The <literal>SPARKS</literal> statistic refers to the
920 use of <literal>Control.Parallel.par</literal> and related
921 functionality in the program. Each spark represents a call
922 to <literal>par</literal>; a spark is "converted" when it is
923 executed in parallel; and a spark is "pruned" when it is
924 found to be already evaluated and is discarded from the pool
925 by the garbage collector. Any remaining sparks are
926 discarded at the end of execution, so "converted" plus
927 "pruned" does not necessarily add up to the total.</para>
928 </listitem>
929 <listitem>
930 <para>
931 Next there is the CPU time and wall clock time elapsed broken
932 down by what the runtime system was doing at the time.
933 INIT is the runtime system initialisation.
934 MUT is the mutator time, i.e. the time spent actually running
935 your code.
936 GC is the time spent doing garbage collection.
937 RP is the time spent doing retainer profiling.
938 PROF is the time spent doing other profiling.
939 EXIT is the runtime system shutdown time.
940 And finally, Total is, of course, the total.
941 </para>
942 <para>
943 %GC time tells you what percentage GC is of Total.
944 "Alloc rate" tells you the "bytes allocated in the heap" divided
945 by the MUT CPU time.
946 "Productivity" tells you what percentage of the Total CPU and wall
947 clock elapsed times are spent in the mutator (MUT).
948 </para>
949 </listitem>
950 </itemizedlist>
951
952 <para>
953 The <literal>-S</literal> flag, as well as giving the same
954 output as the <literal>-s</literal> flag, prints information
955 about each GC as it happens:
956 </para>
957
958 <programlisting>
959 Alloc Copied Live GC GC TOT TOT Page Flts
960 bytes bytes bytes user elap user elap
961 528496 47728 141512 0.01 0.02 0.02 0.02 0 0 (Gen: 1)
962 [...]
963 524944 175944 1726384 0.00 0.00 0.08 0.11 0 0 (Gen: 0)
964 </programlisting>
965
966 <para>
967 For each garbage collection, we print:
968 </para>
969
970 <itemizedlist>
971 <listitem>
972 <para>
973 How many bytes we allocated this garbage collection.
974 </para>
975 </listitem>
976 <listitem>
977 <para>
978 How many bytes we copied this garbage collection.
979 </para>
980 </listitem>
981 <listitem>
982 <para>
983 How many bytes are currently live.
984 </para>
985 </listitem>
986 <listitem>
987 <para>
988 How long this garbage collection took (CPU time and elapsed
989 wall clock time).
990 </para>
991 </listitem>
992 <listitem>
993 <para>
994 How long the program has been running (CPU time and elapsed
995 wall clock time).
996 </para>
997 </listitem>
998 <listitem>
999 <para>
1000 How many page faults occurred this garbage collection.
1001 </para>
1002 </listitem>
1003 <listitem>
1004 <para>
1005 How many page faults occurred since the end of the last garbage
1006 collection.
1007 </para>
1008 </listitem>
1009 <listitem>
1010 <para>
1011 Which generation is being garbage collected.
1012 </para>
1013 </listitem>
1014 </itemizedlist>
1015
1016 </listitem>
1017 </varlistentry>
1018 </variablelist>
1019
1020 </sect2>
1021
1022 <sect2>
1023 <title>RTS options for concurrency and parallelism</title>
1024
1025 <para>The RTS options related to concurrency are described in
1026 <xref linkend="using-concurrent" />, and those for parallelism in
1027 <xref linkend="parallel-options"/>.</para>
1028 </sect2>
1029
1030 <sect2 id="rts-profiling">
1031 <title>RTS options for profiling</title>
1032
1033 <para>Most profiling runtime options are only available when you
1034 compile your program for profiling (see
1035 <xref linkend="prof-compiler-options" />, and
1036 <xref linkend="rts-options-heap-prof" /> for the runtime options).
1037 However, there is one profiling option that is available
1038 for ordinary non-profiled executables:</para>
1039
1040 <variablelist>
1041 <varlistentry>
1042 <term>
1043 <option>-hT</option>
1044 <indexterm><primary><option>-hT</option></primary><secondary>RTS
1045 option</secondary></indexterm>
1046 </term>
1047 <listitem>
1048 <para>(can be shortened to <option>-h</option>.) Generates a basic heap profile, in the
1049 file <literal><replaceable>prog</replaceable>.hp</literal>.
1050 To produce the heap profile graph,
1051 use <command>hp2ps</command> (see <xref linkend="hp2ps"
1052 />). The basic heap profile is broken down by data
1053 constructor, with other types of closures (functions, thunks,
1054 etc.) grouped into broad categories
1055 (e.g. <literal>FUN</literal>, <literal>THUNK</literal>). To
1056 get a more detailed profile, use the full profiling
1057 support (<xref linkend="profiling" />).</para>
1058 </listitem>
1059 </varlistentry>
1060 </variablelist>
1061 </sect2>
1062
1063 <sect2 id="rts-eventlog">
1064 <title>Tracing</title>
1065
1066 <indexterm><primary>tracing</primary></indexterm>
1067 <indexterm><primary>events</primary></indexterm>
1068 <indexterm><primary>eventlog files</primary></indexterm>
1069
1070 <para>
1071 When the program is linked with the <option>-eventlog</option>
1072 option (<xref linkend="options-linker" />), runtime events can
1073 be logged in two ways:
1074 </para>
1075
1076 <itemizedlist>
1077 <listitem>
1078 <para>
1079 In binary format to a file for later analysis by a
1080 variety of tools. One such tool
1081 is <ulink url="http://www.haskell.org/haskellwiki/ThreadScope">ThreadScope</ulink><indexterm><primary>ThreadScope</primary></indexterm>,
1082 which interprets the event log to produce a visual parallel
1083 execution profile of the program.
1084 </para>
1085 </listitem>
1086 <listitem>
1087 <para>
1088 As text to standard output, for debugging purposes.
1089 </para>
1090 </listitem>
1091 </itemizedlist>
1092
1093 <variablelist>
1094 <varlistentry>
1095 <term>
1096 <option>-l<optional><replaceable>flags</replaceable></optional></option>
1097 <indexterm><primary><option>-l</option></primary><secondary>RTS option</secondary></indexterm>
1098 </term>
1099 <listitem>
1100 <para>
1101 Log events in binary format to the
1102 file <filename><replaceable>program</replaceable>.eventlog</filename>.
1103 Without any <replaceable>flags</replaceable> specified, this logs a
1104 default set of events, suitable for use with tools like ThreadScope.
1105 </para>
1106
1107 <para>
1108 For some special use cases you may want more control over which
1109 events are included. The <replaceable>flags</replaceable> is a
1110 sequence of zero or more characters indicating which classes of
1111 events to log. Currently there are four classes of events that can
1112 be enabled/disabled:
1113 <simplelist>
1114 <member>
1115 <option>s</option> &#8212; scheduler events, including Haskell
1116 thread creation and start/stop events
1117 </member>
1118 <member>
1119 <option>g</option> &#8212; GC events, including GC start/stop
1120 </member>
1121 <member>
1122 <option>p</option> &#8212; parallel sparks (sampled)
1123 </member>
1124 <member>
1125 <option>f</option> &#8212; parallel sparks (fully accurate)
1126 </member>
1127 </simplelist>
1128 </para>
1129
1130 <para>
1131 For spark events there are two modes: sampled and fully accurate.
1132 There are various events in the life cycle of each spark, usually
1133 just creating and running, but there are some more exceptional
1134 possibilities. In the sampled mode the number of occurrences of each
1135 kind of spark event is sampled at frequent intervals. In the fully
1136 accurate mode every spark event is logged individually. The latter
1137 has a higher runtime overhead and is not enabled by default.
1138 </para>
1139
1140 <para>
1141 The initial enabled event classes are 's', 'g' and 'p'. In addition
1142 you can disable specific classes, or enable/disable all classes at
1143 once:
1144 <simplelist>
1145 <member>
1146 <option>a</option> &#8212; enable all event classes listed above
1147 </member>
1148 <member>
1149 <option>-<replaceable>x</replaceable></option> &#8212; disable the
1150 given class of events, for any event class listed above or
1151 <option>-a</option> for all classes
1152 </member>
1153 </simplelist>
1154 For example, <option>-l-ag</option> would disable all event classes
1155 (<option>-a</option>) except for GC events (<option>g</option>).
1156 </para>
1157
1158 <para>
1159 The format of the log file is described by the header
1160 <filename>EventLogFormat.h</filename> that comes with
1161 GHC, and it can be parsed in Haskell using
1162 the <ulink url="http://hackage.haskell.org/package/ghc-events">ghc-events</ulink>
1163 library. To dump the contents of
1164 a <literal>.eventlog</literal> file as text, use the
1165 tool <literal>ghc-events-show</literal> that comes with
1166 the <ulink url="http://hackage.haskell.org/package/ghc-events">ghc-events</ulink>
1167 package.
1168 </para>
1169 </listitem>
1170 </varlistentry>
1171
1172 <varlistentry>
1173 <term>
1174 <option>-v</option><optional><replaceable>flags</replaceable></optional>
1175 <indexterm><primary><option>-v</option></primary><secondary>RTS option</secondary></indexterm>
1176 </term>
1177 <listitem>
1178 <para>
1179 Log events as text to standard output, instead of to
1180 the <literal>.eventlog</literal> file.
1181 The <replaceable>flags</replaceable> are the same as
1182 for <option>-l</option>, with the additional
1183 option <literal>t</literal> which indicates that the
1184 each event printed should be preceded by a timestamp value
1185 (in the binary <literal>.eventlog</literal> file, all
1186 events are automatically associated with a timestamp).
1187 </para>
1188 </listitem>
1189 </varlistentry>
1190
1191 </variablelist>
1192
1193 <para>
1194 The debugging
1195 options <option>-D<replaceable>x</replaceable></option> also
1196 generate events which are logged using the tracing framework.
1197 By default those events are dumped as text to stdout
1198 (<option>-D<replaceable>x</replaceable></option>
1199 implies <option>-v</option>), but they may instead be stored in
1200 the binary eventlog file by using the <option>-l</option>
1201 option.
1202 </para>
1203 </sect2>
1204
1205 <sect2 id="rts-options-debugging">
1206 <title>RTS options for hackers, debuggers, and over-interested
1207 souls</title>
1208
1209 <indexterm><primary>RTS options, hacking/debugging</primary></indexterm>
1210
1211 <para>These RTS options might be used (a)&nbsp;to avoid a GHC bug,
1212 (b)&nbsp;to see &ldquo;what's really happening&rdquo;, or
1213 (c)&nbsp;because you feel like it. Not recommended for everyday
1214 use!</para>
1215
1216 <variablelist>
1217
1218 <varlistentry>
1219 <term>
1220 <option>-B</option>
1221 <indexterm><primary><option>-B</option></primary><secondary>RTS option</secondary></indexterm>
1222 </term>
1223 <listitem>
1224 <para>Sound the bell at the start of each (major) garbage
1225 collection.</para>
1226
1227 <para>Oddly enough, people really do use this option! Our
1228 pal in Durham (England), Paul Callaghan, writes: &ldquo;Some
1229 people here use it for a variety of
1230 purposes&mdash;honestly!&mdash;e.g., confirmation that the
1231 code/machine is doing something, infinite loop detection,
1232 gauging cost of recently added code. Certain people can even
1233 tell what stage &lsqb;the program&rsqb; is in by the beep
1234 pattern. But the major use is for annoying others in the
1235 same office&hellip;&rdquo;</para>
1236 </listitem>
1237 </varlistentry>
1238
1239 <varlistentry>
1240 <term>
1241 <option>-D</option><replaceable>x</replaceable>
1242 <indexterm><primary>-D</primary><secondary>RTS option</secondary></indexterm>
1243 </term>
1244 <listitem>
1245 <para>
1246 An RTS debugging flag; only available if the program was
1247 linked with the <option>-debug</option> option. Various
1248 values of <replaceable>x</replaceable> are provided to
1249 enable debug messages and additional runtime sanity checks
1250 in different subsystems in the RTS, for
1251 example <literal>+RTS -Ds -RTS</literal> enables debug
1252 messages from the scheduler.
1253 Use <literal>+RTS&nbsp;-?</literal> to find out which
1254 debug flags are supported.
1255 </para>
1256
1257 <para>
1258 Debug messages will be sent to the binary event log file
1259 instead of stdout if the <option>-l</option> option is
1260 added. This might be useful for reducing the overhead of
1261 debug tracing.
1262 </para>
1263 </listitem>
1264 </varlistentry>
1265
1266 <varlistentry>
1267 <term>
1268 <option>-r</option><replaceable>file</replaceable>
1269 <indexterm><primary><option>-r</option></primary><secondary>RTS option</secondary></indexterm>
1270 <indexterm><primary>ticky ticky profiling</primary></indexterm>
1271 <indexterm><primary>profiling</primary><secondary>ticky ticky</secondary></indexterm>
1272 </term>
1273 <listitem>
1274 <para>Produce &ldquo;ticky-ticky&rdquo; statistics at the
1275 end of the program run (only available if the program was
1276 linked with <option>-debug</option>).
1277 The <replaceable>file</replaceable> business works just like
1278 on the <option>-S</option> RTS option, above.</para>
1279
1280 <para>For more information on ticky-ticky profiling, see
1281 <xref linkend="ticky-ticky"/>.</para>
1282 </listitem>
1283 </varlistentry>
1284
1285 <varlistentry>
1286 <term>
1287 <option>-xc</option>
1288 <indexterm><primary><option>-xc</option></primary><secondary>RTS option</secondary></indexterm>
1289 </term>
1290 <listitem>
1291 <para>(Only available when the program is compiled for
1292 profiling.) When an exception is raised in the program,
1293 this option causes a stack trace to be
1294 dumped to <literal>stderr</literal>.</para>
1295
1296 <para>This can be particularly useful for debugging: if your
1297 program is complaining about a <literal>head []</literal>
1298 error and you haven't got a clue which bit of code is
1299 causing it, compiling with <literal>-prof
1300 -fprof-auto</literal> and running with <literal>+RTS -xc
1301 -RTS</literal> will tell you exactly the call stack at the
1302 point the error was raised.</para>
1303
1304 <para>The output contains one report for each exception
1305 raised in the program (the program might raise and catch
1306 several exceptions during its execution), where each report
1307 looks something like this:
1308 </para>
1309
1310 <screen>
1311 *** Exception raised (reporting due to +RTS -xc), stack trace:
1312 GHC.List.CAF
1313 --> evaluated by: Main.polynomial.table_search,
1314 called from Main.polynomial.theta_index,
1315 called from Main.polynomial,
1316 called from Main.zonal_pressure,
1317 called from Main.make_pressure.p,
1318 called from Main.make_pressure,
1319 called from Main.compute_initial_state.p,
1320 called from Main.compute_initial_state,
1321 called from Main.CAF
1322 ...
1323 </screen>
1324 <para>The stack trace may often begin with something
1325 uninformative like <literal>GHC.List.CAF</literal>; this is
1326 an artifact of GHC's optimiser, which lifts out exceptions
1327 to the top-level where the profiling system assigns them to
1328 the cost centre "CAF". However, <literal>+RTS -xc</literal>
1329 doesn't just print the current stack, it looks deeper and
1330 reports the stack at the time the CAF was evaluated, and it
1331 may report further stacks until a non-CAF stack is found. In
1332 the example above, the next stack (after <literal>-->
1333 evaluated by</literal>) contains plenty of information about
1334 what the program was doing when it evaluated <literal>head
1335 []</literal>.</para>
1336
1337 <para>Implementation details aside, the function names in
1338 the stack should hopefully give you enough clues to track
1339 down the bug.</para>
1340
1341 <para>
1342 See also the function <literal>traceStack</literal> in the
1343 module <literal>Debug.Trace</literal> for another way to
1344 view call stacks.
1345 </para>
1346 </listitem>
1347 </varlistentry>
1348
1349 <varlistentry>
1350 <term>
1351 <option>-Z</option>
1352 <indexterm><primary><option>-Z</option></primary><secondary>RTS option</secondary></indexterm>
1353 </term>
1354 <listitem>
1355 <para>Turn <emphasis>off</emphasis> &ldquo;update-frame
1356 squeezing&rdquo; at garbage-collection time. (There's no
1357 particularly good reason to turn it off, except to ensure
1358 the accuracy of certain data collected regarding thunk entry
1359 counts.)</para>
1360 </listitem>
1361 </varlistentry>
1362 </variablelist>
1363
1364 </sect2>
1365
1366 <sect2 id="ghc-info">
1367 <title>Getting information about the RTS</title>
1368
1369 <indexterm><primary>RTS</primary></indexterm>
1370
1371 <para>It is possible to ask the RTS to give some information about
1372 itself. To do this, use the <option>--info</option> flag, e.g.</para>
1373 <screen>
1374 $ ./a.out +RTS --info
1375 [("GHC RTS", "YES")
1376 ,("GHC version", "6.7")
1377 ,("RTS way", "rts_p")
1378 ,("Host platform", "x86_64-unknown-linux")
1379 ,("Host architecture", "x86_64")
1380 ,("Host OS", "linux")
1381 ,("Host vendor", "unknown")
1382 ,("Build platform", "x86_64-unknown-linux")
1383 ,("Build architecture", "x86_64")
1384 ,("Build OS", "linux")
1385 ,("Build vendor", "unknown")
1386 ,("Target platform", "x86_64-unknown-linux")
1387 ,("Target architecture", "x86_64")
1388 ,("Target OS", "linux")
1389 ,("Target vendor", "unknown")
1390 ,("Word size", "64")
1391 ,("Compiler unregisterised", "NO")
1392 ,("Tables next to code", "YES")
1393 ]
1394 </screen>
1395 <para>The information is formatted such that it can be read as a
1396 of type <literal>[(String, String)]</literal>. Currently the following
1397 fields are present:</para>
1398
1399 <variablelist>
1400
1401 <varlistentry>
1402 <term><literal>GHC RTS</literal></term>
1403 <listitem>
1404 <para>Is this program linked against the GHC RTS? (always
1405 "YES").</para>
1406 </listitem>
1407 </varlistentry>
1408
1409 <varlistentry>
1410 <term><literal>GHC version</literal></term>
1411 <listitem>
1412 <para>The version of GHC used to compile this program.</para>
1413 </listitem>
1414 </varlistentry>
1415
1416 <varlistentry>
1417 <term><literal>RTS way</literal></term>
1418 <listitem>
1419 <para>The variant (&ldquo;way&rdquo;) of the runtime. The
1420 most common values are <literal>rts</literal> (vanilla),
1421 <literal>rts_thr</literal> (threaded runtime, i.e. linked using the
1422 <literal>-threaded</literal> option) and <literal>rts_p</literal>
1423 (profiling runtime, i.e. linked using the <literal>-prof</literal>
1424 option). Other variants include <literal>debug</literal>
1425 (linked using <literal>-debug</literal>),
1426 <literal>t</literal> (ticky-ticky profiling) and
1427 <literal>dyn</literal> (the RTS is
1428 linked in dynamically, i.e. a shared library, rather than statically
1429 linked into the executable itself). These can be combined,
1430 e.g. you might have <literal>rts_thr_debug_p</literal>.</para>
1431 </listitem>
1432 </varlistentry>
1433
1434 <varlistentry>
1435 <term>
1436 <literal>Target platform</literal>,
1437 <literal>Target architecture</literal>,
1438 <literal>Target OS</literal>,
1439 <literal>Target vendor</literal>
1440 </term>
1441 <listitem>
1442 <para>These are the platform the program is compiled to run on.</para>
1443 </listitem>
1444 </varlistentry>
1445
1446 <varlistentry>
1447 <term>
1448 <literal>Build platform</literal>,
1449 <literal>Build architecture</literal>,
1450 <literal>Build OS</literal>,
1451 <literal>Build vendor</literal>
1452 </term>
1453 <listitem>
1454 <para>These are the platform where the program was built
1455 on. (That is, the target platform of GHC itself.) Ordinarily
1456 this is identical to the target platform. (It could potentially
1457 be different if cross-compiling.)</para>
1458 </listitem>
1459 </varlistentry>
1460
1461 <varlistentry>
1462 <term>
1463 <literal>Host platform</literal>,
1464 <literal>Host architecture</literal>
1465 <literal>Host OS</literal>
1466 <literal>Host vendor</literal>
1467 </term>
1468 <listitem>
1469 <para>These are the platform where GHC itself was compiled.
1470 Again, this would normally be identical to the build and
1471 target platforms.</para>
1472 </listitem>
1473 </varlistentry>
1474
1475 <varlistentry>
1476 <term><literal>Word size</literal></term>
1477 <listitem>
1478 <para>Either <literal>"32"</literal> or <literal>"64"</literal>,
1479 reflecting the word size of the target platform.</para>
1480 </listitem>
1481 </varlistentry>
1482
1483 <varlistentry>
1484 <term><literal>Compiler unregistered</literal></term>
1485 <listitem>
1486 <para>Was this program compiled with an
1487 <link linkend="unreg">&ldquo;unregistered&rdquo;</link>
1488 version of GHC? (I.e., a version of GHC that has no platform-specific
1489 optimisations compiled in, usually because this is a currently
1490 unsupported platform.) This value will usually be no, unless you're
1491 using an experimental build of GHC.</para>
1492 </listitem>
1493 </varlistentry>
1494
1495 <varlistentry>
1496 <term><literal>Tables next to code</literal></term>
1497 <listitem>
1498 <para>Putting info tables directly next to entry code is a useful
1499 performance optimisation that is not available on all platforms.
1500 This field tells you whether the program has been compiled with
1501 this optimisation. (Usually yes, except on unusual platforms.)</para>
1502 </listitem>
1503 </varlistentry>
1504
1505 </variablelist>
1506
1507 </sect2>
1508 </sect1>
1509
1510 <!-- Emacs stuff:
1511 ;;; Local Variables: ***
1512 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***
1513 ;;; End: ***
1514 -->