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 using fink, you can do the following:
# Open up therequest_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|
RubyProf::CallTreePrinter.new(results).print(file)
`kcachegrind #{file.path}` if options[:open]
end
Now next time you run the request profiler you will see the KCacheGrind open up with the call tree output in it, yeah!

