ghc-heap-view
ghc-heap-view copied to clipboard
How can I use ghc-heap-view to observe the thunk evaluation process.
For example, I've written this code trying to observe evaluation process of foldr and foldl, but it end up to a dead loop. Maybe it's because buildHeapGraph a
would trigger evaluation of a? Is what I want possible with ghc-heap-view ?
https://gist.github.com/yihuang/f24675aee03c99cd4a6c
What version of GHC are you on?
Ah, judging from your imports, 7.10 :-). The program is better tested on older GHCs, I’ll see if that works better.
Your observe
returns a
, and then you seq
it. That’s your loop. Try
observe :: a -> b -> b
observe a b = unsafePerformIO $ do
performGC
s <- ppHeapGraph <$> buildHeapGraph 1000 () (asBox a)
putStrLn s
return b
{-# NOINLINE observe #-}
and
foldr f z l = result
where
result = loop f z l
loop f z [] = observe result z
loop f z (x:xs) = observe result (x `f` loop f z xs)
Now it does not loop, but it’s not very helpful either:
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
_ind (_bh _unsupported)
Maybe the value is on the stack, which is not well-supported by ghc-heap-view
?