diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2017-11-21 14:27:51 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-11-21 14:28:01 -0500 |
commit | 0b20d9c51d627febab34b826fccf522ca8bac323 (patch) | |
tree | 44a21eb0cbb4fe52646f7b03ff6e431b3cd5acc1 | |
parent | 66d17995a057c313fb22b0660a6327bd41afea4a (diff) | |
download | haskell-0b20d9c51d627febab34b826fccf522ca8bac323.tar.gz |
base: Document GHC.Stack.CCS internals
Reviewers: hvr
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D4204
-rw-r--r-- | compiler/prelude/primops.txt.pp | 2 | ||||
-rw-r--r-- | libraries/base/GHC/Stack/CCS.hsc | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp index 952d4746ff..fe33ead294 100644 --- a/compiler/prelude/primops.txt.pp +++ b/compiler/prelude/primops.txt.pp @@ -2836,7 +2836,7 @@ primop GetCurrentCCSOp "getCurrentCCS#" GenPrimOp a -> State# s -> (# State# s, Addr# #) { Returns the current {\tt CostCentreStack} (value is {\tt NULL} if not profiling). Takes a dummy argument which can be used to - avoid the call to {\tt getCCCS\#} being floated out by the + avoid the call to {\tt getCurrentCCS\#} being floated out by the simplifier, which would result in an uninformative stack ("CAF"). } diff --git a/libraries/base/GHC/Stack/CCS.hsc b/libraries/base/GHC/Stack/CCS.hsc index 51eb6244a4..ba384a13b4 100644 --- a/libraries/base/GHC/Stack/CCS.hsc +++ b/libraries/base/GHC/Stack/CCS.hsc @@ -48,34 +48,50 @@ import GHC.List ( concatMap, reverse ) #define PROFILING #include "Rts.h" +-- | A cost-centre stack from GHC's cost-center profiler. data CostCentreStack + +-- | A cost-centre from GHC's cost-center profiler. data CostCentre +-- | Returns the current 'CostCentreStack' (value is @nullPtr@ if the current +-- program was not compiled with profiling support). Takes a dummy argument +-- which can be used to avoid the call to @getCurrentCCS@ being floated out by +-- the simplifier, which would result in an uninformative stack ("CAF"). getCurrentCCS :: dummy -> IO (Ptr CostCentreStack) getCurrentCCS dummy = IO $ \s -> case getCurrentCCS## dummy s of (## s', addr ##) -> (## s', Ptr addr ##) +-- | Get the 'CostCentreStack' associated with the given value. getCCSOf :: a -> IO (Ptr CostCentreStack) getCCSOf obj = IO $ \s -> case getCCSOf## obj s of (## s', addr ##) -> (## s', Ptr addr ##) +-- | Run a computation with an empty cost-center stack. For example, this is +-- used by the interpreter to run an interpreted computation without the call +-- stack showing that it was invoked from GHC. clearCCS :: IO a -> IO a clearCCS (IO m) = IO $ \s -> clearCCS## m s +-- | Get the 'CostCentre' at the head of a 'CostCentreStack'. ccsCC :: Ptr CostCentreStack -> IO (Ptr CostCentre) ccsCC p = (# peek CostCentreStack, cc) p +-- | Get the tail of a 'CostCentreStack'. ccsParent :: Ptr CostCentreStack -> IO (Ptr CostCentreStack) ccsParent p = (# peek CostCentreStack, prevStack) p +-- | Get the label of a 'CostCentre'. ccLabel :: Ptr CostCentre -> IO CString ccLabel p = (# peek CostCentre, label) p +-- | Get the module of a 'CostCentre'. ccModule :: Ptr CostCentre -> IO CString ccModule p = (# peek CostCentre, module) p +-- | Get the source span of a 'CostCentre'. ccSrcSpan :: Ptr CostCentre -> IO CString ccSrcSpan p = (# peek CostCentre, srcloc) p @@ -92,6 +108,7 @@ ccSrcSpan p = (# peek CostCentre, srcloc) p currentCallStack :: IO [String] currentCallStack = ccsToStrings =<< getCurrentCCS () +-- | Format a 'CostCentreStack' as a list of lines. ccsToStrings :: Ptr CostCentreStack -> IO [String] ccsToStrings ccs0 = go ccs0 [] where |