Create a gist now

Instantly share code, notes, and snippets.

@txus /.pryrc.rb
Last active Dec 18, 2015

What would you like to do?
Pry command to trace a method invocation and log backtraces of each invocation to a file.
def write_backtrace name, backtrace, filename
exceptions = Regexp.union([
backtrace.reject! { |line| line =~ exceptions }, 'a') do |f|
f.write "* #{name}\n\n" + backtrace.join("\n") + "\n\n"
# Example usage:
# trace Redis::Client#process my_redis_calls.log
Pry.commands.block_command(/trace ([^ ]+) ([^ ]+)$/, "Trace a method invocation and log it to a file", :listing => "trace") do |bp, filename|
run "breakpoint #{bp} if (write_backtrace(%{#{bp}}, caller, %{#{filename}}); false)"
run "continue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment