lib/appmap/trace.rb in appmap-0.102.2 vs lib/appmap/trace.rb in appmap-0.103.0

- old
+ new

@@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'delegate' +require "delegate" module AppMap module Trace class RubyMethod < SimpleDelegator attr_reader :class_name, :static @@ -19,11 +19,11 @@ def source_location @method.source_location end def comment - return nil if source_location.nil? || source_location.first.start_with?('<') + 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) rescue Errno::EINVAL, Errno::ENOENT nil @@ -69,12 +69,12 @@ @tracers << tracer tracer.enable if enable end end - def enabled? - @tracers.any?(&:enabled?) + def enabled?(thread_id: nil) + @tracers.any? { |t| t.enabled?(thread_id: thread_id) } end def last_package_for_current_thread @tracers.first&.last_package_for_current_thread end @@ -101,38 +101,38 @@ end class StackPrinter class << self def enabled? - ENV['APPMAP_PRINT_STACKS'] == 'true' + ENV["APPMAP_PRINT_STACKS"] == "true" end def depth - (ENV['APPMAP_STACK_DEPTH'] || 20).to_i + (ENV["APPMAP_STACK_DEPTH"] || 20).to_i end end def initialize @@stacks ||= {} end def record(event) - stack = caller.select { |line| !line.index('/lib/appmap/') }[0...StackPrinter.depth].join("\n ") + stack = caller.select { |line| !line.index("/lib/appmap/") }[0...StackPrinter.depth].join("\n ") stack_hash = Digest::SHA256.hexdigest(stack) return if @@stacks[stack_hash] @@stacks[stack_hash] = stack puts - puts 'Event: ' + event.to_h.map { |k, v| [ "#{k}: #{v}" ] }.join(', ') - puts ' ' + stack + puts "Event: " + event.to_h.map { |k, v| ["#{k}: #{v}"] }.join(", ") + puts " " + stack puts end end class Tracer attr_accessor :stacks - attr_reader :thread_id, :events + attr_reader :thread_id, :events # Records the events which happen in a program. def initialize(thread_id: nil) @events = [] @last_package_for_thread = {} @@ -144,11 +144,13 @@ def enable @enabled = true end - def enabled? - @enabled + def enabled?(thread_id: nil) + return false unless @enabled + + thread_id.nil? || @thread_id.nil? || @thread_id == thread_id end # Private function. Use AppMap.tracing#delete. def disable # :nodoc: @enabled = false