Class: AppMap::Tracer
- Inherits:
-
Object
- Object
- AppMap::Tracer
- Defined in:
- lib/appmap/trace.rb
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 ⇒ 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 ⇒ Tracer
Records the events which happen in a program.
89 90 91 92 93 94 |
# File 'lib/appmap/trace.rb', line 89 def initialize @events = [] @last_package_for_thread = {} @methods = Set.new @enabled = false end |
Instance Method Details
#disable ⇒ Object
Private function. Use AppMap.tracing#delete.
105 106 107 |
# File 'lib/appmap/trace.rb', line 105 def disable # :nodoc: @enabled = false end |
#enable ⇒ Object
96 97 98 |
# File 'lib/appmap/trace.rb', line 96 def enable @enabled = true end |
#enabled? ⇒ Boolean
100 101 102 |
# File 'lib/appmap/trace.rb', line 100 def enabled? @enabled end |
#event? ⇒ Boolean
Whether there is an event available for processing.
145 146 147 |
# File 'lib/appmap/trace.rb', line 145 def event? !@events.empty? end |
#event_methods ⇒ Object
Gets a unique list of the methods that were invoked by the program.
140 141 142 |
# File 'lib/appmap/trace.rb', line 140 def event_methods @methods.to_a end |
#last_package_for_current_thread ⇒ Object
Gets the last package which was observed on the current thread.
135 136 137 |
# File 'lib/appmap/trace.rb', line 135 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.
150 151 152 |
# File 'lib/appmap/trace.rb', line 150 def next_event @events.shift 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.
112 113 114 115 116 117 118 119 120 |
# File 'lib/appmap/trace.rb', line 112 def record_event(event, package: nil, defined_class: nil, method: nil) return unless @enabled @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
130 131 132 |
# File 'lib/appmap/trace.rb', line 130 def record_method(method) @methods << method end |