7

After some of the recent-ish changes to cabal, I am totally confused as to how to profile an executable. In ~/.cabal/config, I have profiling enabled:

amy@wombat$ grep prof ~/.cabal/config
library-profiling: True
executable-profiling: True

But if I try to run my executable with profiling, I get...

amy@wombat$ cabal run realtra-benchmark +RTS -p
cabal: the flag -p requires the program to be built with -prof
cabal: 
cabal: Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>
<snip>

I get the same response if I try to bypass cabal: ./dist/dist-sandbox-c8599c64/build/realtra-benchmark/realtra-benchmark +RTS -p.

Of course, adding the -prof flag to GHC-Options: in my cabal file won't work:

amy@wombat$ cabal build --ghc-options=-Werror && cabal test && cabal install
./realtra.cabal has been changed. Re-configuring with most recently used
options. If this fails, please run configure manually.
Resolving dependencies...
Configuring creatur-realtra-1.0.8...
Warning: 'ghc-options: -prof' is not necessary and will lead to problems when
used on a library. Use the configure flag --enable-library-profiling and/or
--enable-executable-profiling.

I figure I shouldn't have to add those flags since they're in my config file, but just in case, I try it:

amy@wombat$ cabal configure --enable-executable-profiling --enable-library-profiling
Resolving dependencies...
Configuring creatur-realtra-1.0.8...
amy@wombat$ cabal build --ghc-options=-Werror && cabal test && cabal install
<snip>
amy@wombat$ cabal run realtra-benchmark +RTS -p
cabal: the flag -p requires the program to be built with -prof
cabal: 
cabal: Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>
<snip>

What am I missing?

mhwombat
  • 8,026
  • 28
  • 53
  • Did you try this:`cabal run realtra-benchmark +RTS -p -RTS` – Sibi Apr 08 '14 at 16:25
  • 1
    The `-RTS` flag is only needed when you're following with non-runtime flags. But just to make sure, I tried it just now with `-RTS` at the end, and got the same error. – mhwombat Apr 08 '14 at 16:27
  • 2
    Try `cabal run realtra-benchmark -- +RTS -p`. My guess is that `+RTS` gets interpreted as argument to the `cabal` executable itself. – Mikhail Glushenkov Apr 08 '14 at 17:38
  • 1
    Or maybe `cabal run realtra-benchmark +RTS --RTS -- +RTS -p`. – Mikhail Glushenkov Apr 08 '14 at 17:42
  • @Mikhail, both of your suggestions worked. If you want to add this as an answer, I'll accept it. I suspect this info will help others as well, because I googled (or rather, DuckDuckGo'd) extensively for an answer. – mhwombat Apr 09 '14 at 10:18

1 Answers1

7

The problem is that the +RTS -p bit gets interpreted as arguments to the cabal executable itself. To forward these arguments to the realtra-benchmark executable, use cabal run realtra-benchmark -- +RTS -p. In general, you should always put a double dash before the arguments that you want to be forwarded when you're using cabal run (at least until this issue is fixed).

Mikhail Glushenkov
  • 14,928
  • 3
  • 52
  • 65