Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • cabal-dev install --config=./cabal-dev.config, where cabal-dev.config is

    library-profiling: True
    executable-profiling: True
    package-db: /home/christopher/school/senior/senior_thesis/windingnumber_integration/cabal-dev/packages-7.6.1.conf
    local-repo: /home/christopher/school/senior/senior_thesis/windingnumber_integration/cabal-dev/packages
    user-install: False
    remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive
    remote-repo-cache: /home/christopher/.cabal/packages
    optimization: True
    build-summary: /home/christopher/school/senior/senior_thesis/windingnumber_integration/cabal-dev/logs/build.log
    remote-build-reporting: anonymous
    optimization: True
    
    install-dirs user
      prefix: /home/christopher/school/senior/senior_thesis/windingnumber_integration/cabal-dev/
    install-dirs global
    
  • cabal-dev install --cabal-install-arg='--enable-library-profiling' --cabal-install-arg='--enable-executable-profiling'

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

like image 865
Christopher White Avatar asked Jan 01 '13 17:01

Christopher White


Video Answer


1 Answers

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.

like image 164
Mikhail Glushenkov Avatar answered Oct 20 '22 00:10

Mikhail Glushenkov