Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling an executable with cabal

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?

like image 816
mhwombat Avatar asked Apr 08 '14 15:04

mhwombat


1 Answers

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

like image 187
Mikhail Glushenkov Avatar answered Nov 05 '22 23:11

Mikhail Glushenkov