Make event tracing conditional on an RTS flag only
The current event tracing mechanism is enabled at link time by linking in one of two different versions of a C function, one being a no-op function. We could allow users to enable/disable tracing using a RTS flag instead, making event logging more convenient to use. At the same time we would introduce tracing levels.
Add a static memory location where the current tracing level is stored:
uint tracelevel = 0;
GHC.Exts.traceEvent to read
foreign import ccall unsafe "&tracelevel" :: Ptr Word traceEvent :: String -> IO () traceEvent msg = if unsafePerformIO (peek tracelevel) > 0 then do withCString msg $ \(Ptr p) -> IO $ \s -> case traceEvent# p s of s' -> (# s', () #) else return ()
and (optionally) add some more functions that log at different trace levels.
This should be no slower than the current system. With inlining this should result in a load and a branch at the call site. The load should be cheap as the value is likely to be in cache (as it never changes). The branch should be easy to predict as it's always the same. With some cooperation from the code generator we could make sure that the branch is always cheap.