{-# OPTIONS_GHC -optc-DPROFILING #-}
{-# LINE 1 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE MagicHash #-}
module GHC.Exts.Heap.ProfInfo.PeekProfInfo_ProfilingEnabled(
peekStgTSOProfInfo
, peekTopCCS
) where
{-# LINE 10 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import Foreign
import Foreign.C.String
import GHC.Exts
import GHC.Exts.Heap.ProfInfo.Types
import Prelude
type AddressSet = IntSet
type AddressMap = IntMap
peekStgTSOProfInfo :: (Ptr b -> IO (Maybe CostCentreStack)) -> Ptr a -> IO (Maybe StgTSOProfInfo)
peekStgTSOProfInfo :: forall b a.
(Ptr b -> IO (Maybe CostCentreStack))
-> Ptr a -> IO (Maybe StgTSOProfInfo)
peekStgTSOProfInfo Ptr b -> IO (Maybe CostCentreStack)
decodeCCS Ptr a
tsoPtr = do
Ptr b
cccs_ptr <- forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr a
tsoPtr Int
cccsOffset
Maybe CostCentreStack
cccs' <- Ptr b -> IO (Maybe CostCentreStack)
decodeCCS Ptr b
cccs_ptr
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just StgTSOProfInfo {
cccs :: Maybe CostCentreStack
cccs = Maybe CostCentreStack
cccs'
}
peekTopCCS :: Ptr b -> IO (Maybe CostCentreStack)
peekTopCCS :: forall b. Ptr b -> IO (Maybe CostCentreStack)
peekTopCCS Ptr b
cccs_ptr = do
IORef (IntMap CostCentre)
costCenterCacheRef <- forall a. a -> IO (IORef a)
newIORef forall a. IntMap a
IntMap.empty
forall costCentreStack.
AddressSet
-> IORef (IntMap CostCentre)
-> Ptr costCentreStack
-> IO (Maybe CostCentreStack)
peekCostCentreStack AddressSet
IntSet.empty IORef (IntMap CostCentre)
costCenterCacheRef Ptr b
cccs_ptr
cccsOffset :: Int
cccsOffset :: Int
cccsOffset = (Int
112) forall a. Num a => a -> a -> a
+ ((Int
24))
{-# LINE 53 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
peekCostCentreStack
:: AddressSet
-> IORef (AddressMap CostCentre)
-> Ptr costCentreStack
-> IO (Maybe CostCentreStack)
peekCostCentreStack :: forall costCentreStack.
AddressSet
-> IORef (IntMap CostCentre)
-> Ptr costCentreStack
-> IO (Maybe CostCentreStack)
peekCostCentreStack AddressSet
_ IORef (IntMap CostCentre)
_ Ptr costCentreStack
ptr | Ptr costCentreStack
ptr forall a. Eq a => a -> a -> Bool
== forall a. Ptr a
nullPtr = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
peekCostCentreStack AddressSet
loopBreakers IORef (IntMap CostCentre)
_ Ptr costCentreStack
ptr | Int -> AddressSet -> Bool
IntSet.member (forall a. Ptr a -> Int
ptrToInt Ptr costCentreStack
ptr) AddressSet
loopBreakers = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
peekCostCentreStack AddressSet
loopBreakers IORef (IntMap CostCentre)
costCenterCacheRef Ptr costCentreStack
ptr = do
Int
ccs_ccsID' <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
0)) Ptr costCentreStack
ptr
{-# LINE 63 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Ptr Any
ccs_cc_ptr <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
8)) Ptr costCentreStack
ptr
{-# LINE 64 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
CostCentre
ccs_cc' <- forall costCentre.
IORef (IntMap CostCentre) -> Ptr costCentre -> IO CostCentre
peekCostCentre IORef (IntMap CostCentre)
costCenterCacheRef Ptr Any
ccs_cc_ptr
Ptr Any
ccs_prevStack_ptr <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
16)) Ptr costCentreStack
ptr
{-# LINE 66 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
let loopBreakers' :: AddressSet
loopBreakers' = (Int -> AddressSet -> AddressSet
IntSet.insert Int
ptrAsInt AddressSet
loopBreakers)
Maybe CostCentreStack
ccs_prevStack' <- forall costCentreStack.
AddressSet
-> IORef (IntMap CostCentre)
-> Ptr costCentreStack
-> IO (Maybe CostCentreStack)
peekCostCentreStack AddressSet
loopBreakers' IORef (IntMap CostCentre)
costCenterCacheRef Ptr Any
ccs_prevStack_ptr
Ptr Any
ccs_indexTable_ptr <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
24)) Ptr costCentreStack
ptr
{-# LINE 69 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Maybe IndexTable
ccs_indexTable' <- forall indexTable.
AddressSet
-> IORef (IntMap CostCentre)
-> Ptr indexTable
-> IO (Maybe IndexTable)
peekIndexTable AddressSet
loopBreakers' IORef (IntMap CostCentre)
costCenterCacheRef Ptr Any
ccs_indexTable_ptr
Ptr Any
ccs_root_ptr <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
32)) Ptr costCentreStack
ptr
{-# LINE 71 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Maybe CostCentreStack
ccs_root' <- forall costCentreStack.
AddressSet
-> IORef (IntMap CostCentre)
-> Ptr costCentreStack
-> IO (Maybe CostCentreStack)
peekCostCentreStack AddressSet
loopBreakers' IORef (IntMap CostCentre)
costCenterCacheRef Ptr Any
ccs_root_ptr
Word
ccs_depth' <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
40)) Ptr costCentreStack
ptr
{-# LINE 73 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Word64
ccs_scc_count' <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
48)) Ptr costCentreStack
ptr
{-# LINE 74 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Word
ccs_selected' <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
56)) Ptr costCentreStack
ptr
{-# LINE 75 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Word
ccs_time_ticks' <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
64)) Ptr costCentreStack
ptr
{-# LINE 76 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Word64
ccs_mem_alloc' <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
72)) Ptr costCentreStack
ptr
{-# LINE 77 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Word64
ccs_inherited_alloc' <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
80)) Ptr costCentreStack
ptr
{-# LINE 78 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Word
ccs_inherited_ticks' <- ((\Ptr costCentreStack
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentreStack
hsc_ptr Int
88)) Ptr costCentreStack
ptr
{-# LINE 79 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just CostCentreStack {
ccs_ccsID :: Int
ccs_ccsID = Int
ccs_ccsID',
ccs_cc :: CostCentre
ccs_cc = CostCentre
ccs_cc',
ccs_prevStack :: Maybe CostCentreStack
ccs_prevStack = Maybe CostCentreStack
ccs_prevStack',
ccs_indexTable :: Maybe IndexTable
ccs_indexTable = Maybe IndexTable
ccs_indexTable',
ccs_root :: Maybe CostCentreStack
ccs_root = Maybe CostCentreStack
ccs_root',
ccs_depth :: Word
ccs_depth = Word
ccs_depth',
ccs_scc_count :: Word64
ccs_scc_count = Word64
ccs_scc_count',
ccs_selected :: Word
ccs_selected = Word
ccs_selected',
ccs_time_ticks :: Word
ccs_time_ticks = Word
ccs_time_ticks',
ccs_mem_alloc :: Word64
ccs_mem_alloc = Word64
ccs_mem_alloc',
ccs_inherited_alloc :: Word64
ccs_inherited_alloc = Word64
ccs_inherited_alloc',
ccs_inherited_ticks :: Word
ccs_inherited_ticks = Word
ccs_inherited_ticks'
}
where
ptrAsInt :: Int
ptrAsInt = forall a. Ptr a -> Int
ptrToInt Ptr costCentreStack
ptr
peekCostCentre :: IORef (AddressMap CostCentre) -> Ptr costCentre -> IO CostCentre
peekCostCentre :: forall costCentre.
IORef (IntMap CostCentre) -> Ptr costCentre -> IO CostCentre
peekCostCentre IORef (IntMap CostCentre)
costCenterCacheRef Ptr costCentre
ptr = do
IntMap CostCentre
costCenterCache <- forall a. IORef a -> IO a
readIORef IORef (IntMap CostCentre)
costCenterCacheRef
case forall a. Int -> IntMap a -> Maybe a
IntMap.lookup Int
ptrAsInt IntMap CostCentre
costCenterCache of
(Just CostCentre
a) -> forall (m :: * -> *) a. Monad m => a -> m a
return CostCentre
a
Maybe CostCentre
Nothing -> do
Int
cc_ccID' <- ((\Ptr costCentre
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentre
hsc_ptr Int
0)) Ptr costCentre
ptr
{-# LINE 104 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
CString
cc_label_ptr <- ((\Ptr costCentre
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentre
hsc_ptr Int
8)) Ptr costCentre
ptr
{-# LINE 105 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
String
cc_label' <- CString -> IO String
peekCString CString
cc_label_ptr
CString
cc_module_ptr <- ((\Ptr costCentre
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentre
hsc_ptr Int
16)) Ptr costCentre
ptr
{-# LINE 107 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
String
cc_module' <- CString -> IO String
peekCString CString
cc_module_ptr
CString
cc_srcloc_ptr <- ((\Ptr costCentre
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentre
hsc_ptr Int
24)) Ptr costCentre
ptr
{-# LINE 109 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Maybe String
cc_srcloc' <- do
if CString
cc_srcloc_ptr forall a. Eq a => a -> a -> Bool
== forall a. Ptr a
nullPtr then
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
else
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Maybe a
Just (CString -> IO String
peekCString CString
cc_srcloc_ptr)
Word64
cc_mem_alloc' <- ((\Ptr costCentre
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentre
hsc_ptr Int
32)) Ptr costCentre
ptr
{-# LINE 115 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Word
cc_time_ticks' <- ((\Ptr costCentre
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentre
hsc_ptr Int
40)) Ptr costCentre
ptr
{-# LINE 116 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Bool
cc_is_caf' <- ((\Ptr costCentre
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentre
hsc_ptr Int
48)) Ptr costCentre
ptr
{-# LINE 117 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Ptr Any
cc_link_ptr <- ((\Ptr costCentre
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr costCentre
hsc_ptr Int
56)) Ptr costCentre
ptr
{-# LINE 118 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Maybe CostCentre
cc_link' <- if Ptr Any
cc_link_ptr forall a. Eq a => a -> a -> Bool
== forall a. Ptr a
nullPtr then
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
else
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Maybe a
Just (forall costCentre.
IORef (IntMap CostCentre) -> Ptr costCentre -> IO CostCentre
peekCostCentre IORef (IntMap CostCentre)
costCenterCacheRef Ptr Any
cc_link_ptr)
let result :: CostCentre
result = CostCentre {
cc_ccID :: Int
cc_ccID = Int
cc_ccID',
cc_label :: String
cc_label = String
cc_label',
cc_module :: String
cc_module = String
cc_module',
cc_srcloc :: Maybe String
cc_srcloc = Maybe String
cc_srcloc',
cc_mem_alloc :: Word64
cc_mem_alloc = Word64
cc_mem_alloc',
cc_time_ticks :: Word
cc_time_ticks = Word
cc_time_ticks',
cc_is_caf :: Bool
cc_is_caf = Bool
cc_is_caf',
cc_link :: Maybe CostCentre
cc_link = Maybe CostCentre
cc_link'
}
forall a. IORef a -> a -> IO ()
writeIORef IORef (IntMap CostCentre)
costCenterCacheRef (forall a. Int -> a -> IntMap a -> IntMap a
IntMap.insert Int
ptrAsInt CostCentre
result IntMap CostCentre
costCenterCache)
forall (m :: * -> *) a. Monad m => a -> m a
return CostCentre
result
where
ptrAsInt :: Int
ptrAsInt = forall a. Ptr a -> Int
ptrToInt Ptr costCentre
ptr
peekIndexTable :: AddressSet -> IORef (AddressMap CostCentre) -> Ptr indexTable -> IO (Maybe IndexTable)
peekIndexTable :: forall indexTable.
AddressSet
-> IORef (IntMap CostCentre)
-> Ptr indexTable
-> IO (Maybe IndexTable)
peekIndexTable AddressSet
_ IORef (IntMap CostCentre)
_ Ptr indexTable
ptr | Ptr indexTable
ptr forall a. Eq a => a -> a -> Bool
== forall a. Ptr a
nullPtr = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
peekIndexTable AddressSet
loopBreakers IORef (IntMap CostCentre)
costCenterCacheRef Ptr indexTable
ptr = do
Ptr Any
it_cc_ptr <- ((\Ptr indexTable
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr indexTable
hsc_ptr Int
0)) Ptr indexTable
ptr
{-# LINE 144 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
CostCentre
it_cc' <- forall costCentre.
IORef (IntMap CostCentre) -> Ptr costCentre -> IO CostCentre
peekCostCentre IORef (IntMap CostCentre)
costCenterCacheRef Ptr Any
it_cc_ptr
Ptr Any
it_ccs_ptr <- ((\Ptr indexTable
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr indexTable
hsc_ptr Int
8)) Ptr indexTable
ptr
{-# LINE 146 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Maybe CostCentreStack
it_ccs' <- forall costCentreStack.
AddressSet
-> IORef (IntMap CostCentre)
-> Ptr costCentreStack
-> IO (Maybe CostCentreStack)
peekCostCentreStack AddressSet
loopBreakers IORef (IntMap CostCentre)
costCenterCacheRef Ptr Any
it_ccs_ptr
Ptr Any
it_next_ptr <- ((\Ptr indexTable
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr indexTable
hsc_ptr Int
16)) Ptr indexTable
ptr
{-# LINE 148 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
Maybe IndexTable
it_next' <- forall indexTable.
AddressSet
-> IORef (IntMap CostCentre)
-> Ptr indexTable
-> IO (Maybe IndexTable)
peekIndexTable AddressSet
loopBreakers IORef (IntMap CostCentre)
costCenterCacheRef Ptr Any
it_next_ptr
Bool
it_back_edge' <- ((\Ptr indexTable
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr indexTable
hsc_ptr Int
24)) Ptr indexTable
ptr
{-# LINE 150 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just IndexTable {
it_cc :: CostCentre
it_cc = CostCentre
it_cc',
it_ccs :: Maybe CostCentreStack
it_ccs = Maybe CostCentreStack
it_ccs',
it_next :: Maybe IndexTable
it_next = Maybe IndexTable
it_next',
it_back_edge :: Bool
it_back_edge = Bool
it_back_edge'
}
ptrToInt :: Ptr a -> Int
ptrToInt :: forall a. Ptr a -> Int
ptrToInt (Ptr Addr#
a#) = Int# -> Int
I# (Addr# -> Int#
addr2Int# Addr#
a#)
{-# LINE 174 "libraries/ghc-heap/GHC/Exts/Heap/ProfInfo/PeekProfInfo_ProfilingEnabled.hsc" #-}