Skip to content

Instantly share code, notes, and snippets.

@stephanschubert
Created September 24, 2013 08:34
Show Gist options
  • Save stephanschubert/6681953 to your computer and use it in GitHub Desktop.
Save stephanschubert/6681953 to your computer and use it in GitHub Desktop.
Easy profiling w/ ruby-prof
def profile(prefix = "profile")
result = RubyProf.profile { yield }
dir = File.join(Rails.root, "tmp", "performance", params[:controller].parameterize
FileUtils.mkdir_p(dir)
file = File.join(dir, "callgrind.%s.%s.%s" % [prefix.parameterize, params[:action].parameterize, Time.now.to_s.parameterize] )
open(file, "w") { |f| RubyProf::CallTreePrinter.new(result).print(f, :min_percent => 1) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment