Copyright | (C) 2014-2015 Ryan Scott |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Ryan Scott |
Stability | Provisional |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Functions for tracing and monitoring execution.
These can be useful for investigating bugs or performance problems. They should not be used in production code.
If you do not wish to require TextShow
instances for your trace
functions,
the TextShow.Debug.Trace.TH and Text.Show.Text.Debug.Trace.Generic modules
exist to convert the input to a debug message using Template Haskell or generics,
respectively.
Since: 2
- tracet :: Text -> a -> a
- tracetl :: Text -> a -> a
- tracetId :: Text -> Text
- tracetlId :: Text -> Text
- traceTextShow :: TextShow a => a -> b -> b
- traceTextShowId :: TextShow a => a -> a
- tracetStack :: Text -> a -> a
- tracetlStack :: Text -> a -> a
- tracetIO :: Text -> IO ()
- tracetlIO :: Text -> IO ()
- tracetM :: Applicative f => Text -> f ()
- tracetlM :: Applicative f => Text -> f ()
- traceTextShowM :: (TextShow a, Applicative f) => a -> f ()
- tracetEvent :: Text -> a -> a
- tracetlEvent :: Text -> a -> a
- tracetEventIO :: Text -> IO ()
- tracetlEventIO :: Text -> IO ()
- tracetMarker :: Text -> a -> a
- tracetlMarker :: Text -> a -> a
- tracetMarkerIO :: Text -> IO ()
- tracetlMarkerIO :: Text -> IO ()
Tracing
The tracet(l)
, traceTextShow
and tracet(l)IO
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 is stderr
. 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 Text
that's
output to indicate that you're tracing.
tracet :: Text -> a -> a Source
The tracet
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.
tracet ("calling f with x = " <> showt x) (f x)
The tracet
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 message.
Since: 2
tracetId :: Text -> Text Source
Like tracet
but returns the message instead of a third value.
Since: 2
traceTextShow :: TextShow a => a -> b -> b Source
Like tracet
, but uses showt
on the argument to convert it to a Text
.
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 x
and z
:
f x y = traceTextShow (x, z) $ result where z = ... ...
Since: 2
traceTextShowId :: TextShow a => a -> a Source
Like traceTextShow
but returns the shown value instead of a third value.
Since: 2
tracetStack :: Text -> a -> a Source
Like tracet
but additionally prints a call stack if one is
available.
In the current GHC implementation, the call stack is only
availble if the program was compiled with -prof
; otherwise
tracetStack
behaves exactly like tracet
. Entries in the call
stack correspond to SCC
annotations, so it is a good idea to use
-fprof-auto
or -fprof-auto-calls
to add SCC annotations automatically.
Since: 2
tracetlStack :: Text -> a -> a Source
Like tracetStack
but accepts a lazy Text
argument.
Since: 2
tracetIO :: Text -> IO () Source
The tracetIO
function outputs the trace message from the IO monad.
This sequences the output with respect to other IO actions.
Since: 2
tracetM :: Applicative f => Text -> f () Source
Like tracet
but returning unit in an arbitrary Applicative
context. Allows for
convenient use in do-notation. Note that the application of tracet
is not an action
in the Applicative
context, as tracetIO
is in the IO
type.
... = do x <- ... tracetM $ "x: " <> showt x y <- ... tracetM $ "y: " <> showt y
Since: 2
traceTextShowM :: (TextShow a, Applicative f) => a -> f () Source
Eventlog tracing
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 Text
message is
always evaluated, whether or not profiling is available or enabled.
tracetEvent :: Text -> a -> a Source
The tracetEvent
function behaves like tracet
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 use tracetEventIO
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 uses traceEvent
.
Since: 2
tracetlEvent :: Text -> a -> a Source
Like tracetEvent
but accepts a lazy Text
argument.
Since: 2
tracetEventIO :: Text -> IO () Source
The tracetEventIO
function emits a message to the eventlog, if eventlog
profiling is available and enabled at runtime.
Compared to tracetEvent
, tracetEventIO
sequences the event with respect to
other IO actions.
Since: 2
tracetlEventIO :: Text -> IO () Source
Like tracetEventIO
but accepts a lazy Text
argument.
Since: 2
Execution phase markers
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.
tracetMarker :: Text -> a -> a Source
The tracetMarker
function emits a marker to the eventlog, if eventlog
profiling is available and enabled at runtime. The Text
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 use
tracetMarkerIO
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 uses traceMarker
.
Since: 2
tracetlMarker :: Text -> a -> a Source
Like tracetMarker
but accepts a lazy Text
argument.
Since: 2
tracetMarkerIO :: Text -> IO () Source
The tracetMarkerIO
function emits a marker to the eventlog, if eventlog
profiling is available and enabled at runtime.
Compared to tracetMarker
, tracetMarkerIO
sequences the event with respect to
other IO actions.
Since: 2
tracetlMarkerIO :: Text -> IO () Source
Like tracetMarkerIO
but accepts a lazy Text
argument.
Since: 2