Skip to content

Instantly share code, notes, and snippets.

@zyklotomic
Created April 1, 2021 17:45
Show Gist options
  • Save zyklotomic/86e8f4b0905a88e8b591a4514c645080 to your computer and use it in GitHub Desktop.
Save zyklotomic/86e8f4b0905a88e8b591a4514c645080 to your computer and use it in GitHub Desktop.
ghc-debug socket failure, while trying to make a snapshot
main = withDebuggeeConnect "/tmp/ghc-debug" $ mainToDebug
--
--main = snapshotRun "/tmp/ghc-debug-cache" p37
mainToDebug :: Debuggee -> IO ()
mainToDebug d = do
n <- read . head <$> getArgs
-- Allocate lots of BS
let !superset = force $ take n [BS.singleton x | x <- cycle [minBound..maxBound]]
putStrLn "1st plateau start"
spin 3
makeSnapshot d "/tmp/ghc-debug-snapshot"
-- Extract only a small subset, every 10
let subsetFactor = 10 :: Int
let !subset = force $ [x | (x, 1) <- zip superset (cycle [1..subsetFactor])]
putStrLn "2nd Plateau start"
spin (3 * subsetFactor)
-- Stop subset from being GC by using it here
print (length subset)
spin :: Int -> IO ()
spin i = forM_ [1..i] (\_ -> threadDelay 1 >> performGC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment