module ProductionBreakpoints

Constants

VERSION

The current version of this gem

Attributes

installed_breakpoints[RW]

Public Instance Methods

config() click to toggle source
# File lib/ruby-production-breakpoints.rb, line 29
def config
  unless defined?(@configuration)
    raise NotConfiguredError
  end

  @configuration
end
configure() { |configuration| ... } click to toggle source
# File lib/ruby-production-breakpoints.rb, line 23
def configure
  @configuration = Configuration.new
  yield @configuration
  @configuration.finish!
end
disable!() click to toggle source
# File lib/ruby-production-breakpoints.rb, line 63
def disable!
  installed_breakpoints.each do |trace_id, _bp|
    disable_breakpoint(trace_id)
  end
end
disable_breakpoint(trace_id) click to toggle source
# File lib/ruby-production-breakpoints.rb, line 57
def disable_breakpoint(trace_id)
  breakpoint = installed_breakpoints.delete(trace_id)
  breakpoint.unload
  breakpoint.uninstall
end
install_breakpoint(type, source_file, start_line, end_line, trace_id: 1) click to toggle source

For now add new types here

# File lib/ruby-production-breakpoints.rb, line 38
def install_breakpoint(type, source_file, start_line, end_line, trace_id: 1)
  # Hack to check if there is a supported breakpoint of this type for now
  case type.name
  when 'ProductionBreakpoints::Breakpoints::Latency'
  when 'ProductionBreakpoints::Breakpoints::Inspect'
  when 'ProductionBreakpoints::Breakpoints::Locals'
    # logger.debug("Creating latency tracer")
    # now rewrite source to call this created breakpoint through parser
  else
    config.logger.error("Unsupported breakpoint type #{type}")
  end

  breakpoint = type.new(source_file, start_line, end_line, trace_id: trace_id)
  installed_breakpoints[trace_id] = breakpoint
  puts installed_breakpoints.keys
  breakpoint.install
  breakpoint.load
end
sync!() click to toggle source
# File lib/ruby-production-breakpoints.rb, line 69
  def sync!
    # FIXME: don't just install, also remove - want to 'resync'
    # logger.debug("Resync initiated")
    config.reload!
    desired = config.configured_breakpoints['breakpoints']

    desired_trace_ids = desired.map { |bp| bp['trace_id'] }
    installed_trace_ids = installed_breakpoints.keys

    to_install_tids = desired_trace_ids - installed_trace_ids
    to_remove_tids = installed_trace_ids - desired_trace_ids
    to_install = desired.select { |bp| to_install_tids.include?(bp['trace_id']) }
    puts "Will install #{to_install.size} breakpoints"
    puts "Will remove #{to_remove_tids.size} breakpoints"
    to_install.each do |bp|
      handler = breakpoint_constant_for_type(bp)
      unless valid_start_line_end_line?(bp['source_file'], bp['start_line'], bp['end_line'])
        msg = <<~MSG
          Skipping #{handler} for #{bp['source_file']}. start line and end line do not point to any code on the file.
        MSG
        config.logger.warn(msg)
        next
      end
      install_breakpoint(handler, bp['source_file'], bp['start_line'], bp['end_line'], trace_id: bp['trace_id'])
    end

    to_remove_tids.each do |trace_id|
      disable_breakpoint(trace_id)
    end
  end

Private Instance Methods

breakpoint_constant_for_type(bp) click to toggle source
# File lib/ruby-production-breakpoints.rb, line 106
def breakpoint_constant_for_type(bp)
  symstr = "ProductionBreakpoints::Breakpoints::#{bp['handler'].capitalize}"
  Object.const_get(symstr)
rescue NameError
  config.logger.error("Could not find breakpoint handler for #{symstr}")
end
valid_start_line_end_line?(source_file, start_line, end_line) click to toggle source
# File lib/ruby-production-breakpoints.rb, line 102
def valid_start_line_end_line?(source_file, start_line, end_line)
  StartEndLineValidator.call(source_file, start_line, end_line)
end