Rails性能测试中的ruby-prof错误

时间:2012-05-28 03:45:20

标签: ruby-on-rails ruby-on-rails-3.1 ruby-prof

我正在创建一个Rails性能测试,如Rails Guide中所述,我遇到了ruby-prof的问题。

我正在使用Ruby 1.9.2-p0(尽管在p320上遇到了同样的问题)和Rails 3.1.0。

我对一个相当于this example的控制器进行了非常简单的测试。

根据the guide,我需要在使用性能测试之前安装ruby-prof。果然,如果我没有它进行性能测试,我会得到:

  

在Gemfile中将ruby-prof指定为应用程序的依赖关系以运行基准测试。

如果我按照指南的说明操作,我将其添加到我的Gemfile:

  

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

...从wycats存储库获取版本0.11.0。当我运行我的测试时,我收到此错误:

/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'
...

但是“wycats”似乎不是ruby-prof的规范Github回购。该文档涉及rdp(Roger Pack)。如果我改用这个回购:

  

gem'ruby-prof',:git =&gt; 'git的://github.com/rdp/ruby-prof.git'

...我得到版本0.11.2,并收到此错误:

  

/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 method值'for [#]:Array(NoMethodError)       来自/Users/craig/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0/lib/active_support/testing/performance.rb:140:in“run_profile”   ...

如果我直接使用rubygems中的gem(同样,版本0.11.2),我会得到同样的错误:

  

gem'ruby-prof'

任何想法出了什么问题,或者如何解决?

  

5 个答案:

答案 0 :(得分:8)

要使用最新的ruby-prof版本,你需要rails 3.2.3,我不知道你可以使用rails 3.1的ruby-prof版本,也许你可以复制lib / active_support / testing / performance / ruby​​.rb activesupport 3.2.3

答案 1 :(得分:8)

问题出在activesupport-3.2.2 \ lib \ active_support \ testing \ performance \ ruby​​.rb。

更改第39行:

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

要:

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

答案 2 :(得分:4)

Ruby on Rails 3.2.6已经纠正了这个问题。 https://github.com/rails/rails/blob/v3.2.6/activesupport/lib/active_support/testing/performance/ruby.rb

第39行

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

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

它是:

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

看起来方法在这里失败了。

答案 3 :(得分:1)

我有同样的问题。我修复了为我的Rails版本安装正确的ruby-prof版本。

所以,我使用的是2011年6月16日发布的Rails 3.0.9(根据https://rubygems.org/gems/rails/versions)。

然后,我检查了同一天左右发布的ruby-prof。它是2011年7月6日发布的0.10.8。

安装完上面后我就搞定了。可能不支持某些性能分析指标。

干杯。

答案 4 :(得分:0)

在我使用Rails 3.2.9的情况下,我从项目中删除了自动生成的目录'test / performance'。