Sha256: a679b8ca3012d97f7e612842f5666738d8ff88eec9671e0a6101b8990a85b135
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true module AppMap module Trace ScopedMethod = Struct.new(:defined_class, :method) class Tracers def initialize @tracers = [] end def empty? @tracers.empty? end def trace(enable: true) Tracer.new.tap do |tracer| @tracers << tracer tracer.enable if enable end end def enabled? @tracers.any?(&:enabled?) end def record_event(event, defined_class: nil, method: nil) @tracers.each do |tracer| tracer.record_event(event, defined_class: defined_class, method: method) end end def delete(tracer) return unless @tracers.member?(tracer) @tracers.delete(tracer) tracer.disable end end end class Tracer # Records the events which happen in a program. def initialize @events = [] @methods = Set.new @enabled = false end def enable @enabled = true end def enabled? @enabled end # Private function. Use AppMap.tracing#delete. def disable # :nodoc: @enabled = false end # Record a program execution event. # # The event should be one of the MethodEvent subclasses. def record_event(event, defined_class: nil, method: nil) return unless @enabled @events << event @methods << Trace::ScopedMethod.new(defined_class, method) if defined_class && method end # Gets a unique list of the methods that were invoked by the program. def event_methods @methods.to_a end # Whether there is an event available for processing. def event? !@events.empty? end # Gets the next available event, if any. def next_event @events.shift end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
appmap-0.27.0 | lib/appmap/trace.rb |