Skip to content

Commit 7eac27c

Browse files
committed
io-sim-por: added EventRaces
This is only useful for debugging `IOSimPOR` issues.
1 parent 42fc797 commit 7eac27c

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

io-sim/src/Control/Monad/IOSim.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ detachTraceRacesST trace0 = do
176176

177177
go :: SimTrace a -> ST s (SimTrace a)
178178
go (SimTrace a b c d trace) = SimTrace a b c d <$> go trace
179+
go (SimPORTrace _ _ _ _ EventRaces {} trace)
180+
= go trace
179181
go (SimPORTrace a b c d e trace) = SimPORTrace a b c d e <$> go trace
180182
go (TraceRacesFound rs trace) = saveRaces rs >> go trace
181183
go t = return t

io-sim/src/Control/Monad/IOSim/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,9 @@ data SimEventType
10251025
| EventEffect VectorClock Effect
10261026
-- ^ /IOSimPOR/ event: executed effect; Useful for debugging IOSimPOR or
10271027
-- showing compact information about thread execution.
1028+
| EventRaces Races
1029+
-- ^ /IOSimPOR/ event: races. Races are updated while we execute
1030+
-- a simulation. Useful for debugging IOSimPOR.
10281031
deriving Show
10291032

10301033

io-sim/src/Control/Monad/IOSimPOR/Internal.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ schedule thread@Thread{
384384
timers = timers'' }
385385
return (SimPORTrace time tid tstep tlbl (EventThrow e) $
386386
SimPORTrace time tid tstep tlbl (EventMask maskst') $
387-
SimPORTrace time tid tstep tlbl (EventEffect vClock eff)
387+
SimPORTrace time tid tstep tlbl (EventEffect vClock eff) $
388+
SimPORTrace time tid tstep tlbl (EventRaces races')
388389
trace)
389390

390391
(Left isMain, timers'')
@@ -829,7 +830,8 @@ deschedule Yield thread@Thread { threadId = tid,
829830
control' = advanceControl (threadStepId thread) control
830831
races' = updateRaces thread simstate in
831832

832-
SimPORTrace time tid tstep tlbl (EventEffect vClock eff) <$>
833+
SimPORTrace time tid tstep tlbl (EventEffect vClock eff) .
834+
SimPORTrace time tid tstep tlbl (EventRaces races') <$>
833835
reschedule simstate { runqueue = runqueue',
834836
threads = threads',
835837
races = races',
@@ -879,7 +881,8 @@ deschedule Interruptable thread@Thread{threadId = tid,
879881
let (thread', eff) = stepThread thread
880882
races' = updateRaces thread simstate in
881883

882-
SimPORTrace time tid tstep tlbl (EventEffect vClock eff) <$>
884+
SimPORTrace time tid tstep tlbl (EventEffect vClock eff) .
885+
SimPORTrace time tid tstep tlbl (EventRaces races') <$>
883886
schedule thread'
884887
simstate{ races = races',
885888
control = advanceControl (threadStepId thread) control }
@@ -907,7 +910,8 @@ deschedule (Blocked blockedReason) thread@Thread{ threadId = tid,
907910
threads' = Map.insert (threadId thread') thread' threads
908911
races' = updateRaces thread1 simstate in
909912

910-
SimPORTrace time tid tstep tlbl (EventEffect vClock eff) <$>
913+
SimPORTrace time tid tstep tlbl (EventEffect vClock eff) .
914+
SimPORTrace time tid tstep tlbl (EventRaces races') <$>
911915
reschedule simstate { threads = threads',
912916
races = races',
913917
control = advanceControl (threadStepId thread1) control }
@@ -934,10 +938,11 @@ deschedule Terminated thread@Thread { threadId = tid, threadLabel = tlbl, thread
934938
[ (time, tid', (-1), tlbl', EventThrowToWakeup)
935939
| tid' <- unblocked
936940
, let tlbl' = lookupThreadLabel tid' threads ]
937-
$ SimPORTrace time tid (threadStep thread) tlbl (EventEffect vClock eff)
941+
$ SimPORTrace time tid tstep tlbl (EventEffect vClock eff)
942+
$ SimPORTrace time tid tstep tlbl (EventRaces races')
938943
trace
939944

940-
deschedule Sleep thread@Thread { threadId = tid , threadEffect = effect }
945+
deschedule Sleep thread@Thread { threadId = tid , threadEffect = effect' }
941946
simstate@SimState{runqueue, threads} =
942947

943948
-- Schedule control says we should run a different thread. Put

0 commit comments

Comments
 (0)