Christopher White
Christopher White

Reputation: 185

How do I enable profiling in a cabal-dev installation?

I'm trying to profile a program windingnumber which has some few dependencies. Per Aleksander Dmitrov's answer in Profile Haskell without installing installing profiling libraries for all dependencies, I'm using cabal-dev to (attempt to) build all of the dependencies with profiling enabled. I have tried

(with rm -rf cabal-dev in between, of course, to start from a pristine environment.) In each case, I get:

arch% cabal-dev/bin/windingnumber +RTS -p
cabal-dev/bin/windingnumber +RTS -p
windingnumber: the flag -p requires the program to be built with -prof
windingnumber: 
windingnumber: Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>
<snip>

---i.e., profiling is not enabled. How can I enable it?

ETA Solution: add -prof to ghc-options in the .cabal file for the project did it. Apparently setting `executable-profiling: True" in the cabal-dev config didn't do it. Thanks to Daniel Fischer.

Upvotes: 9

Views: 2511

Answers (1)

Mikhail Glushenkov
Mikhail Glushenkov

Reputation: 15038

It looks like cabal-dev rewrites ./cabal-dev/cabal.config every time it runs. However, you can edit ~/.cabal/share/cabal-dev-$VERSION/admin/cabal-config.in to set the default values:

$  vim ~/.cabal/share/cabal-dev-0.9.1/admin/cabal-config.in
# Set executable-profiling and library-profiling to True
$ cabal unpack ghc-core
$ cd ghc-core-0.5.6
$ cabal-dev install --dependencies-only
$ cabal-dev configure -p
$ cabal-dev build
$ ./dist/build/ghc-core/ghc-core +RTS -p
# much success

If you don't want to enable profiling for all projects managed with cabal-dev, use the --extra-config-file option (--config just sets the location of the auto-generated config file):

$ cat cabal-dev.config 
executable-profiling: True
library-profiling: True
$ cabal-dev --extra-config-file='./cabal-dev.config' install
$ ./cabal-dev/bin/ghc-core +RTS -p
# success

Using the ghc-options field in the .cabal file for enabling profiling is not recommended - you don't want everyone who installs your package from Hackage to build with profiling. Use cabal-dev configure -p --ghc-options="-fprof-auto" to enable profiling for the current build only.

Upvotes: 4

Related Questions