Class: AppMap::Tracer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#eventsObject (readonly)

Returns the value of attribute events.



135
136
137
# File 'lib/appmap/trace.rb', line 135

def events
  @events
end

#stacksObject

Returns the value of attribute stacks.



134
135
136
# File 'lib/appmap/trace.rb', line 134

def stacks
  @stacks
end

#thread_idObject (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

#disableObject

Private function. Use AppMap.tracing#delete.



156
157
158
# File 'lib/appmap/trace.rb', line 156

def disable # :nodoc:
  @enabled = false
end

#enableObject



147
148
149
# File 'lib/appmap/trace.rb', line 147

def enable
  @enabled = true
end

#enabled?Boolean

Returns:

  • (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.

Returns:

  • (Boolean)


199
200
201
# File 'lib/appmap/trace.rb', line 199

def event?
  !@events.empty? && @events.first.ready?
end

#event_methodsObject

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_threadObject

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_eventObject

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