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? ⇒ 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
methodshould 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.
138 139 140 141 142 143 144 145 |
# File 'lib/appmap/trace.rb', line 138 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.
135 136 137 |
# File 'lib/appmap/trace.rb', line 135 def events @events end |
#stacks ⇒ Object
Returns the value of attribute stacks.
134 135 136 |
# File 'lib/appmap/trace.rb', line 134 def stacks @stacks end |
#thread_id ⇒ Object (readonly)
Returns the value of attribute thread_id.
135 136 137 |
# File 'lib/appmap/trace.rb', line 135 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
147 148 149 |
# File 'lib/appmap/trace.rb', line 147 def enable @enabled = true end |
#enabled? ⇒ Boolean
151 152 153 |
# File 'lib/appmap/trace.rb', line 151 def enabled? @enabled end |
#event? ⇒ Boolean
Whether there is an event available for processing.
199 200 201 |
# File 'lib/appmap/trace.rb', line 199 def event? !@events.empty? && @events.first.ready? end |
#event_methods ⇒ Object
Gets a unique list of the methods that were invoked by the program.
194 195 196 |
# File 'lib/appmap/trace.rb', line 194 def event_methods @methods.to_a end |
#last_package_for_current_thread ⇒ Object
Gets the last package which was observed on the current thread.
189 190 191 |
# File 'lib/appmap/trace.rb', line 189 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.
204 205 206 |
# File 'lib/appmap/trace.rb', line 204 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 |
# File 'lib/appmap/trace.rb', line 163 def record_event(event, package: nil, defined_class: nil, method: nil) return unless @enabled raise "Expected event in thread #{@thread_id}, got #{event.thread_id}" if @thread_id && @thread_id != event.thread_id @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
184 185 186 |
# File 'lib/appmap/trace.rb', line 184 def record_method(method) @methods << method end |