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?

share|improve this question
    
Did you try this:cabal run realtra-benchmark +RTS -p -RTS – Sibi Apr 8 '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 8 '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 8 '14 at 17:38
1  
Or maybe cabal run realtra-benchmark +RTS --RTS -- +RTS -p. – Mikhail Glushenkov Apr 8 '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 9 '14 at 10:18
up vote 7 down vote accepted

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.