Search code examples
haskellghccabal

How to build with profiling in Stack?


I am struggling with building an app with profiling, because I need stack traces.

$ stack new prof 
$ cd prof
$ stack build --profile --executable-profiling --library-profiling 
$ stack exec prof-exe +RTS -p
stack: the flag -p requires the program to be built with -prof

$ stack --version
Version 2.7.1, Git revision 8afe0c2932716b0441cf4440d6942c59568b6b19 x86_64 hpack-0.34.4

ghc 8.10.7


Solution

  • Stack itself is written in Haskell and therefore it accepts the +RTS -p parameter too. To pass the +RTS -p to your prof-exe you should use the -- separator:

    stack exec prof-exe -- +RTS -p
    

    However, I believe the run command should be used for running executables, and I think you need to add the --profile flag there too. The command that works for me is:

    stack run --profile prof-exe -- +RTS -p