diff options
| author | peb <unknown> | 2005-03-29 10:58:46 +0000 |
|---|---|---|
| committer | peb <unknown> | 2005-03-29 10:58:46 +0000 |
| commit | 2160e648dafaba3e1da7e44fd0fd06d93c2515b6 (patch) | |
| tree | 23974c2b66bd38b1ed84aa3d23e6416b5afdba8d /src/GF/System | |
| parent | 67aa6e7a81d8d22ff8409ed59fab7bacde2312a6 (diff) | |
"Committed_by_peb"
Diffstat (limited to 'src/GF/System')
| -rw-r--r-- | src/GF/System/Tracing.hs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/GF/System/Tracing.hs b/src/GF/System/Tracing.hs new file mode 100644 index 000000000..b092949e8 --- /dev/null +++ b/src/GF/System/Tracing.hs @@ -0,0 +1,63 @@ +{-# OPTIONS -cpp #-} +---------------------------------------------------------------------- +-- | +-- Maintainer : PL +-- Stability : (stable) +-- Portability : (portable) +-- +-- > CVS $Date: 2005/03/29 11:58:46 $ +-- > CVS $Author: peb $ +-- > CVS $Revision: 1.1 $ +-- +-- Tracing utilities for debugging purposes. +-- If the CPP symbol TRACING is set, then the debugging output is shown. +----------------------------------------------------------------------------- + + +module GF.System.Tracing (trace, trace2, traceDot, traceCall, tracePrt) where + +import qualified IOExts + +-- | emit a string inside braces, before(?) calculating the value: +-- @{str}@ +trace :: String -> a -> a + +-- | emit function name and debugging output: +-- @{fun: out}@ +trace2 :: String -> String -> a -> a + +-- | emit a dot before(?) calculating the value, for displaying progress +traceDot :: a -> a + +-- | show when a value is starting to be calculated (with a '+'), +-- and when it is finished (with a '-') +traceCall :: String -> String -> (a -> String) -> a -> a + +-- | showing the resulting value (filtered through a printing function): +-- @{fun: value}@ +tracePrt :: String -> (a -> String) -> a -> a + +#if TRACING +trace str a = IOExts.trace (bold ++ "{" ++ normal ++ str ++ bold ++ "}" ++ normal) a +trace2 fun str a = trace (bold ++ fgcol 1 ++ fun ++ ": " ++ normal ++ str) a +traceDot a = IOExts.unsafePerformIO (putStr ".") `seq` a +traceCall fun start prt val + = trace2 ("+" ++ fun) start $ + val `seq` trace2 ("-" ++ fun) (prt val) val +tracePrt mod prt val = val `seq` trace2 mod (prt val) val +#else +trace _ = id +trace2 _ _ = id +traceDot = id +traceCall _ _ _ = id +tracePrt _ _ = id +#endif + + +escape = "\ESC" +highlight = escape ++ "[7m" +bold = escape ++ "[1m" +underline = escape ++ "[4m" +normal = escape ++ "[0m" +fgcol col = escape ++ "[0" ++ show (30+col) ++ "m" +bgcol col = escape ++ "[0" ++ show (40+col) ++ "m" |
