How do I get ruby-prof to ignore Ruby core / standard library / gem methods?

I'm new to Ruby profiling and it seems that ruby-prof is a popular choice. I just installed gem and called my program:

 ruby-prof ./my-prog.rb 

However, the conclusion is incredibly detailed, as profiling data is included for all Ruby core tools and standard libraries and other gems. For example, the top three lines:

 8.79 0.011 0.010 0.000 0.001 3343 *String#% 7.28 0.078 0.009 0.000 0.069 2068 *Array#each 4.93 0.038 0.006 0.000 0.032 1098 *Array#map 

This is not very useful information for me, since I already know that my program deals with strings and arrays a lot, and, apparently, these classes have already been optimized from them. I only care about the hot spots in my code.

I tried some other printer modes, for example. -p graph_html and -p call_stack , but they all have the same problem.

I see that ruby-prof supports the removal and simplification of the method:

 -x, --exclude regexp exclude methods by regexp (see method elimination) -X, --exclude-file file exclude methods by regexp listed in file (see method elimination) --exclude-common-cycles make common iterators like Integer#times appear inlined --exclude-common-callbacks make common callbacks invocations like Integer#times appear 

but there seems to be no obvious way to get what I really want, it is only profiling data for my code, that is, with the time elapsed inside the code from Ruby core / stdlib, and other gems that are only considered timed out inside my code.

As soon as I see that my code has a foo method, which is a performance bottleneck due to the fact that it is called thousands of times and does not work well, then and only I want to see a breakdown of the time elapsed between my code and core / library, called inside this particular method.

I can’t understand why this is not a standard function, since I would expect that this is all that everyone wants to do: first run your own code, and then when you have run out of things for optimization, potentially start optimizing the gems you use and possibly even a ruby ​​core / stdlib. What am I missing?

+6
source share
2 answers

I agree that this is a big problem with ruby-prof. I prefer perftools.rb . It integrates with gperftools and supports various focus and ignore settings , as well as graphical reports that are better for quickly understanding hot spots and their call trees.

With ruby-prof, you can also try to output the KCacheGrind format and use the KCacheGrind Viewer for analysis. It has a number of visualization modes and facilitates special filtering and research results.

+2
source

You may want to profile and test tests. Minitest allows this as part of testing. This way you can focus on specific behaviors to get your timings.

Available in Ruby 2.0 or as Gem for Ruby 1.9 and below.

As for profiling in the same way, require 'profile' and use it for the same tests.

This blog post details how to do it, I don’t believe that it has changed much.

0
source

Source: https://habr.com/ru/post/951487/


All Articles