From 3219fbb6cc0b44794e6d1406d54ebbc3ac19f740 Mon Sep 17 00:00:00 2001
From: Paolo Capriotti <p.capriotti@gmail.com>
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
|
|
| 15 | 15 | module GHC.Stats |
| 16 | 16 | ( GCStats(..) |
| 17 | 17 | , getGCStats |
| | 18 | , getGCStatsEnabled |
| 18 | 19 | ) where |
| 19 | 20 | |
| | 21 | import Control.Monad |
| | 22 | import Data.Int |
| | 23 | import GHC.IO.Exception |
| 20 | 24 | import Foreign.Marshal.Alloc |
| 21 | 25 | import Foreign.Storable |
| 22 | 26 | import Foreign.Ptr |
| 23 | | import Data.Int |
| 24 | 27 | |
| 25 | 28 | #include "Rts.h" |
| 26 | 29 | |
| 27 | | foreign import ccall "getGCStats" getGCStats_ :: Ptr () -> IO () |
| | 30 | foreign import ccall "getGCStats" getGCStats_ :: Ptr () -> IO () |
| | 31 | foreign import ccall "getGCStatsEnabled" getGCStatsEnabled :: IO Bool |
| 28 | 32 | |
| 29 | 33 | -- I'm probably violating a bucket of constraints here... oops. |
| 30 | 34 | |
| … |
… |
|
| 76 | 80 | -- garbage collection. If you would like your statistics as recent as |
| 77 | 81 | -- possible, first run a 'System.Mem.performGC'. |
| 78 | 82 | getGCStats :: IO GCStats |
| 79 | | getGCStats = allocaBytes (#size GCStats) $ \p -> do |
| | 83 | getGCStats = 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 |
| 80 | 93 | getGCStats_ p |
| 81 | 94 | bytesAllocated <- (# peek GCStats, bytes_allocated) p |
| 82 | 95 | numGcs <- (# peek GCStats, num_gcs ) p |