lib/appmap/hook.rb
# Observe class loading and hook all methods which match the config.
Observe class loading and hook all methods which match the config.
Observe class loading and hook all methods which match the config .
def enable &block
      require 'appmap/hook/method'
      hook_builtins
      tp = TracePoint.new(:end) do |trace_point|
        cls = trace_point.self
        instance_methods = cls.public_instance_methods(false)
        class_methods = cls.singleton_class.public_instance_methods(false) - instance_methods
        hook = lambda do |hook_cls|
          lambda do |method_id|
            method = hook_cls.public_instance_method(method_id)
            warn "AppMap: Examining #{hook_cls} #{method.name}" if LOG
            disasm = RubyVM::InstructionSequence.disasm(method)
            next unless disasm
            next unless \
              config.always_hook?(hook_cls, method.name) ||
              config.included_by_location?(method)
            hook_method = Hook::Method.new(config.package_for_method(method), hook_cls, method)
            next if /\AAppMap[:\.]/.match?(hook_method.method_display_name)
            hook_method.activate
          end
        end
        instance_methods.each(&hook.(cls))
        class_methods.each(&hook.(cls.singleton_class))
      end
      tp.enable(&block)
    end
def enable & block require 'appmap/hook/method' hook_builtins tp = TracePoint . new ( :end ) do | trace_point | cls = trace_point . self instance_methods = cls . public_instance_methods ( false ) class_methods = cls . singleton_class . public_instance_methods ( false ) - instance_methods hook = lambda do | hook_cls | lambda do | method_id | method = hook_cls . public_instance_method ( method_id ) warn "AppMap: Examining #{hook_cls} #{method.name}" if LOG disasm = RubyVM :: InstructionSequence . disasm ( method ) next unless disasm next unless config . always_hook? ( hook_cls , method . name ) || config . included_by_location? ( method ) hook_method = Hook :: Method . new ( config . package_for_method ( method ) , hook_cls , method ) next if / \A AppMap[: \. ] / . match? ( hook_method . method_display_name ) hook_method . activate end end instance_methods . each ( & hook . ( cls ) ) class_methods . each ( & hook . ( cls . singleton_class ) ) end tp . enable ( & block ) end
Observe class loading and hook all methods which match the config.
Observe class loading and hook all methods which match the config .
# Skip methods that have no instruction sequence, as they are obviously trivial. # Don't try and trace the AppMap methods or there will be # a stack overflow in the defined hook method.
block
<not_specific>