Unobtrusive around filter profile snippet

Drop into environment.rb or other required library.

require 'profiler'

class ProfilingFilter

  def before( controller )
    Profiler__::start_profile 
  end

  def after( controller )
    Profiler__::stop_profile
    Profiler__::print_profile(File::new("#{RAILS_ROOT}/log/profiler.log", 'w'))  
  end

end

Usage

Something hogs?

class SomeController < ApplicationController
  around_filter ProfilingFilter.new, :only => :slow_action

  def slow_action; end

  def speedy; end

  def zippy; end

end

Output dumped to log/profiler.log


About this entry