Last active
July 9, 2018 00:16
-
-
Save ozeron/c0bd199442507ac869ca to your computer and use it in GitHub Desktop.
Profiling ruby code
This file contains 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
# https://github.com/ruby-prof/ruby-prof | |
require 'ruby-prof' | |
class DevProfiler | |
BASE_PATH = "#{Rails.root}/tmp/performance/#{file_name}" | |
def self.prof(file_name) | |
RubyProf.start | |
puts "Start profiling method" | |
yield | |
puts "Done Profiling!" | |
results = RubyProf.stop | |
# Print a flat profile to text | |
File.open "#{BASE_PATH}-graph.html", 'w' do |file| | |
RubyProf::GraphHtmlPrinter.new(results).print(file) | |
end | |
File.open "#{BASE_PATH}--flat.txt", 'w' do |file| | |
RubyProf::FlatPrinterWithLineNumbers.new(results).print(file) | |
end | |
File.open "#{BASE_PATH}--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