Repository : ssh://darcs.haskell.org//srv/darcs/packages/base

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/05cf0016f23c9b1f6d4ef0f820c0fd8f56ff02c1

>---------------------------------------------------------------

commit 05cf0016f23c9b1f6d4ef0f820c0fd8f56ff02c1
Author: Paolo Capriotti <[email protected]>
Date:   Fri Jun 15 17:13:16 2012 +0100

    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.

>---------------------------------------------------------------

 GHC/Stats.hsc |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/GHC/Stats.hsc b/GHC/Stats.hsc
index 2020ddd..024d1b2 100644
--- a/GHC/Stats.hsc
+++ b/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



_______________________________________________
Cvs-libraries mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-libraries

Reply via email to