Display pre-emptions following a yield with a lower-case "p"

Fixes #109
This commit is contained in:
Michael Walker 2017-11-26 22:22:54 +00:00
parent e9a64a1f8d
commit c88ec04ec2
2 changed files with 11 additions and 5 deletions

View File

@ -13,6 +13,7 @@ unreleased
### Test.DejaFu.Common
- Fix some incorrect "@since" haddock comments.
- Pretty-printed traces now display a pre-emption following a yield with a little "p".
### Test.DejaFu.Conc

View File

@ -815,15 +815,20 @@ instance NFData Decision where
-- @since 0.5.0.0
showTrace :: Trace -> String
showTrace [] = "<trace discarded>"
showTrace trc = intercalate "\n" $ concatMap go trc : strkey where
go (_,_,CommitCRef _ _) = "C-"
go (Start (ThreadId _ i),_,_) = "S" ++ show i ++ "-"
go (SwitchTo (ThreadId _ i),_,_) = "P" ++ show i ++ "-"
go (Continue,_,_) = "-"
showTrace trc = intercalate "\n" $ go False trc : strkey where
go _ ((_,_,CommitCRef _ _):rest) = "C-" ++ go False rest
go _ ((Start (ThreadId _ i),_,a):rest) = "S" ++ show i ++ "-" ++ go (didYield a) rest
go y ((SwitchTo (ThreadId _ i),_,a):rest) = (if y then "p" else "P") ++ show i ++ "-" ++ go (didYield a) rest
go _ ((Continue,_,a):rest) = '-' : go (didYield a) rest
go _ _ = ""
strkey =
[" " ++ show i ++ ": " ++ name | (i, name) <- threadNames trc]
didYield Yield = True
didYield (ThreadDelay _) = True
didYield _ = False
-- | Get all named threads in the trace.
--
-- @since 0.7.3.0