Posted by Anurag in
Thursday, December 15. 2011
At times you may need to trace a ruby program's execution flow. Ruby's set_trace_func comes handy there.
When saved in a file called trace.rb and executed with $ ruby trace.rb, it outputs
2011-12-15 00:33:26 +0530 c-return trace.rb:3 set_trace_func Kernel
2011-12-15 00:33:26 +0530 line trace.rb:5
2011-12-15 00:33:26 +0530 c-call trace.rb:5 puts Kernel
2011-12-15 00:33:26 +0530 c-call trace.rb:5 puts IO
2011-12-15 00:33:26 +0530 c-call trace.rb:5 write IO
*** Hello World
2011-12-15 00:33:26 +0530 c-return trace.rb:5 write IO
2011-12-15 00:33:26 +0530 c-return trace.rb:5 puts IO
2011-12-15 00:33:26 +0530 c-return trace.rb:5 puts Kernel