Class: AppMap::Trace::Tracer
- Inherits:
-
Object
- Object
- AppMap::Trace::Tracer
- Defined in:
- lib/appmap/trace/tracer.rb
Instance Method Summary collapse
-
#disable ⇒ Object
Private function.
- #enable ⇒ Object
-
#event? ⇒ Boolean
Whether there is an event available for processing.
-
#initialize(functions) ⇒ Tracer
constructor
Trace a specified set of functions.
-
#lookup_function(path, lineno) ⇒ Object
Whether the indicated file path and lineno is a breakpoint on which execution should interrupted.
-
#next_event ⇒ Object
Gets the next available event, if any.
-
#record_event(event) ⇒ Object
Record a program execution event.
Constructor Details
#initialize(functions) ⇒ Tracer
Trace a specified set of functions.
functions Array of AppMap::Feature::Function.
294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/appmap/trace/tracer.rb', line 294 def initialize(functions) @functions = functions @functions_by_location = functions.each_with_object({}) do |m, memo| path, lineno = m.location.split(':', 2) memo[path] ||= {} memo[path][lineno.to_i] = m memo end @events_mutex = Mutex.new @events = [] end |
Instance Method Details
#disable ⇒ Object
Private function. Use AppMap.tracers#delete.
314 315 316 |
# File 'lib/appmap/trace/tracer.rb', line 314 def disable # :nodoc: @trace_point.disable end |
#enable ⇒ Object
308 309 310 311 |
# File 'lib/appmap/trace/tracer.rb', line 308 def enable handler = TracePointHandler.new(self) @trace_point = TracePoint.trace(:call, :return, &handler.method(:handle)) end |
#event? ⇒ Boolean
Whether there is an event available for processing.
This method is thread-safe.
340 341 342 343 344 |
# File 'lib/appmap/trace/tracer.rb', line 340 def event? @events_mutex.synchronize do !@events.empty? end end |
#lookup_function(path, lineno) ⇒ Object
Whether the indicated file path and lineno is a breakpoint on which execution should interrupted.
321 322 323 |
# File 'lib/appmap/trace/tracer.rb', line 321 def lookup_function(path, lineno) (methods_by_path = @functions_by_location[path]) && methods_by_path[lineno] end |
#next_event ⇒ Object
Gets the next available event, if any.
This method is thread-safe.
349 350 351 352 353 |
# File 'lib/appmap/trace/tracer.rb', line 349 def next_event @events_mutex.synchronize do @events.shift end end |
#record_event(event) ⇒ Object
Record a program execution event.
The event should be one of the MethodEvent subclasses.
This method is thread-safe.
331 332 333 334 335 |
# File 'lib/appmap/trace/tracer.rb', line 331 def record_event(event) @events_mutex.synchronize do @events << event end end |