lib/appmap/trace.rb in appmap-0.100.0 vs lib/appmap/trace.rb in appmap-0.101.0
- old
+ new
@@ -22,11 +22,11 @@
def comment
return nil if source_location.nil? || source_location.first.start_with?('<')
# Do not use method_source's comment method because it's slow
- @comment ||= RubyMethod.last_comment *source_location
+ @comment ||= RubyMethod.last_comment(*source_location)
rescue Errno::EINVAL, Errno::ENOENT
nil
end
def package
@@ -39,12 +39,10 @@
def labels
@package.labels
end
- private
-
# Read file and get last comment before line.
def self.last_comment(file, line_number)
File.open(file) do |f|
buffer = []
f.each_line.lazy.take(line_number - 1).reverse_each do |line|
@@ -112,23 +110,23 @@
(ENV['APPMAP_STACK_DEPTH'] || 20).to_i
end
end
def initialize
- @@stacks ||= Hash.new
+ @@stacks ||= {}
end
def record(event)
stack = caller.select { |line| !line.index('/lib/appmap/') }[0...StackPrinter.depth].join("\n ")
stack_hash = Digest::SHA256.hexdigest(stack)
- unless @@stacks[stack_hash]
- @@stacks[stack_hash] = stack
- puts
- puts 'Event: ' + event.to_h.map { |k, v| [ "#{k}: #{v}" ] }.join(", ")
- puts ' ' + stack
- puts
- end
+ return if @@stacks[stack_hash]
+
+ @@stacks[stack_hash] = stack
+ puts
+ puts 'Event: ' + event.to_h.map { |k, v| [ "#{k}: #{v}" ] }.join(', ')
+ puts ' ' + stack
+ puts
end
end
class Tracer
attr_accessor :stacks
@@ -161,10 +159,12 @@
#
# The event should be one of the MethodEvent subclasses.
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
+ if @thread_id && @thread_id != event.thread_id
+ raise "Expected event in thread #{@thread_id}, got #{event.thread_id}"
+ end
@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)