module GHC.RTS.Flags
( RtsTime
, RTSFlags (..)
, GiveGCStats (..)
, GCFlags (..)
, ConcFlags (..)
, MiscFlags (..)
, DebugFlags (..)
, DoCostCentres (..)
, CCFlags (..)
, DoHeapProfile (..)
, ProfFlags (..)
, DoTrace (..)
, TraceFlags (..)
, TickyFlags (..)
, ParFlags (..)
, IoSubSystem (..)
, getRTSFlags
, getGCFlags
, getConcFlags
, getMiscFlags
, getIoManagerFlag
, getDebugFlags
, getCCFlags
, getProfFlags
, getTraceFlags
, getTickyFlags
, getParFlags
) where
import Data.Functor ((<$>))
import Foreign
import Foreign.C
import GHC.Base
import GHC.Enum
import GHC.Generics (Generic)
import GHC.IO
import GHC.Real
import GHC.Show
type RtsTime = Word64
data GiveGCStats
= NoGCStats
| CollectGCStats
| OneLineGCStats
| SummaryGCStats
| VerboseGCStats
deriving ( Show
, Generic
)
instance Enum GiveGCStats where
fromEnum NoGCStats = 0
fromEnum CollectGCStats = 1
fromEnum OneLineGCStats = 2
fromEnum SummaryGCStats = 3
fromEnum VerboseGCStats = 4
toEnum 0 = NoGCStats
toEnum 1 = CollectGCStats
toEnum 2 = OneLineGCStats
toEnum 3 = SummaryGCStats
toEnum 4 = VerboseGCStats
toEnum e = errorWithoutStackTrace ("invalid enum for GiveGCStats: " ++ show e)
data IoSubSystem
= IoPOSIX
| IoNative
deriving (Eq, Show)
instance Enum IoSubSystem where
fromEnum IoPOSIX = 1
fromEnum IoNative = 0
toEnum 1 = IoPOSIX
toEnum 0 = IoNative
toEnum e = errorWithoutStackTrace ("invalid enum for IoSubSystem: " ++ show e)
instance Storable IoSubSystem where
sizeOf = sizeOf . fromEnum
alignment = sizeOf . fromEnum
peek ptr = fmap toEnum $ peek (castPtr ptr)
poke ptr v = poke (castPtr ptr) (fromEnum v)
data GCFlags = GCFlags
{ statsFile :: Maybe FilePath
, giveStats :: GiveGCStats
, maxStkSize :: Word32
, initialStkSize :: Word32
, stkChunkSize :: Word32
, stkChunkBufferSize :: Word32
, maxHeapSize :: Word32
, minAllocAreaSize :: Word32
, largeAllocLim :: Word32
, nurseryChunkSize :: Word32
, minOldGenSize :: Word32
, heapSizeSuggestion :: Word32
, heapSizeSuggestionAuto :: Bool
, oldGenFactor :: Double
, returnDecayFactor :: Double
, pcFreeHeap :: Double
, generations :: Word32
, squeezeUpdFrames :: Bool
, compact :: Bool
, compactThreshold :: Double
, sweep :: Bool
, ringBell :: Bool
, idleGCDelayTime :: RtsTime
, doIdleGC :: Bool
, heapBase :: Word
, allocLimitGrace :: Word
, numa :: Bool
, numaMask :: Word
} deriving ( Show
, Generic
)
data ConcFlags = ConcFlags
{ ctxtSwitchTime :: RtsTime
, ctxtSwitchTicks :: Int
} deriving ( Show
, Generic
)
data MiscFlags = MiscFlags
{ tickInterval :: RtsTime
, installSignalHandlers :: Bool
, installSEHHandlers :: Bool
, generateCrashDumpFile :: Bool
, generateStackTrace :: Bool
, machineReadable :: Bool
, disableDelayedOsMemoryReturn :: Bool
, internalCounters :: Bool
, linkerAlwaysPic :: Bool
, linkerMemBase :: Word
, ioManager :: IoSubSystem
, numIoWorkerThreads :: Word32
} deriving ( Show
, Generic
)
data DebugFlags = DebugFlags
{ scheduler :: Bool
, interpreter :: Bool
, weak :: Bool
, gccafs :: Bool
, gc :: Bool
, nonmoving_gc :: Bool
, block_alloc :: Bool
, sanity :: Bool
, stable :: Bool
, prof :: Bool
, linker :: Bool
, apply :: Bool
, stm :: Bool
, squeeze :: Bool
, hpc :: Bool
, sparks :: Bool
} deriving ( Show
, Generic
)
data DoCostCentres
= CostCentresNone
| CostCentresSummary
| CostCentresVerbose
| CostCentresAll
| CostCentresJSON
deriving ( Show
, Generic
)
instance Enum DoCostCentres where
fromEnum CostCentresNone = 0
fromEnum CostCentresSummary = 1
fromEnum CostCentresVerbose = 2
fromEnum CostCentresAll = 3
fromEnum CostCentresJSON = 4
toEnum 0 = CostCentresNone
toEnum 1 = CostCentresSummary
toEnum 2 = CostCentresVerbose
toEnum 3 = CostCentresAll
toEnum 4 = CostCentresJSON
toEnum e = errorWithoutStackTrace ("invalid enum for DoCostCentres: " ++ show e)
data CCFlags = CCFlags
{ doCostCentres :: DoCostCentres
, profilerTicks :: Int
, msecsPerTick :: Int
} deriving ( Show
, Generic
)
data DoHeapProfile
= NoHeapProfiling
| HeapByCCS
| HeapByMod
| HeapByDescr
| HeapByType
| HeapByRetainer
| HeapByLDV
| HeapByClosureType
| HeapByInfoTable
deriving ( Show
, Generic
)
instance Enum DoHeapProfile where
fromEnum NoHeapProfiling = 0
fromEnum HeapByCCS = 1
fromEnum HeapByMod = 2
fromEnum HeapByDescr = 4
fromEnum HeapByType = 5
fromEnum HeapByRetainer = 6
fromEnum HeapByLDV = 7
fromEnum HeapByClosureType = 8
fromEnum HeapByInfoTable = 9
toEnum 0 = NoHeapProfiling
toEnum 1 = HeapByCCS
toEnum 2 = HeapByMod
toEnum 4 = HeapByDescr
toEnum 5 = HeapByType
toEnum 6 = HeapByRetainer
toEnum 7 = HeapByLDV
toEnum 8 = HeapByClosureType
toEnum 9 = HeapByInfoTable
toEnum e = errorWithoutStackTrace ("invalid enum for DoHeapProfile: " ++ show e)
data ProfFlags = ProfFlags
{ doHeapProfile :: DoHeapProfile
, heapProfileInterval :: RtsTime
, heapProfileIntervalTicks :: Word
, startHeapProfileAtStartup :: Bool
, showCCSOnException :: Bool
, maxRetainerSetSize :: Word
, ccsLength :: Word
, modSelector :: Maybe String
, descrSelector :: Maybe String
, typeSelector :: Maybe String
, ccSelector :: Maybe String
, ccsSelector :: Maybe String
, retainerSelector :: Maybe String
, bioSelector :: Maybe String
} deriving ( Show
, Generic
)
data DoTrace
= TraceNone
| TraceEventLog
| TraceStderr
deriving ( Show
, Generic
)
instance Enum DoTrace where
fromEnum TraceNone = 0
fromEnum TraceEventLog = 1
fromEnum TraceStderr = 2
toEnum 0 = TraceNone
toEnum 1 = TraceEventLog
toEnum 2 = TraceStderr
toEnum e = errorWithoutStackTrace ("invalid enum for DoTrace: " ++ show e)
data TraceFlags = TraceFlags
{ tracing :: DoTrace
, timestamp :: Bool
, traceScheduler :: Bool
, traceGc :: Bool
, traceNonmovingGc
:: Bool
, sparksSampled :: Bool
, sparksFull :: Bool
, user :: Bool
} deriving ( Show
, Generic
)
data TickyFlags = TickyFlags
{ showTickyStats :: Bool
, tickyFile :: Maybe FilePath
} deriving ( Show
, Generic
)
data ParFlags = ParFlags
{ nCapabilities :: Word32
, migrate :: Bool
, maxLocalSparks :: Word32
, parGcEnabled :: Bool
, parGcGen :: Word32
, parGcLoadBalancingEnabled :: Bool
, parGcLoadBalancingGen :: Word32
, parGcNoSyncWithIdle :: Word32
, parGcThreads :: Word32
, setAffinity :: Bool
}
deriving ( Show
, Generic
)
data RTSFlags = RTSFlags
{ gcFlags :: GCFlags
, concurrentFlags :: ConcFlags
, miscFlags :: MiscFlags
, debugFlags :: DebugFlags
, costCentreFlags :: CCFlags
, profilingFlags :: ProfFlags
, traceFlags :: TraceFlags
, tickyFlags :: TickyFlags
, parFlags :: ParFlags
} deriving ( Show
, Generic
)
foreign import ccall "&RtsFlags" rtsFlagsPtr :: Ptr RTSFlags
getRTSFlags :: IO RTSFlags
getRTSFlags =
RTSFlags <$> getGCFlags
<*> getConcFlags
<*> getMiscFlags
<*> getDebugFlags
<*> getCCFlags
<*> getProfFlags
<*> getTraceFlags
<*> getTickyFlags
<*> getParFlags
peekFilePath :: Ptr () -> IO (Maybe FilePath)
peekFilePath ptr
| ptr == nullPtr = return Nothing
| otherwise = return (Just "<filepath>")
peekCStringOpt :: Ptr CChar -> IO (Maybe String)
peekCStringOpt ptr
| ptr == nullPtr = return Nothing
| otherwise = Just <$> peekCString ptr
getGCFlags :: IO GCFlags
getGCFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 0)) rtsFlagsPtr
GCFlags <$> (peekFilePath =<< (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr)
<*> (toEnum . fromIntegral <$>
((\hsc_ptr -> peekByteOff hsc_ptr 8) ptr :: IO Word32))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 12) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 28) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 36) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 40) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 44) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 48) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 52) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 56) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 64) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 72) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 84) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 88) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 89) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 96) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 104) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 105) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 112) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 128) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 144) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 152) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 168) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 176) ptr
getParFlags :: IO ParFlags
getParFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 424)) rtsFlagsPtr
ParFlags
<$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 4) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 12) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 20) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 28) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 36) ptr :: IO CBool))
getConcFlags :: IO ConcFlags
getConcFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 184)) rtsFlagsPtr
ConcFlags <$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
getMiscFlags :: IO MiscFlags
getMiscFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 200)) rtsFlagsPtr
MiscFlags <$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 8) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 9) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 10) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 11) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 12) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 13) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 14) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 15) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
<*> (toEnum . fromIntegral
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 24) ptr :: IO Word32))
<*> (fromIntegral
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 28) ptr :: IO Word32))
getIoManagerFlag :: IO IoSubSystem
getIoManagerFlag = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 200)) rtsFlagsPtr
mgrFlag <- ((\hsc_ptr -> peekByteOff hsc_ptr 24) ptr :: IO Word32)
return $ (toEnum . fromIntegral) mgrFlag
getDebugFlags :: IO DebugFlags
getDebugFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 232)) rtsFlagsPtr
DebugFlags <$> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 0) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 1) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 2) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 3) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 4) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 5) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 6) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 7) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 9) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 10) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 11) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 12) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 13) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 14) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 15) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 16) ptr :: IO CBool))
getCCFlags :: IO CCFlags
getCCFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 0)) rtsFlagsPtr
CCFlags <$> (toEnum . fromIntegral
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 0) ptr :: IO Word32))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 4) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
getProfFlags :: IO ProfFlags
getProfFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 280)) rtsFlagsPtr
ProfFlags <$> (toEnum <$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr)
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 20) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 21) ptr :: IO CBool))
<*> (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
<*> (\hsc_ptr -> peekByteOff hsc_ptr 28) ptr
<*> (peekCStringOpt =<< (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr)
<*> (peekCStringOpt =<< (\hsc_ptr -> peekByteOff hsc_ptr 40) ptr)
<*> (peekCStringOpt =<< (\hsc_ptr -> peekByteOff hsc_ptr 48) ptr)
<*> (peekCStringOpt =<< (\hsc_ptr -> peekByteOff hsc_ptr 56) ptr)
<*> (peekCStringOpt =<< (\hsc_ptr -> peekByteOff hsc_ptr 64) ptr)
<*> (peekCStringOpt =<< (\hsc_ptr -> peekByteOff hsc_ptr 72) ptr)
<*> (peekCStringOpt =<< (\hsc_ptr -> peekByteOff hsc_ptr 80) ptr)
getTraceFlags :: IO TraceFlags
getTraceFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 368)) rtsFlagsPtr
TraceFlags <$> (toEnum . fromIntegral
<$> ((\hsc_ptr -> peekByteOff hsc_ptr 0) ptr :: IO CInt))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 4) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 5) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 6) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 7) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 8) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 9) ptr :: IO CBool))
<*> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 11) ptr :: IO CBool))
getTickyFlags :: IO TickyFlags
getTickyFlags = do
let ptr = ((\hsc_ptr -> hsc_ptr `plusPtr` 408)) rtsFlagsPtr
TickyFlags <$> (toBool <$>
((\hsc_ptr -> peekByteOff hsc_ptr 0) ptr :: IO CBool))
<*> (peekFilePath =<< (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr)