views:

1103

answers:

3

Profiler/profiling related issue with Cucumber testing.

One of our cucumber tests run fairly slow. In stead of guessing on where our application is spending time, I'd like to know programatically.

How do I trigger a cucumber test with a profiler???

What did 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 console and not available for profiler script

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

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

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

+1  A: 

Using ruby-prof, you can start the profiler before the subject code and stop it again after. 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
troelskn
I like your approach, but unfortunately it gives me the possibility to only focus on where I think the problem might be. I'd like a more generic approach that can perhaps be run with a CI tool like hudson
Jesper Rønn-Jensen
I'm not sure what value profiling on the CI server would add. You need a human to read the profiling data to get anything useful out of them anyway.
troelskn
A: 

One more experiment is actually an answer to my question but did not give me but does not really give me a particularly useful result

$ 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

This actually runs the single cucumber scenario on line 36, but the result is not particularly useful

Jesper Rønn-Jensen
+1  A: 

Also try cucumber --format profile to get some stats about the slowest steps.

Using cucumber --format profile gives me an indication of which scenarios (and steps) are running slow. I already know that this step is the root cause of my problem because of the many expense reports: 1.8471970 Given I manage 45 projects with 1 expense reports of 100 DKK # features/manager_overview.feature:37Now, the most interesting part is where in my app it's using up time!
Jesper Rønn-Jensen