Created
July 11, 2014 06:23
-
-
Save jkarmel/e22b4e39d4cd4f79838b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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