Class: OrangeTap::MethodRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/orange_tap/method_registry.rb

Overview

Holds the set of methods to be traced, keyed by [owner, name] rather than by Method/UnboundMethod object identity. Method/UnboundMethod instances are freshly allocated on every obj.method(:foo) call, so identity-based bookkeeping would make untrace_method impossible to use correctly. Using owner (the singleton class for class/singleton methods) + name gives a stable identity for instance methods, class methods, and singleton methods on a specific object alike.

Constant Summary collapse

CLASS_METHOD_NOTATION =

"Foo::Bar.baz" -> class/singleton method; "Foo::Bar#baz" -> instance method. The class-path side never contains "." or "#", so a greedy match up to the last separator is unambiguous.

/\A(.+)\.([^.#]+)\z/
INSTANCE_METHOD_NOTATION =
/\A(.+)#([^.#]+)\z/

Instance Method Summary collapse

Constructor Details

#initializeMethodRegistry

Returns a new instance of MethodRegistry.



20
21
22
23
24
25
26
27
# File 'lib/orange_tap/method_registry.rb', line 20

def initialize
  @entries = {}
  # [owner, name] keys for C-implemented (ISeq-less) methods, traced via a
  # global :c_call/:c_return TracePoint. Only populated when
  # OrangeTap.config.trace_c_methods is enabled at registration time.
  @c_entries = Set.new
  @mutex = Mutex.new
end

Instance Method Details

#c_targetsObject

Snapshot of registered C-method keys ([owner, name]), taken once per Session#open. Empty unless trace_c_methods was enabled at registration time. Session uses this to decide whether to build a global C TracePoint.



52
53
54
# File 'lib/orange_tap/method_registry.rb', line 52

def c_targets
  @mutex.synchronize { @c_entries.dup }
end

#register(*method_objs) ⇒ Object



29
30
31
32
# File 'lib/orange_tap/method_registry.rb', line 29

def register(*method_objs)
  method_objs.each { |m| register_one(m) }
  nil
end

#register_all_instance_methods(klass) ⇒ Object



39
40
41
42
# File 'lib/orange_tap/method_registry.rb', line 39

def register_all_instance_methods(klass)
  klass.instance_methods(false).each { |m| register(klass.instance_method(m)) }
  nil
end

#targetsObject

Snapshot of currently registered ISeqs, taken once per Session#open.



45
46
47
# File 'lib/orange_tap/method_registry.rb', line 45

def targets
  @mutex.synchronize { @entries.values.dup }
end

#unregister(*method_objs) ⇒ Object



34
35
36
37
# File 'lib/orange_tap/method_registry.rb', line 34

def unregister(*method_objs)
  method_objs.each { |m| unregister_one(m) }
  nil
end