Skip to content

Instantly share code, notes, and snippets.

@apneadiving
Created August 14, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apneadiving/2304f41f6f6544fb76f2 to your computer and use it in GitHub Desktop.
Save apneadiving/2304f41f6f6544fb76f2 to your computer and use it in GitHub Desktop.
trace methods
def trace_calls_on
scope = {}
trace = TracePoint.new(:call, :line) do |tp|
case tp.event
when :call then puts "#{tp.path}:#{tp.lineno} #{tp.defined_class}::#{tp.method_id} " \
"called from #{scope[:path]}:#{scope[:lineno]} #{scope[:class]}::#{scope[:method_id]}"
when :line then scope = {
event: :line,
lineno: tp.lineno,
path: tp.path,
class: tp.defined_class,
method_id: tp.method_id
}
end
end
trace.enable
yield
trace.disable
end
require 'open-uri'
trace_calls_on do
open('http://google.com', proxy: nil)
end
@apneadiving
Copy link
Author

credit @toch

@apneadiving
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment