本文介绍了在对红宝石应用程序进行性能分析时,可以忽略不相关的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然使用ruby-prof并以graph-html模式打印出来,但是其中一种方法的报告说(有一些截图)

While using ruby-prof, printed out in graph-html mode, the report for one method says (with some snipping)

%Total       %Self       Total       Self    Wait    Child       Calls      Name    Line
52.85%       0.00%       51.22       0.00    0.00    51.22       1  ClassName#method_name  42
                         51.22       0.00    0.00    51.22       1/3        Hash#each  4200

很显然,不是Hash#each花费了很长时间,而是Hash#each中的yield块.

Obviously, it's not Hash#each that's taking a long time, but the yield block within Hash#each.

查看有关Hash#each的报告会造成混淆,因为它报告了使用Hash#each的任何人所调用的所有代码.

Looking at the report for Hash#each is confusing because it reports on all of the code called by anything that uses Hash#each.

是否可以要求ruby-prof将信息放在ClassName#method_name的报告中的生成代码上?

Is it possible to ask ruby-prof to put the information on yielded code in ClassName#method_name's report?

使用min_percent或切换为平面配置文件似乎无济于事.

Using min_percent or switching to a flat profile doesn't seem to help.

推荐答案

ruby​​-prof的0.9.0版允许方法消除.例如,要消除Integer#times,请使用

Version 0.9.0 of ruby-prof allows method elimination. For example, to eliminate Integer#times, use

result = RubyProf.stop
result.eliminate_methods!([/Integer#times/])

这样

def method_a
  5.times {method_b}
end

将直接指示method_amethod_b之间的关系.

will indicate the relationship between method_a and method_b directly.

这篇关于在对红宝石应用程序进行性能分析时,可以忽略不相关的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:48