packages feed

weigh 0.0.14 → 0.0.15

raw patch · 4 files changed

+30/−50 lines, 4 filesdep +ghc

Dependencies added: ghc

Files

CHANGELOG view
@@ -1,3 +1,6 @@+0.0.15:+	* Fix bug in treating words as int, use only Word as reported by GHC.+ 0.0.14: 	* Use the correct data source for final live bytes total 
src/Weigh.hs view
@@ -76,11 +76,11 @@ import Control.DeepSeq import Control.Monad.State import qualified Data.Foldable as Foldable-import qualified Data.Traversable as Traversable-import Data.Int import qualified Data.List as List import Data.List.Split import Data.Maybe+import qualified Data.Traversable as Traversable+import Data.Word import GHC.Generics import Prelude import System.Environment@@ -117,10 +117,10 @@ -- | How much a computation weighed in at. data Weight =   Weight {weightLabel :: !String-         ,weightAllocatedBytes :: !Int64-         ,weightGCs :: !Int64-         ,weightLiveBytes :: !Int64-         ,weightMaxBytes :: !Int64+         ,weightAllocatedBytes :: !Word64+         ,weightGCs :: !Word32+         ,weightLiveBytes :: !Word64+         ,weightMaxBytes :: !Word64          }   deriving (Read,Show) @@ -255,7 +255,7 @@ action name !m = io name (const m) ()  -- | Make a validator that set sthe maximum allocations.-maxAllocs :: Int64 -- ^ The upper bound.+maxAllocs :: Word64 -- ^ The upper bound.           -> (Weight -> Maybe String) maxAllocs n =   \w ->@@ -380,7 +380,7 @@   :: (NFData a)   => (b -> a)         -- ^ A function whose memory use we want to measure.   -> b                -- ^ Argument to the function. Doesn't have to be forced.-  -> IO (Int64,Int64,Int64,Int64) -- ^ Bytes allocated and garbage collections.+  -> IO (Word64,Word32,Word64,Word64) -- ^ Bytes allocated and garbage collections. weighFunc run !arg = snd <$> weighFuncResult run arg  -- | Weigh a pure function and return the result. This function is heavily@@ -389,7 +389,7 @@   :: (NFData a)   => (b -> a)         -- ^ A function whose memory use we want to measure.   -> b                -- ^ Argument to the function. Doesn't have to be forced.-  -> IO (a, (Int64,Int64,Int64,Int64)) -- ^ Result, Bytes allocated, GCs.+  -> IO (a, (Word64,Word32,Word64,Word64)) -- ^ Result, Bytes allocated, GCs. weighFuncResult run !arg = do   ghcStatsSizeInBytes <- GHCStats.getGhcStatsSizeInBytes   performGC@@ -404,30 +404,30 @@   !actionStats <- GHCStats.getStats   let reflectionGCs = 1 -- We performed an additional GC.       actionBytes =-        (GHCStats.totalBytesAllocated actionStats --         GHCStats.totalBytesAllocated bootupStats) -+        (GHCStats.totalBytesAllocated actionStats `subtracting`+         GHCStats.totalBytesAllocated bootupStats) `subtracting`            -- We subtract the size of "bootupStats", which will be            -- included after we did the performGC.         fromIntegral ghcStatsSizeInBytes       actionGCs =-        GHCStats.gcCount actionStats - GHCStats.gcCount bootupStats -+        GHCStats.gcCount actionStats `subtracting` GHCStats.gcCount bootupStats `subtracting`         reflectionGCs          -- If overheadBytes is too large, we conservatively just          -- return zero. It's not perfect, but this library is for          -- measuring large quantities anyway.       actualBytes = max 0 actionBytes       liveBytes =-        max 0 (GHCStats.liveBytes actionStats - GHCStats.liveBytes bootupStats)+        (GHCStats.liveBytes actionStats `subtracting`+         GHCStats.liveBytes bootupStats)       maxBytes =-        max-          0-          (GHCStats.maxBytesInUse actionStats --           GHCStats.maxBytesInUse bootupStats)-  return (result,-    ( fromIntegral actualBytes-    , fromIntegral actionGCs-    , fromIntegral liveBytes-    , fromIntegral maxBytes))+        (GHCStats.maxBytesInUse actionStats `subtracting`+         GHCStats.maxBytesInUse bootupStats)+  return (result, (actualBytes, actionGCs, liveBytes, maxBytes))+  where+    subtracting x y =+      if x > y+        then x - y+        else 0  -- | Weigh an IO action. This function is based on `weighActionResult`, which is --   heavily documented inside.@@ -435,7 +435,7 @@   :: (NFData a)   => (b -> IO a)      -- ^ A function whose memory use we want to measure.   -> b                -- ^ Argument to the function. Doesn't have to be forced.-  -> IO (Int64,Int64,Int64,Int64) -- ^ Bytes allocated and garbage collections.+  -> IO (Word64,Word32,Word64,Word64) -- ^ Bytes allocated and garbage collections. weighAction run !arg = snd <$> weighActionResult run arg  -- | Weigh an IO action, and return the result. This function is heavily@@ -444,7 +444,7 @@   :: (NFData a)   => (b -> IO a)      -- ^ A function whose memory use we want to measure.   -> b                -- ^ Argument to the function. Doesn't have to be forced.-  -> IO (a, (Int64,Int64,Int64,Int64)) -- ^ Result, Bytes allocated and GCs.+  -> IO (a, (Word64,Word32,Word64,Word64)) -- ^ Result, Bytes allocated and GCs. weighActionResult run !arg = do   ghcStatsSizeInBytes <- GHCStats.getGhcStatsSizeInBytes   performGC
src/Weigh/GHCStats.hs view
@@ -13,34 +13,11 @@   ,maxBytesInUse)   where -#if __GLASGOW_HASKELL__ < 802-import Data.Int-#else-import Data.Int import Data.Word-#endif import GHC.Stats import System.Mem -#if __GLASGOW_HASKELL__ < 802 -- | Get GHC's statistics.-getStats :: IO GCStats-getStats = getGCStats--gcCount :: GCStats -> Int64-gcCount = numGcs--totalBytesAllocated :: GCStats -> Int64-totalBytesAllocated = bytesAllocated--liveBytes :: GCStats -> Int64-liveBytes = currentBytesUsed--maxBytesInUse :: GCStats -> Int64-maxBytesInUse = maxBytesUsed--#else--- | Get GHC's statistics. getStats :: IO RTSStats getStats = getRTSStats @@ -55,10 +32,9 @@  maxBytesInUse :: RTSStats -> Word64 maxBytesInUse = max_live_bytes-#endif  -- | Get the size of a 'RTSStats' object in bytes.-getGhcStatsSizeInBytes :: IO Int64+getGhcStatsSizeInBytes :: IO Word64 getGhcStatsSizeInBytes = do   s1 <- oneGetStats   s2 <- twoGetStats
weigh.cabal view
@@ -1,5 +1,5 @@ name:                weigh-version:             0.0.14+version:             0.0.15 synopsis:            Measure allocations of a Haskell functions/values description:         Please see README.md homepage:            https://github.com/fpco/weigh#readme@@ -25,6 +25,7 @@                      , mtl                      , split                      , temporary+                     , ghc >= 8.2.1   default-language:    Haskell2010  test-suite weigh-test