如何强制ghc的分析器更深入地进入库? [英] How to force ghc's profiler to step deeper into the libraries?
问题描述
我试图描述我的程序。所以我使用 -prof
和 -auto-all
标志进行编译,并使用 -P 获取详细的性能分析报告:
$ ghc --make -prof -auto-all测试。 hs
$ ./Test + RTS -P
以下是一份剖析报告:
成本中心模块编号。项目%时间%分配
主要主要266 1 0.0 0.0
主要273 21845 99.3 99.7
主要274 21844 0.0 0.0
主要268 21845 0.7 0.3
似乎 run
会消耗所有时间和内存。它调用了很多来自不同图书馆的功能,我很确定大部分时间都花在了其中一个功能上,但我无法确定哪一个功能。
如何获得更详细的报告?我希望手动添加大量 SCC
注释不是唯一的方法。
更新。现在,我通过将库的源文件复制到我的程序目录中来解决了这个问题。这允许GHC把它们作为程序的一部分,而不是作为外部库。
这是一个gprof类型的分析器 - 很弱,因为这些原因。
您可以使用 GHCi 来查找性能问题,就像找到无限循环一样,通过这种技术以这种方式:
6.3无限循环在2007年11月21日的glasgow-haskell-users上,
pepe提出了以下建议
检测
GHCi中的原因无限循环。假设违规函数
被命名为loop
,并且需要一个
参数:
1在GHCi中启用标志-fbreak-on-error(
:set -fbreak-on-error
)
2.运行你的表达式:trace(
:trace loop'a'
)
3.hit Ctrl-C而你的程序停留在循环中让调试器在循环中断
4.use:history和:back找出循环的位置和原因。
任何性能问题和无限循环之间的唯一区别是 - 无限循环浪费100%的时间,而性能问题浪费较少的百分比。
所以你可能需要闯入几次。
I'm trying to profile my program. So I compile it with -prof
and -auto-all
flags and run with -P
to get detailed profiling report:
$ ghc --make -prof -auto-all Test.hs
$ ./Test +RTS -P
Here is a piece of profiling report:
COST CENTRE MODULE no. entries %time %alloc
main Main 266 1 0.0 0.0
run Main 273 21845 99.3 99.7
sz Main 274 21844 0.0 0.0
size Main 268 21845 0.7 0.3
It seems that run
consumes all time and memory. It calls a lot of functions from various libraries, and I'm quite sure that most time is spent in one of them, but I can't figure in which one.
How can I get more detailed report? I hope that putting lots of SCC
annotations manually is not the only way.
Update. For now I "solved" the problem by copying sources of libraries to my program directory. This allows GHC to treat them as part of program, not as external libraries.
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.
这篇关于如何强制ghc的分析器更深入地进入库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!