Safe Haskell | None |
---|---|
Language | Haskell2010 |
Thread-safe Logging with bonus controlled-schedule debugging capabilities.
This module supports logging to memory, serializing messages and deferring the work of actually printing them. Another thread can flush the logged messages at its leisure.
The second capability of this infrastructure is to use the debugging print messages
as points at which to gate the execution of the program. That is, each logStrLn_
call becomes a place where the program blocks and checks in with a central
coordinator, which only allows one thread to unblock at a time. Thus, if there are
sufficient debug logging messages in the program, this can enable a form of
deterministic replay (and quickcheck-style testing of different interleavings).
- dbgLvl :: Int
- defaultMemDbgRange :: (Int, Int)
- newLogger :: (Int, Int) -> [OutDest] -> WaitMode -> IO Logger
- logOn :: Logger -> LogMsg -> IO ()
- data Logger
- data WaitMode
- = WaitDynamic
- | WaitNum {
- numThreads :: Int
- downThreads :: IO Int
- | DontWait
- data LogMsg
- mapMsg :: (String -> String) -> LogMsg -> LogMsg
- data OutDest
- forkWithExceptions :: (IO () -> IO ThreadId) -> String -> IO () -> IO ThreadId
- data Backoff
- newBackoff :: Int -> IO Backoff
- backoff :: Backoff -> IO Backoff
- data DbgCfg = DbgCfg {}
Global variables
Debugging flag shared by several modules.
This is activated by setting the environment variable DEBUG=1..5
.
By convention DEBUG=100
turns on full sequentialization of the program and
control over the interleavings in concurrent code, enabling systematic debugging
of concurrency problems.
defaultMemDbgRange :: (Int, Int) Source
New logger interface
:: (Int, Int) | What inclusive range of messages do we accept? Defaults to `(0,dbgLvl)`. |
-> [OutDest] | Where do we write debugging messages? |
-> WaitMode | Do we wait for workers before proceeding sequentially but randomly (fuzz testing event interleavings)? |
-> IO Logger |
Create a new logger, which includes forking a coordinator thread. Takes as argument the number of worker threads participating in the computation.
logOn :: Logger -> LogMsg -> IO () Source
Write a log message from the current thread, IF the level of the
message falls into the range accepted by the given Logger
,
otherwise, the message is ignored.
A Logger coordinates a set of threads that print debug logging messages.
This are abstract objects supporting only the operations provided by this module and the non-hidden fields of the Logger.
Several different ways we know to wait for quiescence in the concurrent mutator before proceeding.
WaitDynamic | UNFINISHED: Dynamically track tasks/workers. The
num workers starts at 1 and then is modified
with |
WaitNum | A fixed set of threads must check-in each round before proceeding. |
| |
DontWait | In this mode, logging calls are non-blocking and return immediately, rather than waiting on a central coordinator. This is what we want if we're simply printing debugging output, not controlling the schedule for stress testing. |
We allow logging in O(1) time in String or ByteString format. In practice the distinction is not that important, because only *thunks* should be logged; the thread printing the logs should deal with forcing those thunks.
StrMsg | |
OffTheRecord | This sort of message is chatter and NOT meant to participate in the scheduler-testing framework. | ByteStrMsg { lvl::Int, } |
A destination for log messages
OutputEvents | Output via GHC's |
OutputTo Handle | Printed human-readable output to a handle. |
OutputInMemory | Accumulate output in memory and flush when appropriate. |
General utilities
forkWithExceptions :: (IO () -> IO ThreadId) -> String -> IO () -> IO ThreadId Source
Exceptions that walk up the fork-tree of threads.
WARNING: By holding onto the ThreadId we keep the parent thread from being garbage collected (at least as of GHC 7.6). This means that even if it was complete, it will still be hanging around to accept the exception below.
Create an object used for exponentential backoff; see backoff
.
DebugConfig: what level of debugging support is activated?
DbgCfg | |
|