Module: ProductionBreakpoints

Extended by:
ProductionBreakpoints
Included in:
ProductionBreakpoints
Defined in:
lib/ruby-production-breakpoints.rb,
lib/ruby-production-breakpoints/parser.rb,
lib/ruby-production-breakpoints/version.rb,
lib/ruby-production-breakpoints/platform.rb,
lib/ruby-production-breakpoints/configuration.rb,
lib/ruby-production-breakpoints/method_override.rb,
lib/ruby-production-breakpoints/breakpoints/base.rb,
lib/ruby-production-breakpoints/breakpoints/locals.rb,
lib/ruby-production-breakpoints/breakpoints/inspect.rb,
lib/ruby-production-breakpoints/breakpoints/latency.rb,
lib/ruby-production-breakpoints/start_end_line_validator.rb

Defined Under Namespace

Modules: Breakpoints, Platform, StartEndLineValidator Classes: Configuration, MethodOverride, Parser

Constant Summary collapse

VERSION =

The current version of this gem

'0.0.6'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#installed_breakpointsObject

Returns the value of attribute installed_breakpoints.



19
20
21
# File 'lib/ruby-production-breakpoints.rb', line 19

def installed_breakpoints
  @installed_breakpoints
end

Instance Method Details

#configObject



29
30
31
32
33
34
35
# File 'lib/ruby-production-breakpoints.rb', line 29

def config
  unless defined?(@configuration)
    raise NotConfiguredError
  end

  @configuration
end

#configure {|@configuration| ... } ⇒ Object

Yields:

  • (@configuration)


23
24
25
26
27
# File 'lib/ruby-production-breakpoints.rb', line 23

def configure
  @configuration = Configuration.new
  yield @configuration
  @configuration.finish!
end

#disable!Object



62
63
64
65
66
# File 'lib/ruby-production-breakpoints.rb', line 62

def disable!
  installed_breakpoints.each do |trace_id, _bp|
    disable_breakpoint(trace_id)
  end
end

#disable_breakpoint(trace_id) ⇒ Object



56
57
58
59
60
# File 'lib/ruby-production-breakpoints.rb', line 56

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) ⇒ Object

For now add new types here



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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.to_sym] = breakpoint
  breakpoint.install
  breakpoint.load
end

#sync!Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ruby-production-breakpoints.rb', line 68

def sync!
  # FIXME: don't just install, also remove - want to 'resync'
  # logger.debug("Resync initiated")
  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']) }
  # logger.debug("Will install #{to_install.size} breakpoints")
  # logger.debug("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 = "        Skipping \#{handler} for \#{bp['source_file']}. start line and end line do not point to any code on the file.\n      MSG\n      config.logger.warn(msg)\n      next\n    end\n    install_breakpoint(handler, bp['source_file'], bp['start_line'], bp['end_line'], trace_id: bp['trace_id'])\n  end\n\n  to_remove_tids.each do |trace_id|\n    disable_breakpoint(trace_id)\n  end\nend\n"