How to force ghc's profiler to step deeper into the libraries?

☆樱花仙子☆ 提交于 2019-12-04 10:38:45
Mike Dunlavey

It's a gprof-type profiler - pretty weak, for these reasons.

You can use GHCi to find performance issues the same way you would find infinite loops, by this technique in this manner:

6.3 Infinite loops On glasgow-haskell-users on 21 Nov 2007, pepe made the following suggestion for detecting the cause infinite loops in GHCi. Assuming the offending function is named loop, and takes one argument:

1.enable the flag -fbreak-on-error (:set -fbreak-on-error in GHCi)

2.run your expression with :trace (:trace loop 'a')

3.hit Ctrl-C while your program is stuck in the loop to have the debugger break in the loop

4.use :history and :back to find out where the loop is located and why.

The only difference between any performance problem and an infinite loop is - infinite loops waste 100% of the time, while performance problems waste a lesser percent. So you might have to break into it a few times.

For the profiler to discriminate library functions, there have to be cost-center annotations on them. You can do this two ways:

  1. Recompile the libraries of interest with -p -auto so that library functions get annotated with SCCs.
  2. Insert SCC annotations around probable time-consuming library calls in your code.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!