3

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?

Chris Taylor
  • 46,912
  • 15
  • 110
  • 154

1 Answers1

6

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-all resp. -fprof-auto should only be used for the library currently under inspection, other libraries should be compiled with fewer cost centre annotations for profiling as given by -auto resp. -fprof-auto-top or -fprof-auto-exported.

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
Jeff Burka
  • 2,571
  • 1
  • 17
  • 30
  • I thought that `-auto-all` had been replaced by `-fprof-auto` in newer versions of GHC. Let me check and get back to you. – Chris Taylor Jul 31 '12 at 19:33
  • Update: No, that doesn't make any difference. – Chris Taylor Jul 31 '12 at 19:34
  • @ChrisTaylor You need to compile the library with `-auto-all` too for that. Set `ghc-prof-options: -O2 -auto-all` in the .cabal file. – Daniel Fischer Jul 31 '12 at 19:35
  • @ChrisTaylor As of 7.4, it doesn't matter, currently both work, `-auto-all` is what I still use since I work with 6.12-7.4. – Daniel Fischer Jul 31 '12 at 19:38
  • 1
    One of you guys should probably post the right information in a new answer instead of leaving it in the comments of a mostly incorrect one. Or I can just edit mine I guess, either way. – Jeff Burka Jul 31 '12 at 19:42