Wednesday, June 10, 2009

ruby-prof, script/performance, and vendor/gems

It seems I keep having all of this fun running into issues working with Rails 2. My most recent challenge was unpacking ruby-prof as part of a Rails 2.1.2 application. Over the past few months I have spent some time getting our project to the point that we were able to unpack our required gems. Everything was working great, until I tried to using ActionController::RequestProfiler a.k.a. script/performance/request to profile a controller action. However when I tried to use it our application complained that: `gem install ruby-prof` to use the profiler
Huh? I thought I unpacked the gem in the vendor directory? A quick directory list revealed that it was there: vendor/gems/ruby-prof-0.7.3
What could be wrong? I started to trace the request script to find this little gem call in the Rails source code:
     # File actionpack/lib/action_controller/request_profiler.rb, line 146
146: def load_ruby_prof
147: begin
148: gem 'ruby-prof', '>= 0.6.1'
149: require 'ruby-prof'
150: if mode = options[:measure]
151: RubyProf.measure_mode = RubyProf.const_get(mode.upcase)
152: end
153: rescue LoadError
154: abort '`gem install ruby-prof` to use the profiler'
155: end
156: end
Really? Another Evil monkey patch in my source code:
     # File /lib/core_ext/action_controller/request_profiler.rb
def load_ruby_prof
require 'ruby-prof'
if mode = options[:measure]
RubyProf.measure_mode = RubyProf.const_get(mode.upcase)
rescue LoadError
abort '`gem install ruby-prof` to use the profiler'

#config/environment.rb do |config|
config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir| = "#{dir}/lib") ? lib : dir

# Add pagination requirement
require "#{RAILS_ROOT}/lib/core_ext/action_controller/request_profiler"

No comments: