6

I'm trying to do some profiling using stack --enable-profiling and I'm a bit confused about what's happening exactly.

Do I need to use also --enable-library ?. Also, is it build in a separate directory ?What happend next I build it, will remember that am I in profiling mode or do I have to use the --enable-profiling all the time.

It is generally recommended to profile in conjonction with the -O2 option. Does --enable-profiling set it automatically ?

mb14
  • 22,276
  • 7
  • 60
  • 102

1 Answers1

5

Stack support for enabling profiling works great, example:

stack build --profile --executable-profiling --library-profiling
stack exec -- example <your prog args> +RTS -p

Then see example.prof for the default output.

Update: the stack support pointed me to the right correct for exec, see https://github.com/commercialhaskell/stack/issues/1655

axm
  • 281
  • 2
  • 6
  • does this set `-O2` ? how – mb14 Jan 14 '16 at 21:18
  • No - I would not think so - why would it? I would set this in the .cabal file, but there is probably a stack option for that, too. – axm Apr 20 '16 at 19:06
  • Because it's a good practice to profile optimised version of the code. I don't want it in the cabal file because it don't need it when I am developing. – mb14 Apr 21 '16 at 14:58
  • Point taken. In the [docs](http://docs.haskellstack.org/en/stable/GUIDE/#exec) are examples for setting ghc options on the command line. This should override the .cabal settings. I have not tested that though. – axm Apr 23 '16 at 17:52
  • 1
    FYI looks like the answer is a little redundant: `stack build --profile` implies `--enable-library-profiling` and `--enable-executable-profiling`: https://docs.haskellstack.org/en/stable/GUIDE/#debugging – mhansen Nov 28 '20 at 01:27