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