Functions for tracing and monitoring execution.
These can be useful for investigating bugs or performance problems. They should not be used in production code.
trace function outputs the trace message given as its first argument,
before returning the second argument as its result.
For example, this returns the value of
f x but first outputs the message.
trace ("calling f with x = " ++ show x) (f x)
trace function should only 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, but additionally prints a call stack if one is
In the current GHC implementation, the call stack is only
availble if the program was compiled with
traceStack behaves exactly like
trace. Entries in the call
stack correspond to
SCC annotations, so it is a good idea to use
-fprof-auto-calls to add SCC annotations automatically.
traceIO function outputs the trace message from the IO monad.
This sequences the output with respect to other IO actions.
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.
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.
It is suitable for use in pure code. In an IO context use
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