46

I want to compile my program with profiling, so I run:

$ cabal configure --enable-executable-profiling
...
$ cabal build
...
    Could not find module 'Graphics.UI.GLUT':
      Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'?
...
$ # indeed I have not installed the prof libs for GLUT, so..
$ cabal install -p GLUT --reinstall
...
    Could not find module 'Graphics.Rendering.OpenGL':
      Perhaps you havent installed the profiling libraries for package 'OpenGL-2.4.0.1'?
...

So, the problem is, that unlike cabal's usual welcome behavior, cabal doesn't resolve the dependencies and install them when needing profiling libraries.

I can work around it by resolving the dependencies manually (by following errors that appear after a while of compiling):

$ cabal install -p OpenGLRaw --reinstall
$ cabal install -p StateVar --reinstall
$ cabal install -p Tensor --reinstall
$ cabal install -p ObjectName --reinstall
$ cabal install -p GLURaw --reinstall
$ cabal install -p OpenGL --reinstall
$ cabal install -p GLUT --reinstall

And then repeat for my next dependency..

Is there a better way to do this? i.e do make cabal do the work on its own as it does for normal libraries?

4
  • 9
    I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling. Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled... Nov 9, 2009 at 23:48
  • @Tom Lokhorst: Thanks. Also, this seems to be the best/only answer. So if you want, you can put it down as an answer so I can accept it
    – yairchu
    Nov 10, 2009 at 15:06
  • Well, it's impolite to say no to free upvotes :-) However, I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time. Nov 10, 2009 at 17:43
  • If you're on Stack and encountering this issue, this question and its answers might help you. Apr 11, 2019 at 11:27

5 Answers 5

46

I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling.

Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled...

3
  • 7
    I imagine this a familiar routine for many people. If only there was a command to automate this otherwise laborious task e.g. cabal reinstall-all --with-library-profiling-enabled . Jul 17, 2013 at 17:47
  • Is it really needed recompiling of all libraries just to profile my application? Isn't there a way to switch faster between Fully optimized version (without profiling code inside) and Profiling one?
    – The_Ghost
    Jan 28, 2014 at 13:59
  • 3
    After weeks of frustrating reinstalls, I suggest that you completely uninstall everything after making the above update to your ~/.cabal/config. There are a few ways to do this. One is rm -rf ~/.ghc Oct 24, 2014 at 20:53
30

From a comment by Tom Lokhorst:

I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time.

For future visitors:

The task of installing profiling versions of all installed libraries has become less of a chore, cabal (cabal-install) now keeps track of what was installed using it in the world file in the .cabal directory (on linux, that would be $HOME/.cabal, on Windows something like C:\Users\%YOU%\AppData\Roaming\cabal\, on OSX ??).

So after enabling profiling in the config file (in the same directory), and clearing GHC's package database (you can find the locations of the global and user db per ghc-pkg list nonexisting; remove the cabal-installed packages from the global database with ghc-pkg unregister packagename if you have any, rename or delete the entire user db - this is necessary because the world file only tracks explicitly installed packages, not their dependencies), installing everything with profiling support should work as follows:

$ cabal install --reinstall world --dry-run

First run with --dry-run to check for problems before actually reinstalling anything. If it would reinstall boot packages like process or directory, that's a bad sign, if you don't know how to handle it, ask on the #haskell IRC channel, one of the mailing lists, or here for guidance. If it fails to find a consistent install plan due to new versions on hackage of some packages which are incompatible with each other, that can usually be solved by editing the world file and constraining allowable versions of some packages.

Then, if you are optimistic that nothing will badly break,

$ cabal install --reinstall world

and have a nice pot of tea while GHC is busy compiling.

5
  • will this actually enable profiling if set to True in config? When I do a --reinstall of existing packages it seems to require the -p flag
    – jberryman
    Jul 23, 2012 at 14:07
  • 2
    I just tried, cabal install --reinstall world did reinstall with profiling enabled. Is the line library-profiling: True perchance commented out in the config file? Jul 23, 2012 at 15:06
  • 6
    heh, thanks. I was reading the -- as a command-line flag not comment. OOOPS!
    – jberryman
    Jul 23, 2012 at 16:19
  • I have removed the db in ~usr/lib/ghc/package.conf.d and when I try to run cabal install --reinstall world and I get an error can't find a package database. Are you sure we need to delete the db?
    – Ford O.
    Aug 11, 2016 at 15:18
  • @FordO. That looks like the global package database, the user db is typically under ~/.ghc/$GHC_Version. Only the user db can be deleted, removing the entire global package database breaks your GHC. If you have a backup of the package db, reinstate that, otherwise I'm afraid you'll need to reinstall GHC. From the global db, only packages installed with cabal should be unregistered. Aug 12, 2016 at 18:44
16

Daniel Fischer's answer looks good, but for some reason my ~/.cabal/world library only contained entries for libraries directly installed, and not their dependencies.

Instead, I dumped out a list of all installed libraries using

$ ghc-pkg list > list

This lists the libraries installed system-wide and locally. Therefore, I edited the list file to remove the first portion (containing libraries installed system-wide) leaving only the lines after /home/<user>/.ghc/.... Finally, I ran

$ cabal install --reinstall $(cat list) 

This worked for me. You should maybe do --dry-run first. Then go make a pot of tea. Or bake a cake.

2
  • 1
    According to Daniel's answer above, the world file is only supposed to contain directly installed packages. I think the idea is that cabal will resolve the dependencies for you, and they may change over time.
    – ntc2
    Sep 23, 2013 at 23:01
  • There are some additional helpful comments here: github.com/haskell/cabal/issues/275
    – Tad
    Dec 5, 2013 at 2:26
4

it appears there is no way right now: Ticket #282 - profiling versions of libraries not managed well "As usual the problem is lack of devevloper time to implement all these nice features we all want."

0

For visitors 2016+: Just install ghc-prof

Debian Linux Systems:

sudo apt-get install ghc-prof

Arch Linux Systems:

sudo pacman -S ghc-prof

1
  • There's currently no package ghc-prof in the pacman repositories. Apr 9, 2019 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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