I wish to profile my program written in Haskell.
On compilation, I am told that I do not have profiling libraries for certain dependencies (e.g. criterion
) installed and cabal
aborts.
I have no interest in profiling parts of those dependencies; code called from main
doesn't even use them.
How can I profile my application without installing profiling libraries I don't need and without removing all those dependencies?
As mentioned in the question you refer to in your comment, a good way to solve this problem in the future is to enable profiling in the cabal configuration. This way all libraries are installed with profiling support. This might not be a satisfying solution but I guess many are opting for it.
If you are only interested in getting an impression of the memory usage of your program you can generate a heap profile of your program using
-hT
. More precisely, you have to compile the program with-rtsopts
to enable RTS options then execute it using+RTS -hT
. The compiler generates a file with the extensionhp
. You can convert thehp
file into a postscript file with a heap profile usinghp2ps
. This should work without any profiling support, but note that I am to lazy to verify it as I have installed all libraries with profiling support ; )A good way to circumvent having to compile everything with profiling is to use cabal sandbox. It allows you to set up a sandbox for one application only, and thereby you won't have to re-install your entire
~/.cabal
prefix. You'll need a recent version of Cabal, so runcabal update && cabal install cabal-install
first.Once you initialise a sandbox, create a file
cabal.config
to include the necessary directives (in your caselibrary-profiling: True
;executable-profiling: True
may also be handy.)A side-effect of this is that you can test your code with dependencies that need not be installed globally, for example, experimental versions, or outdated versions.
EDIT: btw, I don't think you need to have profiling enabled for
criterion
to work. In any case, it works for me without profiling being enabled. Just write aMain
module that containsmain = defaultMain benchmarks
wherebenchmarks
has type[Benchmark]
, i.e. a list of benchmarks that you've written.You then compile that file (say, we call it
benchmarks.hs
withghc --make -o bench benchmarks.hs
, and run the program,./bench
with the appropriate arguments (consult the criterion documentation for details. A good default argument is, say./bench -o benchmarks.html
which will generate a nifty report similar to this one)I had the same problem this week, and although I had recompiled everything by hand, I was instructed in the IRC channel to do the following: