Class: AppMap::Trace::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/appmap/trace/tracer.rb

Instance Method Summary collapse

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

#disableObject

Private function. Use AppMap.tracers#delete.



314
315
316
# File 'lib/appmap/trace/tracer.rb', line 314

def disable # :nodoc:
  @trace_point.disable
end

#enableObject



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_eventObject

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