Mikan
Safe HaskellNone
LanguageHaskell2010

Mikan.Utils.Trace

Description

Utilities for tracing to the eventlog.

These functions should be preferred over Debug.Trace.

Synopsis

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.

The easiest way to enable the eventlog is to pass +RTS -l-au -RTS to mikan. The GHC Manual provides documentation on further options.

traceEventIO :: MonadIO m => Text -> m () Source #

\(\mathcal{O}(n)\). Log a UserMessage event to the eventlog. The input Text is marshalled to a null-terminated CString.

This function does not force the Text if the eventlog is disabled.

Precondition: the string should be shorter than \(2^{16}\) bytes.

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.

For example, a program might have several distinct phases with different performance or resource behaviour in each phase. To properly interpret the profile graph we really want to see when each phase starts and ends.

Markers let us do this: we can annotate the program to emit a marker at an appropriate point during execution and then see that in a profile.

traceMarkerIO :: MonadIO m => Text -> m () Source #

\(\mathcal{O}(n)\). Emit a marker to the eventlog. The input Text is marshalled to a null-terminated CString.

This function does not force the Text if the eventlog is disabled.

Precondition: the string should be shorter than \(2^{16}\) bytes.

Era profiling

Era profiling lets us mark each closure with an era that tracks when the closure was allocated. It can be enabled by passing +RTS -he -RTS to a profiled build of mikan.

There are two ways to control the current era:

  1. Automatically via +RTS --automatic-era-increment -RTS, which increments the era on every major GC.
  2. Manually via setUserEra, incrementUserEra_, and incrementUserEra.

getUserEra :: MonadIO m => m Word Source #

Get the user era count if heap profiling is enabled.

If heap profiling is disabled, this function will always return 0.

setUserEra :: MonadIO m => Word -> m () Source #

Set the user era count if heap profiling is enabled.

If heap profiling is disabled, this function is a no-op.

incrementUserEra :: MonadIO m => Word -> m Word Source #

Increment the user era count if heap profiling is enabled, and return the new era.

If heap profiling is disabled, this function will always return 0.

incrementUserEra_ :: MonadIO m => Word -> m () Source #

Increment the user era count if heap profiling is enabled.

If heap profiling is disabled, this function will always return 0.