class Myco::DEV::CallSites

Public Class Methods

analyze_module(mod, list) click to toggle source
# File lib/myco/dev/call_sites.rb, line 23
def analyze_module(mod, list)
  mod.method_table.each_entry do |name, executable, _|
    if executable.respond_to?(:call_sites)
      executable.call_sites.each do |cache|
        called = "#{cache.stored_module}##{cache.method.name}" rescue "#{cache.name}"
        caller = "#{mod}##{name}"
        location = "#{executable.active_path}:#{executable.line_from_ip(0)}"
        
        list.push [cache.hits, "#{called} in #{caller} near #{location}"]
      end
    end
  end
end
report(*modules) click to toggle source
# File lib/myco/dev/call_sites.rb, line 7
def report(*modules)
  list = []
  if modules.empty?
    ObjectSpace.each_object(Module) { |mod| analyze_module(mod, list) }
  else
    modules.each { |mod| analyze_module(mod, list) }
  end
  list.uniq.sort
end
report!(*args, count: 2000) click to toggle source
# File lib/myco/dev/call_sites.rb, line 17
def report!(*args, count: 2000)
  list = report(*args)
  list = list[-count..-1] if list.size > count
  list.each { |item| p item }
end