Last active
August 29, 2015 14:17
-
-
Save brainopia/806d4cc48b644ee941ef to your computer and use it in GitHub Desktop.
method_calls
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
def method_calls(detailed: false, thread: nil) | |
[].tap do |log| | |
ident = -1 | |
trace = TracePoint.new(:call, :return, :c_call, :c_return) do |tp| | |
break if thread and thread != Thread.current | |
case tp.event | |
when :call, :c_call | |
if tp.event == :call or detailed | |
ident += 1 | |
log << [' '*ident + tp.defined_class.inspect + '#' + tp.method_id.to_s] | |
end | |
when :return, :c_return | |
if tp.event == :return or detailed | |
ident -= 1 | |
end | |
else | |
raise | |
end | |
end | |
trace.enable { yield } | |
end | |
end | |
Author
brainopia
commented
Mar 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment