TraceTree
Print TracePoint(:b_call, :b_return, :c_call, :c_return, :call, :return, :class, :end, :thread_begin, :thread_end) in tree view, to console or html.
Notice: it does not trace :raise, which can be represented by Kernel#raise(:c_call)
Installation
Add this line to your application's Gemfile:
gem 'trace_tree'
And then execute:
$ bundle
Or install it yourself as:
$ gem install trace_tree
Usage
Just call the method you want to trace in the block passed to binding.trace_tree:
things_done = binding.trace_tree do
somebody.do_something
end
Parameters
You may pass optional parameters while invoking binding.trace_tree, for example:
binding.trace_tree(file, color: false, gem: false) do
somebody.do_something
end
file == STDOUTby default. You can give it a File object or anything responds toputs.:color => trueby default. It makes method names have different color than source_location in output. When you print the output to file, you may want to set it false to discard those color ANSI escape sequences.:gem => trueby default. Replace the gem paths in source_location with $GemPathN, can make the lines shorter. To see what are replaced, inspectTraceTree::GemPaths.:html => nilby default. Set it true to generate a html in which a tree constructed with<ul>,<li>. (No need to setcolor).:tmp => nilby default. Set it true or a string or an array of string to specify a tmp file under the default tmp dir of your system. (No need to providefileargument. It makes parent directories as needed):timer => nilby default. Set it true if you want to know how much time spent in tracing and drawing tree. Notice thefileshould be appendable, otherwise the time will overwrite the tree.
Example
Want to know what Sinatra::Base#call does? Wrap it with binding.trace_tree:
require 'sinatra'
require 'trace_tree'
get '/' do
'welcome'
end
class Sinatra::Base
alias_method :o_call, :call
def call env
binding.trace_tree do
o_call env
end
end
end
Execute that sinatra script as normal, then you will see in console:
Sinatra::Application#block in call sin.rb:12