Skip to content
Snippets Groups Projects

Add streaming support to GHC debug brick

Open Zubin requested to merge wip/streaming into master
9 files
+ 385
148
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -24,14 +24,12 @@ import Control.Monad.State
import GHC.Debug.Trace
import GHC.Debug.Types.Graph
import Control.Monad
import GHC.Debug.StreamedTrace
import qualified Data.Set as Set
import Control.Monad.RWS
import Data.Word
addOne :: a -> (Maybe Int, [a]) -> (Maybe Int, [a])
addOne _ (Just 0, cp) = (Just 0, cp)
addOne cp (n, cps) = (subtract 1 <$> n, cp : cps)
import Data.List.NonEmpty ( NonEmpty(..) )
data EraRange
= EraRange { startEra :: Word64, endEra :: Word64} -- inclusive
@@ -100,27 +98,27 @@ matchesFilter filter ptr sc parents = case filter of
findRetainersOf :: Maybe Int
-> [ClosurePtr]
-> [ClosurePtr]
-> DebugM [[ClosurePtr]]
-> DebugM (ResultStream (NonEmpty ClosurePtr) () (Maybe ()))
findRetainersOf limit cps bads =
findRetainers limit (AddressFilter (`Set.member` bad_set)) cps
where
bad_set = Set.fromList bads
findRetainersOfConstructor :: Maybe Int
-> [ClosurePtr] -> String -> DebugM [[ClosurePtr]]
-> [ClosurePtr] -> String -> DebugM (ResultStream (NonEmpty ClosurePtr) () (Maybe ()))
findRetainersOfConstructor limit rroots con_name =
findRetainers limit (ConstructorDescFilter ((== con_name) . name)) rroots
findRetainersOfConstructorExact
:: Maybe Int
-> [ClosurePtr] -> String -> DebugM [[ClosurePtr]]
-> [ClosurePtr] -> String -> DebugM (ResultStream (NonEmpty ClosurePtr) () (Maybe ()))
findRetainersOfConstructorExact limit rroots clos_name =
findRetainers limit (InfoSourceFilter ((== clos_name) . infoName)) rroots
findRetainersOfEra
:: Maybe Int
-> EraRange
-> [ClosurePtr] -> DebugM [[ClosurePtr]]
-> [ClosurePtr] -> DebugM (ResultStream (NonEmpty ClosurePtr) () (Maybe ()))
findRetainersOfEra limit eras rroots =
findRetainers limit filter rroots
where
@@ -128,7 +126,7 @@ findRetainersOfEra limit eras rroots =
findRetainersOfArrWords
:: Maybe Int
-> [ClosurePtr] -> Size -> DebugM [[ClosurePtr]]
-> [ClosurePtr] -> Size -> DebugM (ResultStream (NonEmpty ClosurePtr) () (Maybe ()))
findRetainersOfArrWords limit rroots lim =
findRetainers limit filter rroots
where
@@ -138,7 +136,7 @@ findRetainersOfArrWords limit rroots lim =
findRetainersOfInfoTable
:: Maybe Int
-> [ClosurePtr] -> InfoTablePtr -> DebugM [[ClosurePtr]]
-> [ClosurePtr] -> InfoTablePtr -> DebugM (ResultStream (NonEmpty ClosurePtr) () (Maybe ()))
findRetainersOfInfoTable limit rroots info_ptr =
findRetainers limit (InfoPtrFilter (== info_ptr)) rroots
@@ -148,28 +146,26 @@ findRetainersOfInfoTable limit rroots info_ptr =
-- such as 10.
findRetainers :: Maybe Int
-> ClosureFilter
-> [ClosurePtr] -> DebugM [[ClosurePtr]]
findRetainers limit filter rroots = (\(_, r, _) -> snd r) <$> runRWST (traceFromM funcs rroots) [] (limit, [])
-> [ClosurePtr] -> DebugM (ResultStream (NonEmpty ClosurePtr) () (Maybe ()))
findRetainers limit filter rroots = traceStreamResults rroots limit [] funcs
where
funcs = justClosures closAccum
funcs = justStreamClosures closAccum
-- Add clos
closAccum :: ClosurePtr
-> SizedClosure
-> RWST [ClosurePtr] () (Maybe Int, [[ClosurePtr]]) DebugM ()
-> RWST [ClosurePtr] () (Maybe Int, [[ClosurePtr]]) DebugM ()
closAccum _ (noSize -> WeakClosure {}) _ = return ()
closAccum cp sc k = do
ctx <- ask
b <- lift $ matchesFilter filter cp sc ctx
if b
then do
modify' (addOne (cp: ctx))
local (cp:) k
else do
(lim, _) <- get
case lim of
Just 0 -> return ()
_ -> local (cp:) k
-> Maybe Int
-> [ClosurePtr]
-> DebugM (Step (Maybe Int) [ClosurePtr] (NonEmpty ClosurePtr) ())
closAccum _ (noSize -> WeakClosure {}) l _ = return $ Step Nothing (Prune l)
closAccum cp sc remaining ctx
| Just r <- remaining
, r <= 0 = return $ Step Nothing (End ())
| otherwise = do
b <- matchesFilter filter cp sc ctx
let next = Continue (if b then (subtract 1 <$> remaining) else remaining) (cp:ctx)
if b
then return $ Step (Just (cp:|ctx)) next
else return $ Step Nothing next
addLocationToStack :: [ClosurePtr] -> DebugM [(SizedClosureP, Maybe SourceInformation)]
addLocationToStack r = do
Loading