Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/stickshift.rb
Constant Summary collapse
- RESTRICTED_CLASSES =
[String]
- RESTRICTED_METHODS =
%w(inspect __send__ __id__)
Instance Method Summary collapse
- #__stickshift_mangle(meth) ⇒ Object
- #instrument(*meths) ⇒ Object
- #instrumented?(meth) ⇒ Boolean
- #uninstrument(*meths) ⇒ Object
- #uninstrument_all ⇒ Object
Instance Method Details
#__stickshift_mangle(meth) ⇒ Object
139 140 141 |
# File 'lib/stickshift.rb', line 139 def __stickshift_mangle(meth) (s = meth.to_s) =~ /^[a-zA-Z_][a-zA-Z0-9_]*$/ ? s : "_#{s.unpack("H*")[0]}" end |
#instrument(*meths) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/stickshift.rb', line 93 def instrument(*meths) = Hash === meths.last ? meths.pop : {} Stickshift.top_level_trigger = true if [:top_level] @__stickshift ||= {} meths.each do |meth| unless instrumented?(meth) mangled = __stickshift_mangle(meth) meth_opts = .merge(:original => meth) @__stickshift[mangled] = meth_opts define_method("#{mangled}__instrumented") { meth_opts } alias_method "#{mangled}__orig_instrument", meth alias_method "#{mangled}__without_instrument", meth module_eval(<<-METH, __FILE__, __LINE__) def #{meth}(*args, &block) Stickshift::Timer.new(self, "#{meth}", #{mangled}__instrumented, *args).invoke do #{mangled}__without_instrument(*args, &block) end end METH end end end |
#instrumented?(meth) ⇒ Boolean
119 120 121 122 123 124 |
# File 'lib/stickshift.rb', line 119 def instrumented?(meth) RESTRICTED_CLASSES.include?(self) || RESTRICTED_METHODS.include?(meth.to_s) || meth =~ /__instrumented$/ || instance_methods.include?("#{__stickshift_mangle(meth)}__instrumented") end |
#uninstrument(*meths) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/stickshift.rb', line 126 def uninstrument(*meths) meths.each do |meth| if instrumented?(meth) remove_method "#{__stickshift_mangle(meth)}__instrumented" alias_method meth, "#{__stickshift_mangle(meth)}__orig_instrument" end end end |
#uninstrument_all ⇒ Object
135 136 137 |
# File 'lib/stickshift.rb', line 135 def uninstrument_all uninstrument(*(instance_methods.select {|m| m =~ /__instrumented$/}.map {|mi| @__stickshift[mi[0...-14]][:original]})) end |