Profiling dough for cucumber (ruby / rails)

Profiler-related cucumber testing issue.

One of our cucumber tests is pretty slow. Instead of guessing where our application spends time, I would like to know programmatically.

How to run a cucumber test using a profiler?

What does not work:

  $ URL=/projects/by/114951412 #URL to slow rails page
  $ script/performance/profiler 'app.get "$URL"' 50

This does not work because "app.get" only works in the console and is not available for the profiler script

  $ EXPENSIVE_METHOD="Project.find('6300003243').aggregated_total_amount"
  $ script/performance/profiler "$EXPENSIVE_METHOD" 50

This gives the result, but I have to guess that this method is a bottleneck

(I use cucumber 0.3.94, rails 2.3.2, ruby ​​1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.6.0])

+3
source share
3

, , .

$ PROJECT_DIR=`pwd`
$ which cucumber
/usr/local/bin/cucumber
$ ln -s `which cucumber` cukes #required for profiler to have local file in next step
$ ruby-prof cukes -- features/manager_overview.feature:36

36,

+3

cucumber --format, .

+7

Using ruby-prof, you can start the profiler in front of the topic code and stop it again. eg:.

require 'ruby-prof'
RubyProf.start
# code here
result = RubyProf.stop

# You can then output the trace in different ways.
# Simply print a overview to stdout
printer = RubyProf::FlatPrinter.new(result)
printer.print($stdout, :min_percent => 0.1)

# Save a callgrind trace
# You can load this up in kcachegrind or a compatible tool.
printer = RubyProf::CallTreePrinter.new(result)
File.open "callgrind.out.42", 'w' do |file|
  RubyProf::CallTreePrinter.new(result).print(file)
end
+2
source

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


All Articles