ghc-datasize 0.1 → 0.1.1
raw patch · 2 files changed
+17/−7 lines, 2 filesdep ~ghc-heap-viewPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: ghc-heap-view
API changes (from Hackage documentation)
Files
- ghc-datasize.cabal +3/−2
- src/GHC/DataSize.hs +14/−5
ghc-datasize.cabal view
@@ -1,5 +1,5 @@ name: ghc-datasize-version: 0.1+version: 0.1.1 license: BSD3 license-file: LICENSE category: GHC, Debug, Development@@ -21,7 +21,8 @@ Exposed-modules: GHC.DataSize Default-Language: Haskell2010 Build-depends: base == 4.*,- ghc-heap-view >= 0.3.0.3+ --containers,+ ghc-heap-view >= 0.5 Hs-source-dirs: src/ Ghc-options: -Wall
src/GHC/DataSize.hs view
@@ -7,6 +7,7 @@ module GHC.DataSize ( closureSize, recursiveSize+ --mSize ) where @@ -18,6 +19,11 @@ import System.Mem +--import qualified Data.IntMap as IntMap++--depth :: Int+--depth = 10^10+ -- Inspired by Simon Marlow: -- https://ghcmutterings.wordpress.com/2009/02/12/53/ @@ -41,18 +47,21 @@ -- @ -- recursiveSize $!! \"foobar\" -- @--- ($!! from Control.DeepSeq) to force full evaluation before calulating the size.+-- ($!! from Control.DeepSeq) to force full evaluation before calculating the+-- size. -- -- A garbage collection is performed before the size is calculated, because -- the garbage collector would make heap walks difficult.+ recursiveSize :: Num b => a -> IO b recursiveSize x = do performGC liftM snd $ go ([], 0) $ asBox x- where go (vs, acc) b@(Box y)- | b `elem` vs = return (vs, acc)- | otherwise = do+ where go (vs, acc) b@(Box y) = do+ isElem <- liftM or $ mapM (areBoxesEqual b) vs+ if isElem+ then return (vs, acc)+ else do size <- closureSize y closure <- getClosureData y- --putStrLn $ (show b) ++ " | " ++ (show closure) foldM go (b : vs, acc + size) $ allPtrs closure