| Copyright | (c) The University of Glasgow 2001 |
|---|---|
| License | BSD-style (see the file libraries/base/LICENSE) |
| Maintainer | libraries@haskell.org |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Unsafe |
| Language | Haskell2010 |
Debug.Trace
Description
Functions for tracing and monitoring execution.
These can be useful for investigating bugs or performance problems. They shouldnot be used in production code.
Thetrace,traceShow andtraceIO functions print messages to an output stream. They are intended for "printf debugging", that is: tracing the flow of execution and printing interesting values.
All these functions evaluate the message completely before printing it; so if the message is not fully defined, none of it will be printed.
The usual output stream isstderr. For Windows GUI applications (that have no stderr) the output is directed to the Windows debug console. Some implementations of these functions may decorate the string that's output to indicate that you're tracing.
trace ::String -> a -> aSource#
Thetrace function outputs the trace message given as its first argument,before returning the second argument as its result.
For example, this returns the value off x but first outputs the message.
>>>let x = 123; f = show>>>trace ("calling f with x = " ++ show x) (f x)"calling f with x = 123123"
Thetrace function shouldonly be used for debugging, or for monitoringexecution. The function is not referentially transparent: its type indicatesthat it is a pure function but it has the side effect of outputting thetrace message.
traceId ::String ->StringSource#
Liketrace but returns the message instead of a third value.
>>>traceId "hello""hellohello"
Since: 4.7.0.0
traceShowId ::Show a => a -> aSource#
LiketraceShow but returns the shown value instead of a third value.
>>>traceShowId (1+2+3, "hello" ++ "world")(6,"helloworld")(6,"helloworld")
Since: 4.7.0.0
traceStack ::String -> a -> aSource#
liketrace, but additionally prints a call stack if one is available.
In the current GHC implementation, the call stack is only available if the program was compiled with-prof; otherwisetraceStack behaves exactly liketrace. Entries in the call stack correspond toSCC annotations, so it is a good idea to use-fprof-auto or-fprof-auto-calls to add SCC annotations automatically.
Since: 4.5.0.0
traceIO ::String ->IO ()Source#
ThetraceIO function outputs the trace message from the IO monad. This sequences the output with respect to other IO actions.
Since: 4.5.0.0
traceM ::Applicative f =>String -> f ()Source#
Liketrace but returning unit in an arbitraryApplicative context. Allowsfor convenient use in do-notation.
Note that the application oftraceM is not an action in theApplicativecontext, astraceIO is in theIO type. While the fresh bindings in thefollowing example will force thetraceM expressions to be reduced every timethedo-block is executed,traceM "not crashed" would only be reduced once,and the message would only be printed once. If your monad is inMonadIO,liftIO . traceIO may be a better option.
>>>:{do x <- Just 3 traceM ("x: " ++ show x) y <- pure 12 traceM ("y: " ++ show y) pure (x*2 + y):}x: 3y: 12Just 18
Since: 4.7.0.0
traceShowM :: (Show a,Applicative f) => a -> f ()Source#
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.
traceEvent ::String -> a -> aSource#
ThetraceEvent function behaves liketrace with the difference that the message is emitted to the eventlog, if eventlog profiling is available and enabled at runtime.
It is suitable for use in pure code. In an IO context usetraceEventIO instead.
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 usestraceEvent.
Since: 4.5.0.0
traceEventIO ::String ->IO ()Source#
ThetraceEventIO function emits a message to the eventlog, if eventlog profiling is available and enabled at runtime.
Compared totraceEvent,traceEventIO sequences the event with respect to other IO actions.
Since: 4.5.0.0
When looking at a profile for the execution of a program we often want to be able to mark certain points or phases in the execution and see that visually in the profile.
traceMarker ::String -> a -> aSource#
ThetraceMarker function emits a marker to the eventlog, if eventlog profiling is available and enabled at runtime. TheString is the name of the marker. The name is just used in the profiling tools to help you keep clear which marker is which.
This function is suitable for use in pure code. In an IO context usetraceMarkerIO instead.
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 usestraceMarker.
Since: 4.7.0.0
traceMarkerIO ::String ->IO ()Source#
ThetraceMarkerIO function emits a marker to the eventlog, if eventlog profiling is available and enabled at runtime.
Compared totraceMarker,traceMarkerIO sequences the event with respect to other IO actions.
Since: 4.7.0.0
Produced byHaddock version 2.20.0