Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created March 27, 2012 20:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jashkenas/2220083 to your computer and use it in GitHub Desktop.
Save jashkenas/2220083 to your computer and use it in GitHub Desktop.
# In development mode, optionally perform a RubyProf profile of any request.
# Simply pass perform_profile=true in your params.
def perform_profile
return yield unless params[:perform_profile]
require 'ruby-prof'
RubyProf.start
yield
result = RubyProf.stop
printer = RubyProf::FlatPrinter.new(result)
File.open("#{Rails.root}/tmp/profile.txt", 'w+') do |f|
printer.print(f)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment