Skip to content

Instantly share code, notes, and snippets.

@k41n
Forked from teamon/prof.rb
Created September 8, 2017 12:01
Show Gist options
  • Select an option

  • Save k41n/e96540b807946199ca86b9d65ca11dd3 to your computer and use it in GitHub Desktop.

Select an option

Save k41n/e96540b807946199ca86b9d65ca11dd3 to your computer and use it in GitHub Desktop.
Profile rails controller with ruby-prof
# gem "ruby-prof"
around_filter :profiler
def profiler(&block)
data = RubyProf::Profile.profile(&block)
filepath = Rails.root.join("tmp", "profiler.html")
File.open(filepath, "w") do |f|
RubyProf::CallStackPrinter.new(data).print(f)
end
Rails.logger.debug "Profiler results saved to #{filepath}"
system "open #{filepath}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment