Errors with ruby-prof in a Rails Performance Test
Asked Answered
N

5

8

I'm creating a Rails Performance test, as described in the Rails Guide, and I'm having problems with ruby-prof.

I'm using Ruby 1.9.2-p0 (though experienced the same issue on p320) and Rails 3.1.0.

I have a pretty simple test for a controller that is equivalent to this example.

According to the guide, I need to install ruby-prof before I can use performance tests. Sure enough, if I run my performance test without it, I get:

Specify ruby-prof as application's dependency in Gemfile to run benchmarks.

If I follow the guide's instructions to the letter, I add this to my Gemfile:

gem 'ruby-prof', :git => 'git://github.com/wycats/ruby-prof.git'

...and get version 0.11.0 from the wycats repository. When I run my test I get this error:

/Users/craig/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruby-prof-ffae61a89553/lib/ruby-prof/abstract_printer.rb:44:in `inspect': undefined method `to_s' for #<Class:0x000001025a3f18> (NoMethodError)
from /Users/craig/.rvm/gems/ruby-1.9.2-p0/bundler/gems/ruby-prof-ffae61a89553/lib/ruby-prof/abstract_printer.rb:44:in `full_name'
...

But "wycats" doesn't appear to be the canonical Github repo for ruby-prof. The documentation refers to rdp (Roger Pack). If I use that repo instead:

gem 'ruby-prof', :git => 'git://github.com/rdp/ruby-prof.git'

...I get version 0.11.2, and get this error:

/Users/craig/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0/lib/active_support/testing/performance/ruby.rb:39:in run': undefined methodvalues' for [#]:Array (NoMethodError) from /Users/craig/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0/lib/active_support/testing/performance.rb:140:in `run_profile' ...

I get the same error if I just use the gem from rubygems directly (again, version 0.11.2):

gem 'ruby-prof'

Any ideas what's going wrong, or how to resolve it?

Nagy answered 28/5, 2012 at 3:45 Comment(0)
C
8

To use latest ruby-prof version you need rails 3.2.3, I don't know what ruby-prof version you can use with rails 3.1, maybe you can copy lib/active_support/testing/performance/ruby.rb from activesupport 3.2.3

Consignor answered 1/6, 2012 at 1:12 Comment(0)
R
8

The problem is in activesupport-3.2.2\lib\active_support\testing\performance\ruby.rb.

Change line 39 from:

@total = @data.threads.sum(0) { |method_infos| method_infos.max.total_time }

To:

@total = @data.threads.sum(0) {|thread| thread.top_method.total_time}
Reading answered 3/6, 2012 at 6:47 Comment(1)
awesome! thanks so much. Is this patch submitted to rails, out of curiousity?Alvin
P
4

Ruby on Rails 3.2.6 has this already corrected. https://github.com/rails/rails/blob/v3.2.6/activesupport/lib/active_support/testing/performance/ruby.rb

line 39

@total = @data.threads.sum(0) { |thread| thread.methods.max.total_time }

in Rails 3.2.3
https://github.com/rails/rails/blob/v3.2.3/activesupport/lib/active_support/testing/performance/ruby.rb

it is:

@total = @data.threads.values.sum(0) { |method_infos| method_infos.max.total_time }

and looks like the values method is failing here.

Percival answered 22/6, 2012 at 15:42 Comment(0)
Y
1

I had the same issue. I fixed by installing the correct ruby-prof version for my Rails version.

So, I was using Rails 3.0.9 released on June 16th, 2011 (as per https://rubygems.org/gems/rails/versions).

Then, I checked for ruby-prof released around that same date. And it was 0.10.8 released on July 6, 2011.

After installing the above I got it working. Some of the profiling metrics might not be supported.

Cheers.

Yourself answered 27/2, 2013 at 4:57 Comment(2)
@coder I went through the Faq. Did not see anything I missed in my answer. Can you highlight if something is missed.Yourself
Yes, there was the wrong ruby-prof version in my case, and your solution helped me.Edrei
P
0

In my case with Rails 3.2.9, I removed auto-generated directory 'test/performence' from my project.

Plate answered 26/11, 2012 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.