I’m using GHC 7.4.1 and trying to profile a piece of code. Unfortunately, the output of the profiler assigns one big cost centre to the main function, instead of breaking it up into multiple cost centres for each function.
This is the procedure I’m following to profile the code. I’d appreciate a pointer to what I’m doing wrong.
First, reinstall the library, enabling optimizations and profiling:
cabal install -p -O2
Next, I recompile the code I want to profile:
ghc -rtsopts -prof -fprof-auto -fforce-recomp --make -O2 "Main.hs"
Finally, I run it with a few profiling options:
./Main +RTS -K100M -s -p -hy
and this is the result:
COST CENTRE MODULE %time %alloc
main Main 100.0 100.0
Anything obvious that I’m doing wrong?
The
-auto-all(-fprof-auto, as of GHC 7.4) option automatically marks all top level functions, including ones that aren’t exported, as cost centers.But that option affects only the currently compiled modules, so it may be necessary to also compile the library with that option. To do that, set
ghc-prof-options: -O2 -auto-all(resp.-fprof-auto) in the library’s .cabal file.Note: cost centre annotations can have a big performance impact, so
-auto-allresp.-fprof-autoshould only be used for the library currently under inspection, other libraries should be compiled with fewer cost centre annotations for profiling as given by-autoresp.-fprof-auto-topor-fprof-auto-exported.