@hackage ghc-stack-profiler0.1.0.0

RTS Callstack profiler for GHC.

  • Installation

  • Dependencies (10)

  • Dependents (0)

  • Package Flags

      use-ghc-trace-events
       (on by default)

      Use the package 'ghc-trace-events'. Disabling this flag makes it much easier to use ghc-stack-profiler on the ghc codebase, as we don't have to package 'ghc-trace-events' for hadrian. Always enabled on GHC <9.12.

RTS Callstack profiler for GHC.

The main idea is to periodically sample the Haskell callstack and use IPE and stack annotation information in order to understand the source locations which correspond to the stack frames. To profile a program it needs to be compiled and instrumented with the 'ghc-stack-profiler' package via:

import GHC.Stack.Profiler.Sampler

main :: IO ()
main = withStackProfilerForMyThread (SampleIntervalMs 10) $ do
    ...

This will spawn a profiling thread that will periodically take a snapshot of the current RTS callstack of your program and serialises it to the eventlog.

To improve readability of the profile, compile the program with -finfo-table-map and -fdistinct-constructor-tables. Using cabal, this can be achieved with an appropriate cabal.project file:

packages: ...

...

package *
    ghc-options: -finfo-table-map -fdistinct-constructor-tables

To emit the eventlog messages by the profiler, you need to run your program with the -l RTS flag, for example via:

./<program> ... +RTS -l -RTS

This will write out an eventlog to <program>.eventlog which can be transformed for speedscope.app via the script 'ghc-stack-profiler-speedscope'.

ghc-stack-profiler-speedscope <program>.eventlog

The resulting profile <program>.eventlog.json can be viewed and further analysed in speedscope.app.

Note that the results are affected by compilation optimisation options, such as -fno-omit-yields.