{-# LINE 1 "GHC/Stats.hsc" #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
module GHC.Stats
(
RTSStats(..), GCDetails(..), RtsTime
, getRTSStats
, getRTSStatsEnabled
, 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
import Foreign.Marshal.Alloc
import Foreign.Storable
import Foreign.Ptr
foreign import ccall "getRTSStats" getRTSStats_ :: Ptr () -> IO ()
foreign import ccall "getRTSStatsEnabled" getRTSStatsEnabled :: IO Bool
data RTSStats = RTSStats {
gcs :: Word32
, major_gcs :: Word32
, allocated_bytes :: Word64
, max_live_bytes :: Word64
, max_large_objects_bytes :: Word64
, max_compact_bytes :: Word64
, max_slop_bytes :: Word64
, max_mem_in_use_bytes :: Word64
, cumulative_live_bytes :: Word64
, copied_bytes :: Word64
, par_copied_bytes :: Word64
, cumulative_par_max_copied_bytes :: Word64
, mutator_cpu_ns :: RtsTime
, mutator_elapsed_ns :: RtsTime
, gc_cpu_ns :: RtsTime
, gc_elapsed_ns :: RtsTime
, cpu_ns :: RtsTime
, elapsed_ns :: RtsTime
, gc :: GCDetails
} deriving (Read, Show)
data GCDetails = GCDetails {
gcdetails_gen :: Word32
, gcdetails_threads :: Word32
, gcdetails_allocated_bytes :: Word64
, gcdetails_live_bytes :: Word64
, gcdetails_large_objects_bytes :: Word64
, gcdetails_compact_bytes :: Word64
, gcdetails_slop_bytes :: Word64
, gcdetails_mem_in_use_bytes :: Word64
, gcdetails_copied_bytes :: Word64
, gcdetails_par_max_copied_bytes :: Word64
, gcdetails_sync_elapsed_ns :: RtsTime
, gcdetails_cpu_ns :: RtsTime
, gcdetails_elapsed_ns :: RtsTime
} deriving (Read, Show)
type RtsTime = Int64
getRTSStats :: IO RTSStats
getRTSStats = do
statsEnabled <- getGCStatsEnabled
unless statsEnabled . ioError $ IOError
Nothing
UnsupportedOperation
""
"getGCStats: GC stats not enabled. Use `+RTS -T -RTS' to enable them."
Nothing
Nothing
allocaBytes ((232)) $ \p -> do
{-# LINE 159 "GHC/Stats.hsc" #-}
getRTSStats_ p
gcs <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p
{-# LINE 161 "GHC/Stats.hsc" #-}
major_gcs <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) p
{-# LINE 162 "GHC/Stats.hsc" #-}
allocated_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p
{-# LINE 163 "GHC/Stats.hsc" #-}
max_live_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
{-# LINE 164 "GHC/Stats.hsc" #-}
max_large_objects_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) p
{-# LINE 165 "GHC/Stats.hsc" #-}
max_compact_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) p
{-# LINE 166 "GHC/Stats.hsc" #-}
max_slop_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) p
{-# LINE 167 "GHC/Stats.hsc" #-}
max_mem_in_use_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) p
{-# LINE 168 "GHC/Stats.hsc" #-}
cumulative_live_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 56)) p
{-# LINE 169 "GHC/Stats.hsc" #-}
copied_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 64)) p
{-# LINE 170 "GHC/Stats.hsc" #-}
par_copied_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 72)) p
{-# LINE 171 "GHC/Stats.hsc" #-}
cumulative_par_max_copied_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 80)) p
{-# LINE 173 "GHC/Stats.hsc" #-}
mutator_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 88)) p
{-# LINE 174 "GHC/Stats.hsc" #-}
mutator_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 96)) p
{-# LINE 175 "GHC/Stats.hsc" #-}
gc_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 104)) p
{-# LINE 176 "GHC/Stats.hsc" #-}
gc_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 112)) p
{-# LINE 177 "GHC/Stats.hsc" #-}
cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 120)) p
{-# LINE 178 "GHC/Stats.hsc" #-}
elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 128)) p
{-# LINE 179 "GHC/Stats.hsc" #-}
let pgc = ((\hsc_ptr -> hsc_ptr `plusPtr` 136)) p
{-# LINE 180 "GHC/Stats.hsc" #-}
gc <- do
gcdetails_gen <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) pgc
{-# LINE 182 "GHC/Stats.hsc" #-}
gcdetails_threads <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) pgc
{-# LINE 183 "GHC/Stats.hsc" #-}
gcdetails_allocated_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) pgc
{-# LINE 184 "GHC/Stats.hsc" #-}
gcdetails_live_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) pgc
{-# LINE 185 "GHC/Stats.hsc" #-}
gcdetails_large_objects_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 24)) pgc
{-# LINE 187 "GHC/Stats.hsc" #-}
gcdetails_compact_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) pgc
{-# LINE 188 "GHC/Stats.hsc" #-}
gcdetails_slop_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) pgc
{-# LINE 189 "GHC/Stats.hsc" #-}
gcdetails_mem_in_use_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) pgc
{-# LINE 190 "GHC/Stats.hsc" #-}
gcdetails_copied_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 56)) pgc
{-# LINE 191 "GHC/Stats.hsc" #-}
gcdetails_par_max_copied_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 64)) pgc
{-# LINE 193 "GHC/Stats.hsc" #-}
gcdetails_sync_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 72)) pgc
{-# LINE 194 "GHC/Stats.hsc" #-}
gcdetails_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 80)) pgc
{-# LINE 195 "GHC/Stats.hsc" #-}
gcdetails_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 88)) pgc
{-# LINE 196 "GHC/Stats.hsc" #-}
return GCDetails{..}
return RTSStats{..}
{-# DEPRECATED GCStats "Use RTSStats instead. This will be removed in GHC 8.4.1" #-}
data GCStats = GCStats
{
bytesAllocated :: !Int64
, numGcs :: !Int64
, maxBytesUsed :: !Int64
, numByteUsageSamples :: !Int64
, cumulativeBytesUsed :: !Int64
, bytesCopied :: !Int64
, currentBytesUsed :: !Int64
, currentBytesSlop :: !Int64
, maxBytesSlop :: !Int64
, peakMegabytesAllocated :: !Int64
, mblocksAllocated :: !Int64
, mutatorCpuSeconds :: !Double
, mutatorWallSeconds :: !Double
, gcCpuSeconds :: !Double
, gcWallSeconds :: !Double
, cpuSeconds :: !Double
, wallSeconds :: !Double
, parTotBytesCopied :: !Int64
, parMaxBytesCopied :: !Int64
} deriving (Show, Read)
{-# 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 ((232)) $ \p -> do
{-# LINE 284 "GHC/Stats.hsc" #-}
getRTSStats_ p
bytesAllocated <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p
{-# LINE 286 "GHC/Stats.hsc" #-}
numGcs <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p
{-# LINE 287 "GHC/Stats.hsc" #-}
numByteUsageSamples <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) p
{-# LINE 288 "GHC/Stats.hsc" #-}
maxBytesUsed <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
{-# LINE 289 "GHC/Stats.hsc" #-}
cumulativeBytesUsed <- ((\hsc_ptr -> peekByteOff hsc_ptr 56)) p
{-# LINE 290 "GHC/Stats.hsc" #-}
bytesCopied <- ((\hsc_ptr -> peekByteOff hsc_ptr 64)) p
{-# LINE 291 "GHC/Stats.hsc" #-}
currentBytesUsed <- ((\hsc_ptr -> peekByteOff hsc_ptr 152)) p
{-# LINE 292 "GHC/Stats.hsc" #-}
currentBytesSlop <- ((\hsc_ptr -> peekByteOff hsc_ptr 176)) p
{-# LINE 293 "GHC/Stats.hsc" #-}
maxBytesSlop <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) p
{-# LINE 294 "GHC/Stats.hsc" #-}
peakMegabytesAllocated <- do
bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) p
{-# LINE 296 "GHC/Stats.hsc" #-}
return (bytes `quot` (1024*1024))
mblocksAllocated <- do
bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 184)) p
{-# LINE 299 "GHC/Stats.hsc" #-}
return (bytes `quot` (1024*1024))
mutatorCpuSeconds <- nsToSecs <$> ((\hsc_ptr -> peekByteOff hsc_ptr 88)) p
{-# LINE 301 "GHC/Stats.hsc" #-}
mutatorWallSeconds <-
nsToSecs <$> ((\hsc_ptr -> peekByteOff hsc_ptr 96)) p
{-# LINE 303 "GHC/Stats.hsc" #-}
gcCpuSeconds <- nsToSecs <$> ((\hsc_ptr -> peekByteOff hsc_ptr 104)) p
{-# LINE 304 "GHC/Stats.hsc" #-}
gcWallSeconds <- nsToSecs <$> ((\hsc_ptr -> peekByteOff hsc_ptr 112)) p
{-# LINE 305 "GHC/Stats.hsc" #-}
cpuSeconds <- nsToSecs <$> ((\hsc_ptr -> peekByteOff hsc_ptr 120)) p
{-# LINE 306 "GHC/Stats.hsc" #-}
wallSeconds <- nsToSecs <$> ((\hsc_ptr -> peekByteOff hsc_ptr 128)) p
{-# LINE 307 "GHC/Stats.hsc" #-}
parTotBytesCopied <- ((\hsc_ptr -> peekByteOff hsc_ptr 72)) p
{-# LINE 308 "GHC/Stats.hsc" #-}
parMaxBytesCopied <- ((\hsc_ptr -> peekByteOff hsc_ptr 80)) p
{-# LINE 309 "GHC/Stats.hsc" #-}
return GCStats { .. }
nsToSecs :: Int64 -> Double
nsToSecs ns = fromIntegral ns / (1000000000)
{-# LINE 313 "GHC/Stats.hsc" #-}
{-# DEPRECATED getGCStatsEnabled
"use getRTSStatsEnabled instead. This will be removed in GHC 8.4.1" #-}
getGCStatsEnabled :: IO Bool
getGCStatsEnabled = getRTSStatsEnabled