<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Debug.Trace</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_Debug-Trace.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">base-4.5.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Stability</th><td>provisional</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr><tr><th>Safe Haskell</th><td>Unsafe</td></tr></table><p class="caption">Debug.Trace</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Tracing </a></li><li><a href="#g:2">Eventlog tracing </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Functions for tracing and monitoring execution. </p><p>These can be useful for investigating bugs or performance problems. They should <em>not</em> be used in production code. </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:trace">trace</a> :: <a href="Data-String.html#t:String">String</a> -> a -> a</li><li class="src short"><a href="#v:traceShow">traceShow</a> :: <a href="Text-Show.html#t:Show">Show</a> a => a -> b -> b</li><li class="src short"><a href="#v:traceStack">traceStack</a> :: <a href="Data-String.html#t:String">String</a> -> a -> a</li><li class="src short"><a href="#v:traceIO">traceIO</a> :: <a href="Data-String.html#t:String">String</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:putTraceMsg">putTraceMsg</a> :: <a href="Data-String.html#t:String">String</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:traceEvent">traceEvent</a> :: <a href="Data-String.html#t:String">String</a> -> a -> a</li><li class="src short"><a href="#v:traceEventIO">traceEventIO</a> :: <a href="Data-String.html#t:String">String</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li></ul></div><div id="interface"><h1 id="g:1">Tracing </h1><div class="doc"><p>The <code><a href="Debug-Trace.html#v:trace">trace</a></code>, <code><a href="Debug-Trace.html#v:traceShow">traceShow</a></code> and <code><a href="Debug-Trace.html#v:traceIO">traceIO</a></code> functions print messages to an output stream. They are intended for "printf debugging", that is: tracing the flow of execution and printing interesting values. </p></div><div class="top"><p class="src"><a name="v:trace" class="def">trace</a> :: <a href="Data-String.html#t:String">String</a> -> a -> a</p><div class="doc"><p>The <code><a href="Debug-Trace.html#v:trace">trace</a></code> function outputs the trace message given as its first argument, before returning the second argument as its result. </p><p>For example, this returns the value of <code>f x</code> but first outputs the message. </p><pre> trace ("calling f with x = " ++ show x) (f x) </pre><p>The <code><a href="Debug-Trace.html#v:trace">trace</a></code> function should <em>only</em> be used for debugging, or for monitoring execution. The function is not referentially transparent: its type indicates that it is a pure function but it has the side effect of outputting the trace message. </p></div></div><div class="top"><p class="src"><a name="v:traceShow" class="def">traceShow</a> :: <a href="Text-Show.html#t:Show">Show</a> a => a -> b -> b</p><div class="doc"><p>Like <code><a href="Debug-Trace.html#v:trace">trace</a></code>, but uses <code><a href="Text-Show.html#v:show">show</a></code> on the argument to convert it to a <code><a href="Data-String.html#t:String">String</a></code>. </p><p>This makes it convenient for printing the values of interesting variables or expressions inside a function. For example here we print the value of the variables <code>x</code> and <code>z</code>: </p><pre> f x y = traceShow (x, z) $ result where z = ... ... </pre></div></div><div class="top"><p class="src"><a name="v:traceStack" class="def">traceStack</a> :: <a href="Data-String.html#t:String">String</a> -> a -> a</p><div class="doc"><p>like <code><a href="Debug-Trace.html#v:trace">trace</a></code>, but additionally prints a call stack if one is available. </p><p>In the current GHC implementation, the call stack is only availble if the program was compiled with <code>-prof</code>; otherwise <code><a href="Debug-Trace.html#v:traceStack">traceStack</a></code> behaves exactly like <code><a href="Debug-Trace.html#v:trace">trace</a></code>. Entries in the call stack correspond to <code>SCC</code> annotations, so it is a good idea to use <code>-fprof-auto</code> or <code>-fprof-auto-calls</code> to add SCC annotations automatically. </p></div></div><div class="top"><p class="src"><a name="v:traceIO" class="def">traceIO</a> :: <a href="Data-String.html#t:String">String</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The <code><a href="Debug-Trace.html#v:traceIO">traceIO</a></code> function outputs the trace message from the IO monad. This sequences the output with respect to other IO actions. </p></div></div><div class="top"><p class="src"><a name="v:putTraceMsg" class="def">putTraceMsg</a> :: <a href="Data-String.html#t:String">String</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><div class="warning"><p>Deprecated: Use Debug.Trace.traceIO</p></div><p>Deprecated. Use <code><a href="Debug-Trace.html#v:traceIO">traceIO</a></code>. </p></div></div><h1 id="g:2">Eventlog tracing </h1><div class="doc"><p>Eventlog tracing is a performance profiling system. These functions emit extra events into the eventlog. In combination with eventlog profiling tools these functions can be used for monitoring execution and investigating performance problems. </p><p>Currently only GHC provides eventlog profiling, see the GHC user guide for details on how to use it. These function exists for other Haskell implementations but no events are emitted. Note that the string message is always evaluated, whether or not profiling is available or enabled. </p></div><div class="top"><p class="src"><a name="v:traceEvent" class="def">traceEvent</a> :: <a href="Data-String.html#t:String">String</a> -> a -> a</p><div class="doc"><p>The <code><a href="Debug-Trace.html#v:traceEvent">traceEvent</a></code> function behaves like <code><a href="Debug-Trace.html#v:trace">trace</a></code> with the difference that the message is emitted to the eventlog, if eventlog profiling is available and enabled at runtime. </p><p>It is suitable for use in pure code. In an IO context use <code><a href="Debug-Trace.html#v:traceEventIO">traceEventIO</a></code> instead. </p><p>Note that when using GHC's SMP runtime, it is possible (but rare) to get duplicate events emitted if two CPUs simultaneously evaluate the same thunk that uses <code><a href="Debug-Trace.html#v:traceEvent">traceEvent</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:traceEventIO" class="def">traceEventIO</a> :: <a href="Data-String.html#t:String">String</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The <code><a href="Debug-Trace.html#v:traceEventIO">traceEventIO</a></code> function emits a message to the eventlog, if eventlog profiling is available and enabled at runtime. </p><p>Compared to <code><a href="Debug-Trace.html#v:traceEvent">traceEvent</a></code>, <code><a href="Debug-Trace.html#v:traceEventIO">traceEventIO</a></code> sequences the event with respect to other IO actions. </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>