Created
March 27, 2012 20:37
-
-
Save jashkenas/2220083 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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