Created
November 23, 2023 06:05
-
-
Save vishless/8305520f3832a6d9074d673536add89c to your computer and use it in GitHub Desktop.
TracePoint wrapper for rails initializer
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
IGNORED_METHODS = [:visit_descendant_selector, :start_mapping, :end_mapping, :start_sequence, :end_sequence] | |
PRINT_PARAMS = false | |
trace = TracePoint.new(:call) do |tp| | |
#puts tp.methods-Object.methods | |
#exit | |
next if tp.path =~ /.rvm/ | |
next if IGNORED_METHODS.include? tp.method_id | |
puts "======== #{tp.path}" | |
puts "===================== #{tp.self.class}##{tp.method_id}" | |
#puts "===================== #{tp.callee_id} =====================" | |
#puts "defined class => #{tp.defined_class}" | |
if PRINT_PARAMS | |
b_self = tp.binding.eval('self') | |
names = b_self.method(tp.method_id).parameters.map(&:last) | |
values = names.map { |name| tp.binding.eval(name.to_s) } | |
p names.zip(values) | |
end | |
end | |
#trace.enable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment