Skip to content

Instantly share code, notes, and snippets.

@jkarmel
Created July 11, 2014 06:24
Show Gist options
  • Save jkarmel/8579733b7a4a6ce148ac to your computer and use it in GitHub Desktop.
Save jkarmel/8579733b7a4a6ce148ac to your computer and use it in GitHub Desktop.
module Profiler
self.singleton_class.instance_eval do
attr_accessor :defaults
end
self.defaults = {
open: true,
path: 'tmp',
name: 'profile'
}
def self.profile options = {}, &block
options = defaults.merge options
profile = RubyProf.profile(&block)
RubyProf::MultiPrinter.new(profile)
.print(:path => options[:path], :profile => options[:name])
if options[:open]
`open #{options[:path]}/#{options[:name]}.stack.html`
end
profile
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment