{-# LINE 1 "libraries/base/GHC/Stats.hsc" #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
module GHC.Stats
(
RTSStats(..), GCDetails(..), RtsTime
, getRTSStats
, getRTSStatsEnabled
) where
import Control.Monad
import Data.Int
import Data.Word
import GHC.Base
import GHC.Generics (Generic)
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 {
RTSStats -> Word32
gcs :: Word32
, RTSStats -> Word32
major_gcs :: Word32
, RTSStats -> Word64
allocated_bytes :: Word64
, RTSStats -> Word64
max_live_bytes :: Word64
, RTSStats -> Word64
max_large_objects_bytes :: Word64
, RTSStats -> Word64
max_compact_bytes :: Word64
, RTSStats -> Word64
max_slop_bytes :: Word64
, RTSStats -> Word64
max_mem_in_use_bytes :: Word64
, RTSStats -> Word64
cumulative_live_bytes :: Word64
, RTSStats -> Word64
copied_bytes :: Word64
, RTSStats -> Word64
par_copied_bytes :: Word64
, RTSStats -> Word64
cumulative_par_max_copied_bytes :: Word64
, RTSStats -> Word64
cumulative_par_balanced_copied_bytes :: Word64
, RTSStats -> RtsTime
init_cpu_ns :: RtsTime
, RTSStats -> RtsTime
init_elapsed_ns :: RtsTime
, RTSStats -> RtsTime
mutator_cpu_ns :: RtsTime
, RTSStats -> RtsTime
mutator_elapsed_ns :: RtsTime
, RTSStats -> RtsTime
gc_cpu_ns :: RtsTime
, RTSStats -> RtsTime
gc_elapsed_ns :: RtsTime
, RTSStats -> RtsTime
cpu_ns :: RtsTime
, RTSStats -> RtsTime
elapsed_ns :: RtsTime
, RTSStats -> RtsTime
nonmoving_gc_sync_cpu_ns :: RtsTime
, RTSStats -> RtsTime
nonmoving_gc_sync_elapsed_ns :: RtsTime
, RTSStats -> RtsTime
nonmoving_gc_sync_max_elapsed_ns :: RtsTime
, RTSStats -> RtsTime
nonmoving_gc_cpu_ns :: RtsTime
, RTSStats -> RtsTime
nonmoving_gc_elapsed_ns :: RtsTime
, RTSStats -> RtsTime
nonmoving_gc_max_elapsed_ns :: RtsTime
, RTSStats -> GCDetails
gc :: GCDetails
} deriving ( ReadPrec [RTSStats]
ReadPrec RTSStats
Int -> ReadS RTSStats
ReadS [RTSStats]
(Int -> ReadS RTSStats)
-> ReadS [RTSStats]
-> ReadPrec RTSStats
-> ReadPrec [RTSStats]
-> Read RTSStats
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS RTSStats
readsPrec :: Int -> ReadS RTSStats
$creadList :: ReadS [RTSStats]
readList :: ReadS [RTSStats]
$creadPrec :: ReadPrec RTSStats
readPrec :: ReadPrec RTSStats
$creadListPrec :: ReadPrec [RTSStats]
readListPrec :: ReadPrec [RTSStats]
Read
, Int -> RTSStats -> ShowS
[RTSStats] -> ShowS
RTSStats -> String
(Int -> RTSStats -> ShowS)
-> (RTSStats -> String) -> ([RTSStats] -> ShowS) -> Show RTSStats
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RTSStats -> ShowS
showsPrec :: Int -> RTSStats -> ShowS
$cshow :: RTSStats -> String
show :: RTSStats -> String
$cshowList :: [RTSStats] -> ShowS
showList :: [RTSStats] -> ShowS
Show
, (forall x. RTSStats -> Rep RTSStats x)
-> (forall x. Rep RTSStats x -> RTSStats) -> Generic RTSStats
forall x. Rep RTSStats x -> RTSStats
forall x. RTSStats -> Rep RTSStats x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RTSStats -> Rep RTSStats x
from :: forall x. RTSStats -> Rep RTSStats x
$cto :: forall x. Rep RTSStats x -> RTSStats
to :: forall x. Rep RTSStats x -> RTSStats
Generic
)
data GCDetails = GCDetails {
GCDetails -> Word32
gcdetails_gen :: Word32
, GCDetails -> Word32
gcdetails_threads :: Word32
, GCDetails -> Word64
gcdetails_allocated_bytes :: Word64
, GCDetails -> Word64
gcdetails_live_bytes :: Word64
, GCDetails -> Word64
gcdetails_large_objects_bytes :: Word64
, GCDetails -> Word64
gcdetails_compact_bytes :: Word64
, GCDetails -> Word64
gcdetails_slop_bytes :: Word64
, GCDetails -> Word64
gcdetails_mem_in_use_bytes :: Word64
, GCDetails -> Word64
gcdetails_copied_bytes :: Word64
, GCDetails -> Word64
gcdetails_par_max_copied_bytes :: Word64
, GCDetails -> Word64
gcdetails_par_balanced_copied_bytes :: Word64
, GCDetails -> Word64
gcdetails_block_fragmentation_bytes :: Word64
, GCDetails -> RtsTime
gcdetails_sync_elapsed_ns :: RtsTime
, GCDetails -> RtsTime
gcdetails_cpu_ns :: RtsTime
, GCDetails -> RtsTime
gcdetails_elapsed_ns :: RtsTime
, GCDetails -> RtsTime
gcdetails_nonmoving_gc_sync_cpu_ns :: RtsTime
, GCDetails -> RtsTime
gcdetails_nonmoving_gc_sync_elapsed_ns :: RtsTime
} deriving ( ReadPrec [GCDetails]
ReadPrec GCDetails
Int -> ReadS GCDetails
ReadS [GCDetails]
(Int -> ReadS GCDetails)
-> ReadS [GCDetails]
-> ReadPrec GCDetails
-> ReadPrec [GCDetails]
-> Read GCDetails
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS GCDetails
readsPrec :: Int -> ReadS GCDetails
$creadList :: ReadS [GCDetails]
readList :: ReadS [GCDetails]
$creadPrec :: ReadPrec GCDetails
readPrec :: ReadPrec GCDetails
$creadListPrec :: ReadPrec [GCDetails]
readListPrec :: ReadPrec [GCDetails]
Read
, Int -> GCDetails -> ShowS
[GCDetails] -> ShowS
GCDetails -> String
(Int -> GCDetails -> ShowS)
-> (GCDetails -> String)
-> ([GCDetails] -> ShowS)
-> Show GCDetails
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GCDetails -> ShowS
showsPrec :: Int -> GCDetails -> ShowS
$cshow :: GCDetails -> String
show :: GCDetails -> String
$cshowList :: [GCDetails] -> ShowS
showList :: [GCDetails] -> ShowS
Show
, (forall x. GCDetails -> Rep GCDetails x)
-> (forall x. Rep GCDetails x -> GCDetails) -> Generic GCDetails
forall x. Rep GCDetails x -> GCDetails
forall x. GCDetails -> Rep GCDetails x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. GCDetails -> Rep GCDetails x
from :: forall x. GCDetails -> Rep GCDetails x
$cto :: forall x. Rep GCDetails x -> GCDetails
to :: forall x. Rep GCDetails x -> GCDetails
Generic
)
type RtsTime = Int64
getRTSStats :: IO RTSStats
getRTSStats :: IO RTSStats
getRTSStats = do
Bool
statsEnabled <- IO Bool
getRTSStatsEnabled
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
statsEnabled (IO () -> IO ()) -> (IOException -> IO ()) -> IOException -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOException -> IO ()
forall a. IOException -> IO a
ioError (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError
Maybe Handle
forall a. Maybe a
Nothing
IOErrorType
UnsupportedOperation
String
""
String
"GHC.Stats.getRTSStats: GC stats not enabled. Use `+RTS -T -RTS' to enable them."
Maybe CInt
forall a. Maybe a
Nothing
Maybe String
forall a. Maybe a
Nothing
Int -> (Ptr () -> IO RTSStats) -> IO RTSStats
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes ((Int
376)) ((Ptr () -> IO RTSStats) -> IO RTSStats)
-> (Ptr () -> IO RTSStats) -> IO RTSStats
forall a b. (a -> b) -> a -> b
$ \Ptr ()
p -> do
{-# LINE 204 "libraries/base/GHC/Stats.hsc" #-}
getRTSStats_ p
gcs <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p
{-# LINE 206 "libraries/base/GHC/Stats.hsc" #-}
major_gcs <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) p
{-# LINE 207 "libraries/base/GHC/Stats.hsc" #-}
allocated_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p
{-# LINE 208 "libraries/base/GHC/Stats.hsc" #-}
max_live_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
{-# LINE 209 "libraries/base/GHC/Stats.hsc" #-}
max_large_objects_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) p
{-# LINE 210 "libraries/base/GHC/Stats.hsc" #-}
max_compact_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) p
{-# LINE 211 "libraries/base/GHC/Stats.hsc" #-}
max_slop_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) p
{-# LINE 212 "libraries/base/GHC/Stats.hsc" #-}
max_mem_in_use_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) p
{-# LINE 213 "libraries/base/GHC/Stats.hsc" #-}
cumulative_live_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 56)) p
{-# LINE 214 "libraries/base/GHC/Stats.hsc" #-}
copied_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 64)) p
{-# LINE 215 "libraries/base/GHC/Stats.hsc" #-}
par_copied_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 72)) p
{-# LINE 216 "libraries/base/GHC/Stats.hsc" #-}
cumulative_par_max_copied_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 80)) p
{-# LINE 218 "libraries/base/GHC/Stats.hsc" #-}
cumulative_par_balanced_copied_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 88)) p
{-# LINE 220 "libraries/base/GHC/Stats.hsc" #-}
init_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 96)) p
{-# LINE 221 "libraries/base/GHC/Stats.hsc" #-}
init_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 104)) p
{-# LINE 222 "libraries/base/GHC/Stats.hsc" #-}
mutator_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 112)) p
{-# LINE 223 "libraries/base/GHC/Stats.hsc" #-}
mutator_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 120)) p
{-# LINE 224 "libraries/base/GHC/Stats.hsc" #-}
gc_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 128)) p
{-# LINE 225 "libraries/base/GHC/Stats.hsc" #-}
gc_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 136)) p
{-# LINE 226 "libraries/base/GHC/Stats.hsc" #-}
cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 144)) p
{-# LINE 227 "libraries/base/GHC/Stats.hsc" #-}
elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 152)) p
{-# LINE 228 "libraries/base/GHC/Stats.hsc" #-}
nonmoving_gc_sync_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 328)) p
{-# LINE 229 "libraries/base/GHC/Stats.hsc" #-}
nonmoving_gc_sync_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 336)) p
{-# LINE 230 "libraries/base/GHC/Stats.hsc" #-}
nonmoving_gc_sync_max_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 344)) p
{-# LINE 231 "libraries/base/GHC/Stats.hsc" #-}
nonmoving_gc_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 352)) p
{-# LINE 232 "libraries/base/GHC/Stats.hsc" #-}
nonmoving_gc_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 360)) p
{-# LINE 233 "libraries/base/GHC/Stats.hsc" #-}
nonmoving_gc_max_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 368)) p
{-# LINE 234 "libraries/base/GHC/Stats.hsc" #-}
let pgc = ((\hsc_ptr -> hsc_ptr `plusPtr` 160)) p
{-# LINE 235 "libraries/base/GHC/Stats.hsc" #-}
gc <- do
gcdetails_gen <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) pgc
{-# LINE 237 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_threads <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) pgc
{-# LINE 238 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_allocated_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) pgc
{-# LINE 239 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_live_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) pgc
{-# LINE 240 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_large_objects_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 24)) pgc
{-# LINE 242 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_compact_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) pgc
{-# LINE 243 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_slop_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) pgc
{-# LINE 244 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_mem_in_use_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) pgc
{-# LINE 245 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_copied_bytes <- ((\hsc_ptr -> peekByteOff hsc_ptr 56)) pgc
{-# LINE 246 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_par_max_copied_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 72)) pgc
{-# LINE 248 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_par_balanced_copied_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 80)) pgc
{-# LINE 250 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_block_fragmentation_bytes <-
((\hsc_ptr -> peekByteOff hsc_ptr 64)) pgc
{-# LINE 252 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_sync_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 88)) pgc
{-# LINE 253 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 96)) pgc
{-# LINE 254 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 104)) pgc
{-# LINE 255 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_nonmoving_gc_sync_cpu_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 112)) pgc
{-# LINE 256 "libraries/base/GHC/Stats.hsc" #-}
gcdetails_nonmoving_gc_sync_elapsed_ns <- ((\hsc_ptr -> peekByteOff hsc_ptr 120)) pgc
{-# LINE 257 "libraries/base/GHC/Stats.hsc" #-}
return GCDetails{..}
return RTSStats{..}