Class: Puppet::Util::Instrumentation::Instrumentable::Probe
- Defined in:
- lib/vendor/puppet/util/instrumentation/instrumentable.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #disable ⇒ Object
- #enable ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(method, klass, options = {}) ⇒ Probe
constructor
A new instance of Probe.
Constructor Details
#initialize(method, klass, options = {}) ⇒ Probe
Returns a new instance of Probe.
25 26 27 28 29 30 31 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 25 def initialize(method, klass, = {}) @method = method @klass = klass @label = [:label] || method @data = [:data] || {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
23 24 25 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 23 def data @data end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
23 24 25 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 23 def klass @klass end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
23 24 25 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 23 def label @label end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
23 24 25 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 23 def method @method end |
Instance Method Details
#disable ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 59 def disable raise "Probe is not enabled" unless enabled? # For the same reason as in #enable, we're forced to do a local # copy method = @method klass.class_eval do alias_method(method, "instrumented_#{method}") remove_method("instrumented_#{method}".to_sym) end @enabled = false end |
#enable ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 33 def enable raise "Probe already enabled" if enabled? # We're forced to perform this copy because in the class_eval'uated # block below @method would be evaluated in the class context. It's better # to close on locally-scoped variables than to resort to complex namespacing # to get access to the probe instance variables. method = @method; label = @label; data = @data klass.class_eval { alias_method("instrumented_#{method}", method) define_method(method) do |*args| id = nil instrumentation_data = nil begin instrumentation_label = label.respond_to?(:call) ? label.call(self, args) : label instrumentation_data = data.respond_to?(:call) ? data.call(self, args) : data id = Puppet::Util::Instrumentation.start(instrumentation_label, instrumentation_data) send("instrumented_#{method}".to_sym, *args) ensure Puppet::Util::Instrumentation.stop(instrumentation_label, id, instrumentation_data || {}) end end } @enabled = true end |
#enabled? ⇒ Boolean
72 73 74 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 72 def enabled? !!@enabled end |