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