Skip to content

Instantly share code, notes, and snippets.

@jkarmel
Created July 11, 2014 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkarmel/e22b4e39d4cd4f79838b to your computer and use it in GitHub Desktop.
Save jkarmel/e22b4e39d4cd4f79838b 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