diff options
author | Paolo Capriotti <p.capriotti@gmail.com> | 2012-06-15 17:13:16 +0100 |
---|---|---|
committer | Paolo Capriotti <p.capriotti@gmail.com> | 2012-06-19 14:36:24 +0100 |
commit | c41ac8ff68490accbbea7a4a01431819867ce390 (patch) | |
tree | ef215849104dbbd8a0cc616e8f67d025590c6d6e /libraries/base/GHC/Stats.hsc | |
parent | 1befc1929191f61e6008229eab263803c8dcb19b (diff) | |
download | haskell-c41ac8ff68490accbbea7a4a01431819867ce390.tar.gz |
Add GHC.Stats.getGCStatsEnabled function (#5846)
Add getGCStatsEnabled function which checks whether GC stats have been
enabled (with `-T`, for example).
Make getGCStats throw an exception if called with GC stats disabled.
Diffstat (limited to 'libraries/base/GHC/Stats.hsc')
-rw-r--r-- | libraries/base/GHC/Stats.hsc | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/libraries/base/GHC/Stats.hsc b/libraries/base/GHC/Stats.hsc index 2020dddddf..024d1b22b6 100644 --- a/libraries/base/GHC/Stats.hsc +++ b/libraries/base/GHC/Stats.hsc @@ -15,16 +15,20 @@ module GHC.Stats ( GCStats(..) , getGCStats + , getGCStatsEnabled ) where +import Control.Monad +import Data.Int +import GHC.IO.Exception import Foreign.Marshal.Alloc import Foreign.Storable import Foreign.Ptr -import Data.Int #include "Rts.h" -foreign import ccall "getGCStats" getGCStats_ :: Ptr () -> IO () +foreign import ccall "getGCStats" getGCStats_ :: Ptr () -> IO () +foreign import ccall "getGCStatsEnabled" getGCStatsEnabled :: IO Bool -- I'm probably violating a bucket of constraints here... oops. @@ -76,7 +80,16 @@ data GCStats = GCStats -- garbage collection. If you would like your statistics as recent as -- possible, first run a 'System.Mem.performGC'. getGCStats :: IO GCStats -getGCStats = allocaBytes (#size GCStats) $ \p -> do +getGCStats = do + statsEnabled <- getGCStatsEnabled + unless statsEnabled . ioError $ IOError + Nothing + UnsupportedOperation + "" + "getGCStats: GC stats not enabled. Use `+RTS -T -RTS' to enable them." + Nothing + Nothing + allocaBytes (#size GCStats) $ \p -> do getGCStats_ p bytesAllocated <- (# peek GCStats, bytes_allocated) p numGcs <- (# peek GCStats, num_gcs ) p |