Is it possible to ignore irrelevant methods when profiling ruby applications?
Asked Answered
P

2

2

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

Obviously, it's not Hash#each that's taking a long time, but the yield block within 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.

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

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

Premed answered 11/2, 2010 at 0:47 Comment(0)
P
2

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/])

so that

def method_a
  5.times {method_b}
end

will indicate the relationship between method_a and method_b directly.

Premed answered 27/7, 2010 at 5:11 Comment(0)
M
0

If you don't mind low-tech, maybe you want to consider this. All you need is to be able to pause the debugger. Guaranteed, it will quickly find anything you can find any other way, and not show you any irrelevant code.

Mackmackay answered 11/2, 2010 at 1:51 Comment(3)
your technique doesn't provide any more information than already exists. Downvotes don't indicate "This answer is wrong" but "This answer is not useful".Premed
@Andrew: The question was "Is it possible to ignore irrelevant methods when profiling ruby applications?". The halting method automatically ignores irrelevant methods, and it does locate relevant methods, and relevant lines of code within those methods, so it is nothing if not useful. I think the downvote is really saying "This isn't what I was taught."Mackmackay
@Andrew: Here's more than you may have wanted to know on that subject: https://mcmap.net/q/15226/-alternatives-to-gprof-closed/…Mackmackay

© 2022 - 2024 — McMap. All rights reserved.