Created
January 31, 2019 00:08
-
-
Save jcoglan/6490a2c2232239c46bf91fec86f752d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "set" | |
mods = Class.ancestors + | |
Method.ancestors + | |
UnboundMethod.ancestors | |
reserved = %i[ | |
== | |
=== | |
=~ | |
caller | |
first | |
split | |
] | |
project = %r{/jit/lib/} | |
$called = SortedSet.new | |
def exit(*) | |
File.open("calls.log", "w") do |f| | |
$called.each { |thing| f.puts thing.inspect } | |
end | |
super | |
end | |
ObjectSpace.each_object(Module) do |mod| | |
next if mods.include?(mod) | |
mod.instance_methods(false).each do |m_name| | |
next if reserved.include?(m_name) | |
method = mod.instance_method(m_name) | |
next if method.source_location.to_s =~ project | |
key = [mod.inspect, m_name] | |
mod.module_eval do | |
define_method m_name do |*args, &blk| | |
file = caller.first.split(":").first | |
$called.add(key) if file != __FILE__ and file =~ project | |
method.bind(self).call(*args, &blk) | |
end | |
end | |
rescue FrozenError | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment