Skip to content

Instantly share code, notes, and snippets.

@agraves
Created May 25, 2012 22:40
Show Gist options
  • Save agraves/2790966 to your computer and use it in GitHub Desktop.
Save agraves/2790966 to your computer and use it in GitHub Desktop.
Profile a controller action
# ApplicationController
# Source: http://stackoverflow.com/questions/31320/how-to-profile-a-rails-controller-action
around_filter :profile if Rails.env.development?
def profile
if params[:profile] && result = RubyProf.profile { yield }
out = StringIO.new
RubyProf::GraphHtmlPrinter.new(result).print out, :min_percent => 0
self.response_body = out.string
else
yield
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment