Skip to content

Commit 952dcbc

Browse files
committed
EventDuration: Make it more robust to truncated eventlogs
Previously this would throw an exception in the (not uncommon) case of a truncated eventlog. Now we simply declare the thread to stop running at the time of the last event that we saw.
1 parent d333922 commit 952dcbc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Events/EventDuration.hs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,20 @@ eventsToDurations :: [GHC.Event] -> [EventDuration]
8787
eventsToDurations [] = []
8888
eventsToDurations (event : events) =
8989
case evSpec event of
90-
RunThread{thread=t} -> runDuration t : rest
90+
RunThread{thread=t}
91+
| Just ev <- runDuration t -> ev : rest
92+
| otherwise -> rest
9193
StopThread{} -> rest
9294
StartGC -> gcStart (evTime event) events
9395
EndGC{} -> rest
9496
_otherEvent -> rest
9597
where
9698
rest = eventsToDurations events
9799

98-
runDuration t = ThreadRun t s (evTime event) endTime
99-
where (endTime, s) = case findRunThreadTime events of
100-
Nothing -> error $ "findRunThreadTime for " ++ (show event)
101-
Just x -> x
100+
runDuration :: ThreadId -> Maybe EventDuration
101+
runDuration t = do
102+
(endTime, s) <- findRunThreadTime events
103+
return $ ThreadRun t s (evTime event) endTime
102104

103105
isDiscreteEvent :: GHC.Event -> Bool
104106
isDiscreteEvent e =
@@ -172,6 +174,11 @@ findRunThreadTime [] = Nothing
172174
findRunThreadTime (e : es)
173175
= case evSpec e of
174176
StopThread{status=s} -> Just (evTime e, s)
175-
_ -> findRunThreadTime es
177+
_ | [] <- es -> do
178+
hPutStrLn stderr "warning: failed to find stop event for thread; eventlog truncated?"
179+
return $ Just (evTime e, NoStatus)
180+
-- the eventlog abruptly ended; presumably the
181+
-- thread was still running.
182+
| otherwise -> findRunThreadTime es
176183

177184
-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)