Class: Puppet::Util::Instrumentation::Instrumentable::Probe
- Defined in:
- lib/puppet/util/instrumentation/instrumentable.rb
Instance Attribute Summary collapse
- #data ⇒ Object readonly
- #klass ⇒ Object readonly
- #label ⇒ Object readonly
- #method ⇒ Object readonly
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.
24 25 26 27 28 29 30 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 24 def initialize(method, klass, = {}) @method = method @klass = klass @label = [:label] || method @data = [:data] || {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
22 23 24 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 22 def data @data end |
#klass ⇒ Object (readonly)
22 23 24 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 22 def klass @klass end |
#label ⇒ Object (readonly)
22 23 24 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 22 def label @label end |
#method ⇒ Object (readonly)
22 23 24 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 22 def method @method end |
Instance Method Details
#disable ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 58 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 32 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
71 72 73 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 71 def enabled? !!@enabled end |