-
-
Save heaven00/240f78ced3728376654b to your computer and use it in GitHub Desktop.
Simple class to wrap a profile run around some code
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
class DevelopmentProfiler | |
def self.prof(file_name) | |
RubyProf.start | |
yield | |
results = RubyProf.stop | |
# Print a flat profile to text | |
File.open "#{Rails.root}/tmp/performance/#{file_name}-graph.html", 'w' do |file| | |
RubyProf::GraphHtmlPrinter.new(results).print(file) | |
end | |
File.open "#{Rails.root}/tmp/performance/#{file_name}-flat.txt", 'w' do |file| | |
# RubyProf::FlatPrinter.new(results).print(file) | |
RubyProf::FlatPrinterWithLineNumbers.new(results).print(file) | |
end | |
File.open "#{Rails.root}/tmp/performance/#{file_name}-stack.html", 'w' do |file| | |
RubyProf::CallStackPrinter.new(results).print(file) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment