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

Cra*_*ker 7 ruby-on-rails ruby-prof ruby-on-rails-3.1

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

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

我有一个非常简单的测试控制器,相当于这个例子.

根据指南,我需要先安装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'
...
Run Code Online (Sandbox Code Playgroud)

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

gem'ruby-prof',:git =>'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 methodvalues for [#]:Array(来自/Users/craig/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.1.0/lib/active_support/testing/performance.rb:140:in"run_profile"的NoMethodError ...

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

宝石'红宝石'教授'

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

小智 8

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


小智 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 }
Run Code Online (Sandbox Code Playgroud)

至:

@total = @data.threads.sum(0) {|thread| thread.top_method.total_time}
Run Code Online (Sandbox Code Playgroud)