0

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

Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49

1 Answers1

1

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
Noughtmare
  • 9,410
  • 1
  • 12
  • 38
  • run commands runs, but there is no stack trace I guess because dependency directory is not rebuild with profiling – Daniil Iaitskov Oct 19 '21 at 15:49
  • 1
    I believe you need to also add [the `-xc` RTS option](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/runtime_control.html#rts-flag--xc) to get stack traces. – Noughtmare Oct 19 '21 at 15:58