Ticket #5846: 5846-base.patch

File 5846-base.patch, 1.8 KB (added by pcapriotti, 3 years ago)
  • GHC/Stats.hsc

    From 3219fbb6cc0b44794e6d1406d54ebbc3ac19f740 Mon Sep 17 00:00:00 2001
    From: Paolo Capriotti <[email protected]>
    Date: Fri, 15 Jun 2012 17:13:16 +0100
    Subject: [PATCH] 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 b  
    1515module GHC.Stats
    1616    ( GCStats(..)
    1717    , getGCStats
     18    , getGCStatsEnabled
    1819) where
    1920
     21import Control.Monad
     22import Data.Int
     23import GHC.IO.Exception
    2024import Foreign.Marshal.Alloc
    2125import Foreign.Storable
    2226import Foreign.Ptr
    23 import Data.Int
    2427
    2528#include "Rts.h"
    2629
    27 foreign import ccall "getGCStats"    getGCStats_    :: Ptr () -> IO ()
     30foreign import ccall "getGCStats"        getGCStats_       :: Ptr () -> IO ()
     31foreign import ccall "getGCStatsEnabled" getGCStatsEnabled :: IO Bool
    2832
    2933-- I'm probably violating a bucket of constraints here... oops.
    3034
    data GCStats = GCStats 
    7680-- garbage collection.  If you would like your statistics as recent as
    7781-- possible, first run a 'System.Mem.performGC'.
    7882getGCStats :: IO GCStats
    79 getGCStats = allocaBytes (#size GCStats) $ \p -> do
     83getGCStats = do
     84  statsEnabled <- getGCStatsEnabled
     85  unless statsEnabled .  ioError $ IOError
     86    Nothing
     87    UnsupportedOperation
     88    ""
     89    "getGCStats: GC stats not enabled. Use `+RTS -T -RTS' to enable them."
     90    Nothing
     91    Nothing
     92  allocaBytes (#size GCStats) $ \p -> do
    8093    getGCStats_ p
    8194    bytesAllocated <- (# peek GCStats, bytes_allocated) p
    8295    numGcs <- (# peek GCStats, num_gcs ) p