11
votes

I am trying to profile some Haskell code using the GHC profiling tools. The cost center I am most interested in, however, is dominated currently by a bunch of initialization code that I don't really care about.

My code looks roughly, like this:

main = do
  x <- lotsOfInitialization
  print $ {-# SCC "myCostCenter" #-} interestingPart x

In my actual code, the lotsOfInitialization part is taking ~98% of the time and so it's difficult to see with any granularity what is happening inside interestingPart.

I thought that only annotating in one place (and not using -fprof-auto) would be enough, but the report I'm getting still shows all the function calls.

I also tried a strictness annotation on x, but that didn't seem to change anything.

Is there some way to tell GHC to ignore the initialization code, or to only focus on the parts I want?

1

1 Answers

3
votes

According to the ghc manual you can do heap profiling on certain cost centers by e.g. using -hc⟨name⟩ or -hy⟨type⟩.

I couldn't find a solution that does something similar for time profiling though.

EDIT:

I did actuall manage to find a way to conveniently do what you need for both allocation and time profiling. If you use the profiteur visualizer for .prof files you can look at the performance profile of just a certain cost centre as a nicely formatted tree-map.