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