Profiling an executable with cabal
Asked Answered
A

1

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?

Aggrieved answered 8/4, 2014 at 15:57 Comment(5)
Did you try this:cabal run realtra-benchmark +RTS -p -RTSDarlenedarline
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.Aggrieved
Try cabal run realtra-benchmark -- +RTS -p. My guess is that +RTS gets interpreted as argument to the cabal executable itself.Replay
Or maybe cabal run realtra-benchmark +RTS --RTS -- +RTS -p.Replay
@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.Aggrieved
R
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).

Replay answered 9/4, 2014 at 16:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.