Tag Archive | rails performance

Making the Rails Request Profiler and KCacheGrind Play

I have been working on optimizing my companies site after porting over many features. I have been finding the newer rails performance tools including the request profiler to be very helpful in this effort. Ryan Bates put out a great screencast on request profiling that will get you started, but if your app has any complexity, you will find out quickly like I did that the html file gets too large and is not very helpful when it crashes your browser. 😉

Assuming that you have already installed KCacheGrind on your Mac usingfink, you can do the following:

# Open up the request_profiler.rb in the actionpack gem (the code that is used by ./script/performance/request)

mate /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/request_profiler.rb

# Add the following lines of ruby to the show_profile_results method at the bottom.

        File.open "#{RAILS_ROOT}/tmp/profile-call-tree.kcg", 'w' do |file|
           `kcachegrind #{file.path}` if options[:open]

Now next time you run the request profiler you will see the KCacheGrind open up with the call tree output in it, yeah!