Flags.hsc 18.7 KB
Newer Older
1 2 3 4 5
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RecordWildCards   #-}

-- | Accessors to GHC RTS flags.
-- Descriptions of flags can be seen in
6
-- <https://www.haskell.org/ghc/docs/latest/html/users_guide/runtime_control.html GHC User's Guide>,
7 8
-- or by running RTS help message using @+RTS --help@.
--
9
-- @since 4.8.0.0
10 11
--
module GHC.RTS.Flags
12 13 14
  ( RtsTime
  , RTSFlags (..)
  , GiveGCStats (..)
15 16 17 18
  , GCFlags (..)
  , ConcFlags (..)
  , MiscFlags (..)
  , DebugFlags (..)
19
  , DoCostCentres (..)
20
  , CCFlags (..)
21
  , DoHeapProfile (..)
22
  , ProfFlags (..)
23
  , DoTrace (..)
24 25
  , TraceFlags (..)
  , TickyFlags (..)
Simon Marlow's avatar
Simon Marlow committed
26
  , ParFlags (..)
27 28 29 30 31 32 33 34 35
  , getRTSFlags
  , getGCFlags
  , getConcFlags
  , getMiscFlags
  , getDebugFlags
  , getCCFlags
  , getProfFlags
  , getTraceFlags
  , getTickyFlags
Simon Marlow's avatar
Simon Marlow committed
36
  , getParFlags
37 38 39 40 41 42 43 44
  ) where

#include "Rts.h"
#include "rts/Flags.h"

import Control.Applicative
import Control.Monad

Simon Marlow's avatar
Simon Marlow committed
45 46
import Foreign
import Foreign.C
47 48 49 50 51 52 53

import GHC.Base
import GHC.Enum
import GHC.IO
import GHC.Real
import GHC.Show

54
-- | 'RtsTime' is defined as a @StgWord64@ in @stg/Types.h@
55
--
56
-- @since 4.8.2.0
57
type RtsTime = Word64
58

59 60 61
-- | Should we produce a summary of the garbage collector statistics after the
-- program has exited?
--
62
-- @since 4.8.2.0
63 64 65 66 67 68
data GiveGCStats
    = NoGCStats
    | CollectGCStats
    | OneLineGCStats
    | SummaryGCStats
    | VerboseGCStats
69 70
    deriving ( Show -- ^ @since 4.8.0.0
             )
71

72
-- | @since 4.8.0.0
73 74 75 76 77 78 79 80 81 82 83 84
instance Enum GiveGCStats where
    fromEnum NoGCStats      = #{const NO_GC_STATS}
    fromEnum CollectGCStats = #{const COLLECT_GC_STATS}
    fromEnum OneLineGCStats = #{const ONELINE_GC_STATS}
    fromEnum SummaryGCStats = #{const SUMMARY_GC_STATS}
    fromEnum VerboseGCStats = #{const VERBOSE_GC_STATS}

    toEnum #{const NO_GC_STATS}      = NoGCStats
    toEnum #{const COLLECT_GC_STATS} = CollectGCStats
    toEnum #{const ONELINE_GC_STATS} = OneLineGCStats
    toEnum #{const SUMMARY_GC_STATS} = SummaryGCStats
    toEnum #{const VERBOSE_GC_STATS} = VerboseGCStats
Eric Seidel's avatar
Eric Seidel committed
85
    toEnum e = errorWithoutStackTrace ("invalid enum for GiveGCStats: " ++ show e)
86

87 88 89
-- | Parameters of the garbage collector.
--
-- @since 4.8.0.0
90 91 92
data GCFlags = GCFlags
    { statsFile             :: Maybe FilePath
    , giveStats             :: GiveGCStats
Simon Marlow's avatar
Simon Marlow committed
93 94 95 96 97 98 99 100 101 102
    , maxStkSize            :: Word32
    , initialStkSize        :: Word32
    , stkChunkSize          :: Word32
    , stkChunkBufferSize    :: Word32
    , maxHeapSize           :: Word32
    , minAllocAreaSize      :: Word32
    , largeAllocLim         :: Word32
    , nurseryChunkSize      :: Word32
    , minOldGenSize         :: Word32
    , heapSizeSuggestion    :: Word32
103
    , heapSizeSuggestionAuto :: Bool
104 105
    , oldGenFactor          :: Double
    , pcFreeHeap            :: Double
Simon Marlow's avatar
Simon Marlow committed
106
    , generations           :: Word32
107 108 109 110 111 112
    , squeezeUpdFrames      :: Bool
    , compact               :: Bool -- ^ True <=> "compact all the time"
    , compactThreshold      :: Double
    , sweep                 :: Bool
      -- ^ use "mostly mark-sweep" instead of copying for the oldest generation
    , ringBell              :: Bool
113
    , idleGCDelayTime       :: RtsTime
114 115 116
    , doIdleGC              :: Bool
    , heapBase              :: Word -- ^ address to ask the OS for memory
    , allocLimitGrace       :: Word
Simon Marlow's avatar
Simon Marlow committed
117
    , numa                  :: Bool
Simon Marlow's avatar
Simon Marlow committed
118
    , numaMask              :: Word
119 120
    } deriving ( Show -- ^ @since 4.8.0.0
               )
121

122 123 124
-- | Parameters concerning context switching
--
-- @since 4.8.0.0
125
data ConcFlags = ConcFlags
126
    { ctxtSwitchTime  :: RtsTime
127
    , ctxtSwitchTicks :: Int
128 129
    } deriving ( Show -- ^ @since 4.8.0.0
               )
130

131 132 133
-- | Miscellaneous parameters
--
-- @since 4.8.0.0
134
data MiscFlags = MiscFlags
135
    { tickInterval          :: RtsTime
136
    , installSignalHandlers :: Bool
137
    , installSEHHandlers    :: Bool
138
    , generateCrashDumpFile :: Bool
139
    , generateStackTrace    :: Bool
140
    , machineReadable       :: Bool
141
    , internalCounters      :: Bool
142 143
    , linkerMemBase         :: Word
      -- ^ address to ask the OS for memory for the linker, 0 ==> off
144 145
    } deriving ( Show -- ^ @since 4.8.0.0
               )
146 147 148

-- | Flags to control debugging output & extra checking in various
-- subsystems.
149 150
--
-- @since 4.8.0.0
151
data DebugFlags = DebugFlags
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    { scheduler   :: Bool -- ^ @s@
    , interpreter :: Bool -- ^ @i@
    , weak        :: Bool -- ^ @w@
    , gccafs      :: Bool -- ^ @G@
    , gc          :: Bool -- ^ @g@
    , block_alloc :: Bool -- ^ @b@
    , sanity      :: Bool -- ^ @S@
    , stable      :: Bool -- ^ @t@
    , prof        :: Bool -- ^ @p@
    , linker      :: Bool -- ^ @l@ the object linker
    , apply       :: Bool -- ^ @a@
    , stm         :: Bool -- ^ @m@
    , squeeze     :: Bool -- ^ @z@ stack squeezing & lazy blackholing
    , hpc         :: Bool -- ^ @c@ coverage
    , sparks      :: Bool -- ^ @r@
167 168
    } deriving ( Show -- ^ @since 4.8.0.0
               )
169

170 171
-- | Should the RTS produce a cost-center summary?
--
172
-- @since 4.8.2.0
173 174 175 176 177
data DoCostCentres
    = CostCentresNone
    | CostCentresSummary
    | CostCentresVerbose
    | CostCentresAll
Ben Gamari's avatar
Ben Gamari committed
178
    | CostCentresJSON
179 180
    deriving ( Show -- ^ @since 4.8.0.0
             )
181

182
-- | @since 4.8.0.0
183 184 185 186 187
instance Enum DoCostCentres where
    fromEnum CostCentresNone    = #{const COST_CENTRES_NONE}
    fromEnum CostCentresSummary = #{const COST_CENTRES_SUMMARY}
    fromEnum CostCentresVerbose = #{const COST_CENTRES_VERBOSE}
    fromEnum CostCentresAll     = #{const COST_CENTRES_ALL}
Ben Gamari's avatar
Ben Gamari committed
188
    fromEnum CostCentresJSON    = #{const COST_CENTRES_JSON}
189 190 191 192 193

    toEnum #{const COST_CENTRES_NONE}    = CostCentresNone
    toEnum #{const COST_CENTRES_SUMMARY} = CostCentresSummary
    toEnum #{const COST_CENTRES_VERBOSE} = CostCentresVerbose
    toEnum #{const COST_CENTRES_ALL}     = CostCentresAll
Ben Gamari's avatar
Ben Gamari committed
194
    toEnum #{const COST_CENTRES_JSON}    = CostCentresJSON
Eric Seidel's avatar
Eric Seidel committed
195
    toEnum e = errorWithoutStackTrace ("invalid enum for DoCostCentres: " ++ show e)
196

197 198 199
-- | Parameters pertaining to the cost-center profiler.
--
-- @since 4.8.0.0
200 201 202 203
data CCFlags = CCFlags
    { doCostCentres :: DoCostCentres
    , profilerTicks :: Int
    , msecsPerTick  :: Int
204 205
    } deriving ( Show -- ^ @since 4.8.0.0
               )
206

207 208
-- | What sort of heap profile are we collecting?
--
209
-- @since 4.8.2.0
210 211 212 213 214 215 216 217 218
data DoHeapProfile
    = NoHeapProfiling
    | HeapByCCS
    | HeapByMod
    | HeapByDescr
    | HeapByType
    | HeapByRetainer
    | HeapByLDV
    | HeapByClosureType
219 220
    deriving ( Show -- ^ @since 4.8.0.0
             )
221

222
-- | @since 4.8.0.0
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
instance Enum DoHeapProfile where
    fromEnum NoHeapProfiling   = #{const NO_HEAP_PROFILING}
    fromEnum HeapByCCS         = #{const HEAP_BY_CCS}
    fromEnum HeapByMod         = #{const HEAP_BY_MOD}
    fromEnum HeapByDescr       = #{const HEAP_BY_DESCR}
    fromEnum HeapByType        = #{const HEAP_BY_TYPE}
    fromEnum HeapByRetainer    = #{const HEAP_BY_RETAINER}
    fromEnum HeapByLDV         = #{const HEAP_BY_LDV}
    fromEnum HeapByClosureType = #{const HEAP_BY_CLOSURE_TYPE}

    toEnum #{const NO_HEAP_PROFILING}    = NoHeapProfiling
    toEnum #{const HEAP_BY_CCS}          = HeapByCCS
    toEnum #{const HEAP_BY_MOD}          = HeapByMod
    toEnum #{const HEAP_BY_DESCR}        = HeapByDescr
    toEnum #{const HEAP_BY_TYPE}         = HeapByType
    toEnum #{const HEAP_BY_RETAINER}     = HeapByRetainer
    toEnum #{const HEAP_BY_LDV}          = HeapByLDV
    toEnum #{const HEAP_BY_CLOSURE_TYPE} = HeapByClosureType
Eric Seidel's avatar
Eric Seidel committed
241
    toEnum e = errorWithoutStackTrace ("invalid enum for DoHeapProfile: " ++ show e)
242

243 244 245
-- | Parameters of the cost-center profiler
--
-- @since 4.8.0.0
246 247
data ProfFlags = ProfFlags
    { doHeapProfile            :: DoHeapProfile
248 249
    , heapProfileInterval      :: RtsTime -- ^ time between samples
    , heapProfileIntervalTicks :: Word    -- ^ ticks between samples (derived)
250 251 252 253 254 255 256 257 258 259 260
    , includeTSOs              :: 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
261 262
    } deriving ( Show -- ^ @since 4.8.0.0
               )
263

264 265
-- | Is event tracing enabled?
--
266
-- @since 4.8.2.0
267
data DoTrace
268 269 270
    = TraceNone      -- ^ no tracing
    | TraceEventLog  -- ^ send tracing events to the event log
    | TraceStderr    -- ^ send tracing events to @stderr@
271 272
    deriving ( Show -- ^ @since 4.8.0.0
             )
273

274
-- | @since 4.8.0.0
275 276 277 278 279 280 281 282
instance Enum DoTrace where
    fromEnum TraceNone     = #{const TRACE_NONE}
    fromEnum TraceEventLog = #{const TRACE_EVENTLOG}
    fromEnum TraceStderr   = #{const TRACE_STDERR}

    toEnum #{const TRACE_NONE}     = TraceNone
    toEnum #{const TRACE_EVENTLOG} = TraceEventLog
    toEnum #{const TRACE_STDERR}   = TraceStderr
Eric Seidel's avatar
Eric Seidel committed
283
    toEnum e = errorWithoutStackTrace ("invalid enum for DoTrace: " ++ show e)
284

285 286 287
-- | Parameters pertaining to event tracing
--
-- @since 4.8.0.0
288 289 290 291 292 293 294 295
data TraceFlags = TraceFlags
    { tracing        :: DoTrace
    , timestamp      :: Bool -- ^ show timestamp in stderr output
    , traceScheduler :: Bool -- ^ trace scheduler events
    , traceGc        :: Bool -- ^ trace GC events
    , sparksSampled  :: Bool -- ^ trace spark events by a sampled method
    , sparksFull     :: Bool -- ^ trace spark events 100% accurately
    , user           :: Bool -- ^ trace user events (emitted from Haskell code)
296 297
    } deriving ( Show -- ^ @since 4.8.0.0
               )
298

299 300 301
-- | Parameters pertaining to ticky-ticky profiler
--
-- @since 4.8.0.0
302 303 304
data TickyFlags = TickyFlags
    { showTickyStats :: Bool
    , tickyFile      :: Maybe FilePath
305 306
    } deriving ( Show -- ^ @since 4.8.0.0
               )
307

Simon Marlow's avatar
Simon Marlow committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
-- | Parameters pertaining to parallelism
--
-- @since 4.8.0.0
data ParFlags = ParFlags
    { nCapabilities :: Word32
    , migrate :: Bool
    , maxLocalSparks :: Word32
    , parGcEnabled :: Bool
    , parGcGen :: Word32
    , parGcLoadBalancingEnabled :: Bool
    , parGcLoadBalancingGen :: Word32
    , parGcNoSyncWithIdle :: Word32
    , parGcThreads :: Word32
    , setAffinity :: Bool
    }
323 324
    deriving ( Show -- ^ @since 4.8.0.0
             )
Simon Marlow's avatar
Simon Marlow committed
325

326 327 328
-- | Parameters of the runtime system
--
-- @since 4.8.0.0
329 330 331 332 333 334 335 336 337
data RTSFlags = RTSFlags
    { gcFlags         :: GCFlags
    , concurrentFlags :: ConcFlags
    , miscFlags       :: MiscFlags
    , debugFlags      :: DebugFlags
    , costCentreFlags :: CCFlags
    , profilingFlags  :: ProfFlags
    , traceFlags      :: TraceFlags
    , tickyFlags      :: TickyFlags
Simon Marlow's avatar
Simon Marlow committed
338
    , parFlags        :: ParFlags
339 340
    } deriving ( Show -- ^ @since 4.8.0.0
               )
341

Simon Marlow's avatar
Simon Marlow committed
342
foreign import ccall "&RtsFlags" rtsFlagsPtr :: Ptr RTSFlags
343 344 345 346 347 348 349 350 351 352 353

getRTSFlags :: IO RTSFlags
getRTSFlags = do
  RTSFlags <$> getGCFlags
           <*> getConcFlags
           <*> getMiscFlags
           <*> getDebugFlags
           <*> getCCFlags
           <*> getProfFlags
           <*> getTraceFlags
           <*> getTickyFlags
Simon Marlow's avatar
Simon Marlow committed
354
           <*> getParFlags
355 356 357 358 359 360 361 362 363 364 365 366 367 368

peekFilePath :: Ptr () -> IO (Maybe FilePath)
peekFilePath ptr
  | ptr == nullPtr = return Nothing
  | otherwise      = return (Just "<filepath>")

-- | Read a NUL terminated string. Return Nothing in case of a NULL pointer.
peekCStringOpt :: Ptr CChar -> IO (Maybe String)
peekCStringOpt ptr
  | ptr == nullPtr = return Nothing
  | otherwise      = Just <$> peekCString ptr

getGCFlags :: IO GCFlags
getGCFlags = do
Simon Marlow's avatar
Simon Marlow committed
369
  let ptr = (#ptr RTS_FLAGS, GcFlags) rtsFlagsPtr
370 371
  GCFlags <$> (peekFilePath =<< #{peek GC_FLAGS, statsFile} ptr)
          <*> (toEnum . fromIntegral <$>
Simon Marlow's avatar
Simon Marlow committed
372
                (#{peek GC_FLAGS, giveStats} ptr :: IO Word32))
373 374 375 376 377 378
          <*> #{peek GC_FLAGS, maxStkSize} ptr
          <*> #{peek GC_FLAGS, initialStkSize} ptr
          <*> #{peek GC_FLAGS, stkChunkSize} ptr
          <*> #{peek GC_FLAGS, stkChunkBufferSize} ptr
          <*> #{peek GC_FLAGS, maxHeapSize} ptr
          <*> #{peek GC_FLAGS, minAllocAreaSize} ptr
Simon Marlow's avatar
Simon Marlow committed
379 380
          <*> #{peek GC_FLAGS, largeAllocLim} ptr
          <*> #{peek GC_FLAGS, nurseryChunkSize} ptr
381 382
          <*> #{peek GC_FLAGS, minOldGenSize} ptr
          <*> #{peek GC_FLAGS, heapSizeSuggestion} ptr
383 384
          <*> (toBool <$>
                (#{peek GC_FLAGS, heapSizeSuggestionAuto} ptr :: IO CBool))
385 386 387
          <*> #{peek GC_FLAGS, oldGenFactor} ptr
          <*> #{peek GC_FLAGS, pcFreeHeap} ptr
          <*> #{peek GC_FLAGS, generations} ptr
388 389 390 391
          <*> (toBool <$>
                (#{peek GC_FLAGS, squeezeUpdFrames} ptr :: IO CBool))
          <*> (toBool <$>
                (#{peek GC_FLAGS, compact} ptr :: IO CBool))
392
          <*> #{peek GC_FLAGS, compactThreshold} ptr
393 394 395 396
          <*> (toBool <$>
                (#{peek GC_FLAGS, sweep} ptr :: IO CBool))
          <*> (toBool <$>
                (#{peek GC_FLAGS, ringBell} ptr :: IO CBool))
397
          <*> #{peek GC_FLAGS, idleGCDelayTime} ptr
398 399
          <*> (toBool <$>
                (#{peek GC_FLAGS, doIdleGC} ptr :: IO CBool))
400 401
          <*> #{peek GC_FLAGS, heapBase} ptr
          <*> #{peek GC_FLAGS, allocLimitGrace} ptr
402 403
          <*> (toBool <$>
                (#{peek GC_FLAGS, numa} ptr :: IO CBool))
Simon Marlow's avatar
Simon Marlow committed
404
          <*> #{peek GC_FLAGS, numaMask} ptr
Simon Marlow's avatar
Simon Marlow committed
405 406 407 408 409 410

getParFlags :: IO ParFlags
getParFlags = do
  let ptr = (#ptr RTS_FLAGS, ParFlags) rtsFlagsPtr
  ParFlags
    <$> #{peek PAR_FLAGS, nCapabilities} ptr
411 412
    <*> (toBool <$>
          (#{peek PAR_FLAGS, migrate} ptr :: IO CBool))
Simon Marlow's avatar
Simon Marlow committed
413
    <*> #{peek PAR_FLAGS, maxLocalSparks} ptr
414 415
    <*> (toBool <$>
          (#{peek PAR_FLAGS, parGcEnabled} ptr :: IO CBool))
Simon Marlow's avatar
Simon Marlow committed
416
    <*> #{peek PAR_FLAGS, parGcGen} ptr
417 418
    <*> (toBool <$>
          (#{peek PAR_FLAGS, parGcLoadBalancingEnabled} ptr :: IO CBool))
Simon Marlow's avatar
Simon Marlow committed
419 420 421
    <*> #{peek PAR_FLAGS, parGcLoadBalancingGen} ptr
    <*> #{peek PAR_FLAGS, parGcNoSyncWithIdle} ptr
    <*> #{peek PAR_FLAGS, parGcThreads} ptr
422 423
    <*> (toBool <$>
          (#{peek PAR_FLAGS, setAffinity} ptr :: IO CBool))
424 425 426

getConcFlags :: IO ConcFlags
getConcFlags = do
Simon Marlow's avatar
Simon Marlow committed
427
  let ptr = (#ptr RTS_FLAGS, ConcFlags) rtsFlagsPtr
428 429 430 431 432
  ConcFlags <$> #{peek CONCURRENT_FLAGS, ctxtSwitchTime} ptr
            <*> #{peek CONCURRENT_FLAGS, ctxtSwitchTicks} ptr

getMiscFlags :: IO MiscFlags
getMiscFlags = do
Simon Marlow's avatar
Simon Marlow committed
433
  let ptr = (#ptr RTS_FLAGS, MiscFlags) rtsFlagsPtr
434
  MiscFlags <$> #{peek MISC_FLAGS, tickInterval} ptr
435 436 437 438 439 440
            <*> (toBool <$>
                  (#{peek MISC_FLAGS, install_signal_handlers} ptr :: IO CBool))
            <*> (toBool <$>
                  (#{peek MISC_FLAGS, install_seh_handlers} ptr :: IO CBool))
            <*> (toBool <$>
                  (#{peek MISC_FLAGS, generate_dump_file} ptr :: IO CBool))
441 442
            <*> (toBool <$>
                  (#{peek MISC_FLAGS, generate_stack_trace} ptr :: IO CBool))
443 444
            <*> (toBool <$>
                  (#{peek MISC_FLAGS, machineReadable} ptr :: IO CBool))
445 446
            <*> (toBool <$>
                  (#{peek MISC_FLAGS, internalCounters} ptr :: IO CBool))
447 448 449 450
            <*> #{peek MISC_FLAGS, linkerMemBase} ptr

getDebugFlags :: IO DebugFlags
getDebugFlags = do
Simon Marlow's avatar
Simon Marlow committed
451
  let ptr = (#ptr RTS_FLAGS, DebugFlags) rtsFlagsPtr
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
  DebugFlags <$> (toBool <$>
                   (#{peek DEBUG_FLAGS, scheduler} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, interpreter} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, weak} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, gccafs} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, gc} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, block_alloc} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, sanity} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, stable} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, prof} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, linker} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, apply} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, stm} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, squeeze} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, hpc} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek DEBUG_FLAGS, sparks} ptr :: IO CBool))
482 483 484

getCCFlags :: IO CCFlags
getCCFlags = do
Simon Marlow's avatar
Simon Marlow committed
485
  let ptr = (#ptr RTS_FLAGS, GcFlags) rtsFlagsPtr
486
  CCFlags <$> (toEnum . fromIntegral
Simon Marlow's avatar
Simon Marlow committed
487
                <$> (#{peek COST_CENTRE_FLAGS, doCostCentres} ptr :: IO Word32))
488 489 490 491 492
          <*> #{peek COST_CENTRE_FLAGS, profilerTicks} ptr
          <*> #{peek COST_CENTRE_FLAGS, msecsPerTick} ptr

getProfFlags :: IO ProfFlags
getProfFlags = do
Simon Marlow's avatar
Simon Marlow committed
493
  let ptr = (#ptr RTS_FLAGS, ProfFlags) rtsFlagsPtr
494 495 496
  ProfFlags <$> (toEnum <$> #{peek PROFILING_FLAGS, doHeapProfile} ptr)
            <*> #{peek PROFILING_FLAGS, heapProfileInterval} ptr
            <*> #{peek PROFILING_FLAGS, heapProfileIntervalTicks} ptr
497 498 499 500
            <*> (toBool <$>
                  (#{peek PROFILING_FLAGS, includeTSOs} ptr :: IO CBool))
            <*> (toBool <$>
                  (#{peek PROFILING_FLAGS, showCCSOnException} ptr :: IO CBool))
501 502 503 504 505 506 507 508 509 510 511 512
            <*> #{peek PROFILING_FLAGS, maxRetainerSetSize} ptr
            <*> #{peek PROFILING_FLAGS, ccsLength} ptr
            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, modSelector} ptr)
            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, descrSelector} ptr)
            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, typeSelector} ptr)
            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, ccSelector} ptr)
            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, ccsSelector} ptr)
            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, retainerSelector} ptr)
            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, bioSelector} ptr)

getTraceFlags :: IO TraceFlags
getTraceFlags = do
Simon Marlow's avatar
Simon Marlow committed
513
  let ptr = (#ptr RTS_FLAGS, TraceFlags) rtsFlagsPtr
514 515
  TraceFlags <$> (toEnum . fromIntegral
                   <$> (#{peek TRACE_FLAGS, tracing} ptr :: IO CInt))
516 517 518 519 520 521 522 523 524 525 526 527
             <*> (toBool <$>
                   (#{peek TRACE_FLAGS, timestamp} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek TRACE_FLAGS, scheduler} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek TRACE_FLAGS, gc} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek TRACE_FLAGS, sparks_sampled} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek TRACE_FLAGS, sparks_full} ptr :: IO CBool))
             <*> (toBool <$>
                   (#{peek TRACE_FLAGS, user} ptr :: IO CBool))
528 529 530

getTickyFlags :: IO TickyFlags
getTickyFlags = do
Simon Marlow's avatar
Simon Marlow committed
531
  let ptr = (#ptr RTS_FLAGS, TickyFlags) rtsFlagsPtr
532 533
  TickyFlags <$> (toBool <$>
                   (#{peek TICKY_FLAGS, showTickyStats} ptr :: IO CBool))
534
             <*> (peekFilePath =<< #{peek TICKY_FLAGS, tickyFile} ptr)