Skip to content

Instantly share code, notes, and snippets.

@JesusTinoco
Created September 28, 2017 11:22
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 JesusTinoco/a6bce16c056ac35df1b8da883b694708 to your computer and use it in GitHub Desktop.
Save JesusTinoco/a6bce16c056ac35df1b8da883b694708 to your computer and use it in GitHub Desktop.
# trace the whatever_code_to_be_traced
trace(:call) do
whatever_code_to_be_traced
end
# filter by 'state_machine' files
trace(:call, 'state_machine') do
whatever_code_to_be_traced
end
def trace(event_type = :call, *matchers)
points = []
tracer = TracePoint.new(event_type) do |trace_point|
if matchers.all? { |match| trace_point.path.match(match) }
points << { file: trace_point.path, line: trace_point.lineno, }
end
end
result = tracer.enable { yield }
File.open('/tmp/trace.txt', 'w') do |file|
points.each do |point|
file.puts "#{point[:file]}:#{point[:line]}"
end
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment