Skip to content

Instantly share code, notes, and snippets.

@korakotlee
Created May 10, 2020 06:40
Show Gist options
  • Save korakotlee/9b606e563595b99257bebb8956eb8167 to your computer and use it in GitHub Desktop.
Save korakotlee/9b606e563595b99257bebb8956eb8167 to your computer and use it in GitHub Desktop.
# lib/profiler.rb
class Profiler
def self.prof(file_name)
RubyProf.start
yield
results = RubyProf.stop
# Print a flat profile to text
File.open "#{Rails.root}/tmp/profiler-#{file_name}-graph.html", 'w' do |file|
RubyProf::GraphHtmlPrinter.new(results).print(file)
end
File.open "#{Rails.root}/tmp/profiler-#{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