简体   繁体   中英

Enable memory reports with rails-perftest (Rails 4.1.4, Ruby 2.1.2)

I am using rails 4.1.4, ruby 2.1.2 and rvm.

Gemfile (extract)

gem 'rails-perftest'
gem 'ruby-prof', group: :test

I installed ruby using these commands (in order to apply patch which enables memory profiling)

rvm get stable
rvm reinstall 2.1.2 --patch railsexpress

But still no luck and memory reports are empty with rake test:benchmark or rake test:profile

I was trying to get the same Ruby patch and version working with a Rails 3 benchmark and that was broken too, albeit in a different way. It looks to me like this is an oversight in Rails. I'm seeing this warning string on a Rails 3.2 app

$ bundle exec rake test:benchmark
Update your ruby interpreter to be able to run benchmarks.
$ bundle exec rails -v
Rails 3.2.21

The problem seems to be that ActiveSupport 3.2 isn't aware of Ruby versions higher that 2.0 for this particular piece of code

if RUBY_VERSION.between?('1.9.2', '2.0')
  require 'active_support/testing/performance/ruby/yarv'
elsif RUBY_VERSION.between?('1.8.6', '1.9')
  require 'active_support/testing/performance/ruby/mri'
else
  $stderr.puts 'Update your ruby interpreter to be able to run benchmarks.'
  exit
end

see https://www.omniref.com/ruby/gems/activesupport/3.2.12/symbols/ActiveSupport::Testing::Performance::Metrics::CpuTime#line=145

After editing the version check manually I can confirm that the patch does work in Rails 3 with version 2.1.2. Perhaps you could check your RUBY_VERSION and RUBY_ENGINE constants for anything unusual?

(I understand this isn't really an answer but I don't have enough reputation to comment. Also it hopefully rules out the rvm patch and ruby-prof as a problem)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM