Class: DiverDown::Trace::Tracer
- Inherits:
-
Object
- Object
- DiverDown::Trace::Tracer
- Defined in:
- lib/diver_down/trace/tracer.rb
Constant Summary collapse
- DEFAULT_TRACE_EVENTS =
%i[ call return c_call c_return b_call b_return ].freeze
Class Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(module_set: {}, caller_paths: nil, ignored_method_ids: nil, filter_method_id_path: nil) ⇒ Tracer
constructor
A new instance of Tracer.
- #new_session(title: SecureRandom.uuid, definition_group: nil) ⇒ TracePoint
-
#trace(title: SecureRandom.uuid, definition_group: nil) ⇒ DiverDown::Definition
Trace the call stack of the block and build the definition.
Constructor Details
#initialize(module_set: {}, caller_paths: nil, ignored_method_ids: nil, filter_method_id_path: nil) ⇒ Tracer
Returns a new instance of Tracer.
30 31 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 57 58 59 60 |
# File 'lib/diver_down/trace/tracer.rb', line 30 def initialize(module_set: {}, caller_paths: nil, ignored_method_ids: nil, filter_method_id_path: nil) if caller_paths && !caller_paths.all? { Pathname.new(_1).absolute? } raise ArgumentError, "caller_paths must be absolute path(#{caller_paths})" end @module_set = if module_set.is_a?(DiverDown::Trace::ModuleSet) module_set elsif module_set.is_a?(Hash) DiverDown::Trace::ModuleSet.new(**module_set) else raise ArgumentError, <<~MSG Given invalid module_set. #{module_set}" Available types are: Hash{ modules: Array<Module, String> | Set<Module, String> | nil paths: Array<String> | Set<String> | nil } | DiverDown::Trace::ModuleSet MSG end @ignored_method_ids = if ignored_method_ids.is_a?(DiverDown::Trace::IgnoredMethodIds) ignored_method_ids elsif !ignored_method_ids.nil? DiverDown::Trace::IgnoredMethodIds.new(ignored_method_ids) end @caller_paths = caller_paths&.to_set @filter_method_id_path = filter_method_id_path end |
Class Attribute Details
.trace_events ⇒ Array<Symbol>
16 17 18 |
# File 'lib/diver_down/trace/tracer.rb', line 16 def self.trace_events @trace_events || DEFAULT_TRACE_EVENTS end |
Instance Method Details
#new_session(title: SecureRandom.uuid, definition_group: nil) ⇒ TracePoint
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/diver_down/trace/tracer.rb', line 85 def new_session(title: SecureRandom.uuid, definition_group: nil) DiverDown::Trace::Session.new( module_set: @module_set, ignored_method_ids: @ignored_method_ids, caller_paths: @caller_paths, filter_method_id_path: @filter_method_id_path, definition: DiverDown::Definition.new( title:, definition_group: ) ) end |
#trace(title: SecureRandom.uuid, definition_group: nil) ⇒ DiverDown::Definition
Trace the call stack of the block and build the definition
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/diver_down/trace/tracer.rb', line 68 def trace(title: SecureRandom.uuid, definition_group: nil, &) session = new_session(title:, definition_group:) session.start yield session.stop session.definition ensure # Ensure to stop the session session&.stop end |