Profiling controllers

Guys,

I’ve built some fairly complex controllers and I’d like to profile them.
What’s the best way to go about this? I suspect the profiling script
shipped
with Rails doesn’t work well with controllers. I looked at railsbench,
but
it doesn’t work well because the controllers use acts_as_authenticated.

What does everyone use?

Thanks!
Jake

Jake C. wrote:

I’ve built some fairly complex controllers and I’d like to profile them.
What’s the best way to go about this?

This probably isn’t the best way to go about it, but for a quick hack
to get some results you could try this:

  1. Add

require ‘profiler’

at the top of your ‘whatever_controller.rb’.

  1. After the ‘def my_action’ line of the action you want to profile,
    add

Profiler__::start_profile

  1. At the end of the action, add

Profiler__::stop_profile
Profiler__::print_profile(File::new("#{RAILS_ROOT}/log/profiler.log",
‘w’))

Then when you run that action in your browser, it’ll write a file into
log/profiler.log that contains a profile for the controller part of
that action.

Quick and dirty, but maybe it’ll do the job (or inspire you to write
something nicer!).

Chris