summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/Stats.hsc
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/GHC/Stats.hsc')
-rw-r--r--libraries/base/GHC/Stats.hsc176
1 files changed, 26 insertions, 150 deletions
diff --git a/libraries/base/GHC/Stats.hsc b/libraries/base/GHC/Stats.hsc
index 58fb12592f..58b5e22d04 100644
--- a/libraries/base/GHC/Stats.hsc
+++ b/libraries/base/GHC/Stats.hsc
@@ -18,20 +18,12 @@ module GHC.Stats
RTSStats(..), GCDetails(..), RtsTime
, getRTSStats
, getRTSStatsEnabled
-
- -- * DEPRECATED, don't use
- , GCStats(..)
- , getGCStats
- , getGCStatsEnabled
) where
-import Control.Applicative
import Control.Monad
import Data.Int
import Data.Word
import GHC.Base
-import GHC.Num (Num(..))
-import GHC.Real (quot, fromIntegral, (/))
import GHC.Read ( Read )
import GHC.Show ( Show )
import GHC.IO.Exception
@@ -45,14 +37,14 @@ foreign import ccall "getRTSStats" getRTSStats_ :: Ptr () -> IO ()
-- | Returns whether GC stats have been enabled (with @+RTS -T@, for example).
--
--- @since 4.9.0.0
+-- @since 4.10.0.0
foreign import ccall "getRTSStatsEnabled" getRTSStatsEnabled :: IO Bool
--
-- | Statistics about runtime activity since the start of the
-- program. This is a mirror of the C @struct RTSStats@ in @RtsAPI.h@
--
--- @since 4.9.0.0
+-- @since 4.10.0.0
--
data RTSStats = RTSStats {
-- -----------------------------------
@@ -64,7 +56,8 @@ data RTSStats = RTSStats {
, major_gcs :: Word32
-- | Total bytes allocated
, allocated_bytes :: Word64
- -- | Maximum live data (including large objects + compact regions)
+ -- | Maximum live data (including large objects + compact regions) in the
+ -- heap. Updated after a major GC.
, max_live_bytes :: Word64
-- | Maximum live data in large objects
, max_large_objects_bytes :: Word64
@@ -91,6 +84,12 @@ data RTSStats = RTSStats {
-- (we use signed values here because due to inaccuracies in timers
-- the values can occasionally go slightly negative)
+ -- | Total CPU time used by the init phase
+ -- @since 4.12.0.0
+ , init_cpu_ns :: RtsTime
+ -- | Total elapsed time used by the init phase
+ -- @since 4.12.0.0
+ , init_elapsed_ns :: RtsTime
-- | Total CPU time used by the mutator
, mutator_cpu_ns :: RtsTime
-- | Total elapsed time used by the mutator
@@ -106,7 +105,9 @@ data RTSStats = RTSStats {
-- | Details about the most recent GC
, gc :: GCDetails
- } deriving (Read, Show)
+ } deriving ( Read -- ^ @since 4.10.0.0
+ , Show -- ^ @since 4.10.0.0
+ )
--
-- | Statistics about a single GC. This is a mirror of the C @struct
@@ -120,7 +121,9 @@ data GCDetails = GCDetails {
, gcdetails_threads :: Word32
-- | Number of bytes allocated since the previous GC
, gcdetails_allocated_bytes :: Word64
- -- | Total amount of live data in the heap (incliudes large + compact data)
+ -- | Total amount of live data in the heap (incliudes large + compact data).
+ -- Updated after every GC. Data in uncollected generations (in minor GCs)
+ -- are considered live.
, gcdetails_live_bytes :: Word64
-- | Total amount of live data in large objects
, gcdetails_large_objects_bytes :: Word64
@@ -143,21 +146,25 @@ data GCDetails = GCDetails {
, gcdetails_cpu_ns :: RtsTime
-- | The time elapsed during GC itself
, gcdetails_elapsed_ns :: RtsTime
- } deriving (Read, Show)
+ } deriving ( Read -- ^ @since 4.10.0.0
+ , Show -- ^ @since 4.10.0.0
+ )
-- | Time values from the RTS, using a fixed resolution of nanoseconds.
type RtsTime = Int64
--- @since 4.9.0.0
+-- | Get current runtime system statistics.
+--
+-- @since 4.10.0.0
--
getRTSStats :: IO RTSStats
getRTSStats = do
- statsEnabled <- getGCStatsEnabled
+ statsEnabled <- getRTSStatsEnabled
unless statsEnabled . ioError $ IOError
Nothing
UnsupportedOperation
""
- "getGCStats: GC stats not enabled. Use `+RTS -T -RTS' to enable them."
+ "GHC.Stats.getRTSStats: GC stats not enabled. Use `+RTS -T -RTS' to enable them."
Nothing
Nothing
allocaBytes (#size RTSStats) $ \p -> do
@@ -177,6 +184,8 @@ getRTSStats = do
(# peek RTSStats, cumulative_par_max_copied_bytes) p
cumulative_par_balanced_copied_bytes <-
(# peek RTSStats, cumulative_par_balanced_copied_bytes) p
+ init_cpu_ns <- (# peek RTSStats, init_cpu_ns) p
+ init_elapsed_ns <- (# peek RTSStats, init_elapsed_ns) p
mutator_cpu_ns <- (# peek RTSStats, mutator_cpu_ns) p
mutator_elapsed_ns <- (# peek RTSStats, mutator_elapsed_ns) p
gc_cpu_ns <- (# peek RTSStats, gc_cpu_ns) p
@@ -204,136 +213,3 @@ getRTSStats = do
gcdetails_elapsed_ns <- (# peek GCDetails, elapsed_ns) pgc
return GCDetails{..}
return RTSStats{..}
-
--- -----------------------------------------------------------------------------
--- DEPRECATED API
-
--- I'm probably violating a bucket of constraints here... oops.
-
--- | Statistics about memory usage and the garbage collector. Apart from
--- 'currentBytesUsed' and 'currentBytesSlop' all are cumulative values since
--- the program started.
---
--- @since 4.5.0.0
-{-# DEPRECATED GCStats "Use RTSStats instead. This will be removed in GHC 8.4.1" #-}
-data GCStats = GCStats
- { -- | Total number of bytes allocated
- bytesAllocated :: !Int64
- -- | Number of garbage collections performed (any generation, major and
- -- minor)
- , numGcs :: !Int64
- -- | Maximum number of live bytes seen so far
- , maxBytesUsed :: !Int64
- -- | Number of byte usage samples taken, or equivalently
- -- the number of major GCs performed.
- , numByteUsageSamples :: !Int64
- -- | Sum of all byte usage samples, can be used with
- -- 'numByteUsageSamples' to calculate averages with
- -- arbitrary weighting (if you are sampling this record multiple
- -- times).
- , cumulativeBytesUsed :: !Int64
- -- | Number of bytes copied during GC
- , bytesCopied :: !Int64
- -- | Number of live bytes at the end of the last major GC
- , currentBytesUsed :: !Int64
- -- | Current number of bytes lost to slop
- , currentBytesSlop :: !Int64
- -- | Maximum number of bytes lost to slop at any one time so far
- , maxBytesSlop :: !Int64
- -- | Maximum number of megabytes allocated
- , peakMegabytesAllocated :: !Int64
- -- | CPU time spent running mutator threads. This does not include
- -- any profiling overhead or initialization.
- , mblocksAllocated :: !Int64 -- ^ Number of allocated megablocks
- , mutatorCpuSeconds :: !Double
-
- -- | Wall clock time spent running mutator threads. This does not
- -- include initialization.
- , mutatorWallSeconds :: !Double
- -- | CPU time spent running GC
- , gcCpuSeconds :: !Double
- -- | Wall clock time spent running GC
- , gcWallSeconds :: !Double
- -- | Total CPU time elapsed since program start
- , cpuSeconds :: !Double
- -- | Total wall clock time elapsed since start
- , wallSeconds :: !Double
- -- | Number of bytes copied during GC, minus space held by mutable
- -- lists held by the capabilities. Can be used with
- -- 'parMaxBytesCopied' to determine how well parallel GC utilized
- -- all cores.
- , parTotBytesCopied :: !Int64
-
- -- | Sum of number of bytes copied each GC by the most active GC
- -- thread each GC. The ratio of 'parTotBytesCopied' divided by
- -- 'parMaxBytesCopied' approaches 1 for a maximally sequential
- -- run and approaches the number of threads (set by the RTS flag
- -- @-N@) for a maximally parallel run. This is included for
- -- backwards compatibility; to compute work balance use
- -- `parBalancedBytesCopied`.
- , parMaxBytesCopied :: !Int64
-
- -- | Sum of number of balanced bytes copied on each thread of each GC.
- -- Balanced bytes are those up to a
- -- limit = (parTotBytesCopied / num_gc_threads).
- -- This number is normalized so that when balance is perfect
- -- @parBalancedBytesCopied = parTotBytesCopied@ and when all
- -- gc is done by a single thread @parBalancedBytesCopied = 0@.
- , parBalancedBytesCopied :: !Int64
-
- } deriving (Show, Read)
-
--- | Retrieves garbage collection and memory statistics as of the last
--- garbage collection. If you would like your statistics as recent as
--- possible, first run a 'System.Mem.performGC'.
---
--- @since 4.5.0.0
-{-# DEPRECATED getGCStats
- "Use getRTSStats instead. This will be removed in GHC 8.4.1" #-}
-getGCStats :: IO GCStats
-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 RTSStats) $ \p -> do
- getRTSStats_ p
- bytesAllocated <- (# peek RTSStats, allocated_bytes) p
- numGcs <- (# peek RTSStats, gcs ) p
- numByteUsageSamples <- (# peek RTSStats, major_gcs ) p
- maxBytesUsed <- (# peek RTSStats, max_live_bytes ) p
- cumulativeBytesUsed <- (# peek RTSStats, cumulative_live_bytes ) p
- bytesCopied <- (# peek RTSStats, copied_bytes ) p
- currentBytesUsed <- (# peek RTSStats, gc.live_bytes ) p
- currentBytesSlop <- (# peek RTSStats, gc.slop_bytes) p
- maxBytesSlop <- (# peek RTSStats, max_slop_bytes) p
- peakMegabytesAllocated <- do
- bytes <- (# peek RTSStats, max_mem_in_use_bytes ) p
- return (bytes `quot` (1024*1024))
- mblocksAllocated <- do
- bytes <- (# peek RTSStats, gc.mem_in_use_bytes) p
- return (bytes `quot` (1024*1024))
- mutatorCpuSeconds <- nsToSecs <$> (# peek RTSStats, mutator_cpu_ns) p
- mutatorWallSeconds <-
- nsToSecs <$> (# peek RTSStats, mutator_elapsed_ns) p
- gcCpuSeconds <- nsToSecs <$> (# peek RTSStats, gc_cpu_ns) p
- gcWallSeconds <- nsToSecs <$> (# peek RTSStats, gc_elapsed_ns) p
- cpuSeconds <- nsToSecs <$> (# peek RTSStats, cpu_ns) p
- wallSeconds <- nsToSecs <$> (# peek RTSStats, elapsed_ns) p
- parTotBytesCopied <- (# peek RTSStats, par_copied_bytes) p
- parMaxBytesCopied <- (# peek RTSStats, cumulative_par_max_copied_bytes) p
- parBalancedBytesCopied <-
- (# peek RTSStats, cumulative_par_balanced_copied_bytes) p
- return GCStats { .. }
-
-nsToSecs :: Int64 -> Double
-nsToSecs ns = fromIntegral ns / (# const TIME_RESOLUTION)
-
-{-# DEPRECATED getGCStatsEnabled
- "use getRTSStatsEnabled instead. This will be removed in GHC 8.4.1" #-}
-getGCStatsEnabled :: IO Bool
-getGCStatsEnabled = getRTSStatsEnabled