Skip to content

Instantly share code, notes, and snippets.

@guiocavalcanti
Created May 3, 2013 17:33
Show Gist options
  • Save guiocavalcanti/5511718 to your computer and use it in GitHub Desktop.
Save guiocavalcanti/5511718 to your computer and use it in GitHub Desktop.
require 'ruby-prof'
class DevelopmentProfiler
def self.prof(file_name)
RubyProf.start
yield
results = RubyProf.stop
# Print a flat profile to text
File.open "#{Rails.root}/tmp/#{file_name}-graph.html", 'w' do |file|
RubyProf::GraphHtmlPrinter.new(results).print(file)
end
File.open "#{Rails.root}/tmp/#{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/#{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