Profile only a single function (or cost center) with GHC
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?
According to the ghc manual you can do heap profiling on certain cost centers by eg 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.
上一篇: 为什么GHC不能推理一些无限列表?
下一篇: 使用GHC只配置一个功能(或成本中心)