Skip to content

Instantly share code, notes, and snippets.

@denyago
Last active August 29, 2015 14:20
Show Gist options
  • Save denyago/5df0c60e2e0d397c086a to your computer and use it in GitHub Desktop.
Save denyago/5df0c60e2e0d397c086a to your computer and use it in GitHub Desktop.
Ruby profiling
# gem 'ruby-prof'
module WithProfiling
def self.run
RubyProf.start
puts 'Start'
result = yield
puts 'End'
result = RubyProf.stop
file_path = "/tmp/callgrind.#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}"
io = IO.new(IO.sysopen(file_path, 'w'), 'w')
printer = RubyProf::CallTreePrinter.new(result)
printer.print(io)
io.close
puts "qcachegrind #{file_path}"
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment