Class: AppMap::Tracer
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#stacks ⇒ Object
Returns the value of attribute stacks.
-
#thread_id ⇒ Object
readonly
Returns the value of attribute thread_id.
Instance Method Summary collapse
-
#disable ⇒ Object
Private function.
- #enable ⇒ Object
- #enabled?(thread_id: nil) ⇒ Boolean
-
#event? ⇒ Boolean
Whether there is an event available for processing.
-
#event_methods ⇒ Object
Gets a unique list of the methods that were invoked by the program.
-
#initialize(thread_id: nil) ⇒ Tracer
constructor
Records the events which happen in a program.
-
#last_package_for_current_thread ⇒ Object
Gets the last package which was observed on the current thread.
-
#next_event ⇒ Object
Gets the next available event, if any.
-
#record_event(event, package: nil, defined_class: nil, method: nil) ⇒ Object
Record a program execution event.
-
#record_method(method) ⇒ Object
method
should be duck-typed to respond to the following: * package * defined_class * name * static * comment * labels * source_location.
Constructor Details
#initialize(thread_id: nil) ⇒ Tracer
Records the events which happen in a program.
136 137 138 139 140 141 142 143 |
# File 'lib/appmap/trace.rb', line 136 def initialize(thread_id: nil) @events = [] @last_package_for_thread = {} @methods = Set.new @stack_printer = StackPrinter.new if StackPrinter.enabled? @enabled = false @thread_id = thread_id end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
133 134 135 |
# File 'lib/appmap/trace.rb', line 133 def events @events end |
#stacks ⇒ Object
Returns the value of attribute stacks.
132 133 134 |
# File 'lib/appmap/trace.rb', line 132 def stacks @stacks end |
#thread_id ⇒ Object (readonly)
Returns the value of attribute thread_id.
133 134 135 |
# File 'lib/appmap/trace.rb', line 133 def thread_id @thread_id end |
Instance Method Details
#disable ⇒ Object
Private function. Use AppMap.tracing#delete.
156 157 158 |
# File 'lib/appmap/trace.rb', line 156 def disable # :nodoc: @enabled = false end |
#enable ⇒ Object
145 146 147 |
# File 'lib/appmap/trace.rb', line 145 def enable @enabled = true end |
#enabled?(thread_id: nil) ⇒ Boolean
149 150 151 152 153 |
# File 'lib/appmap/trace.rb', line 149 def enabled?(thread_id: nil) return false unless @enabled thread_id.nil? || @thread_id.nil? || @thread_id == thread_id end |
#event? ⇒ Boolean
Whether there is an event available for processing.
201 202 203 |
# File 'lib/appmap/trace.rb', line 201 def event? !@events.empty? && @events.first.ready? end |
#event_methods ⇒ Object
Gets a unique list of the methods that were invoked by the program.
196 197 198 |
# File 'lib/appmap/trace.rb', line 196 def event_methods @methods.to_a end |
#last_package_for_current_thread ⇒ Object
Gets the last package which was observed on the current thread.
191 192 193 |
# File 'lib/appmap/trace.rb', line 191 def last_package_for_current_thread @last_package_for_thread[Thread.current.object_id] end |
#next_event ⇒ Object
Gets the next available event, if any.
206 207 208 |
# File 'lib/appmap/trace.rb', line 206 def next_event @events.shift if event? end |
#record_event(event, package: nil, defined_class: nil, method: nil) ⇒ Object
Record a program execution event.
The event should be one of the MethodEvent subclasses.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/appmap/trace.rb', line 163 def record_event(event, package: nil, defined_class: nil, method: nil) return unless @enabled if @thread_id && @thread_id != event.thread_id raise "Expected event in thread #{@thread_id}, got #{event.thread_id}" end @stack_printer.record(event) if @stack_printer @last_package_for_thread[Thread.current.object_id] = package if package @events << event static = event.static if event.respond_to?(:static) record_method Trace::RubyMethod.new(package, defined_class, method, static) \ if package && defined_class && method && (event.event == :call) end |
#record_method(method) ⇒ Object
method
should be duck-typed to respond to the following:
-
package
-
defined_class
-
name
-
static
-
comment
-
labels
-
source_location
186 187 188 |
# File 'lib/appmap/trace.rb', line 186 def record_method(method) @methods << method end |