views:

30

answers:

2

Hi folks, I have a function that is being called more than a thousand times, slowing everything down. However, it is a low level function, and do not know which of my high level function is lopping and making these calls. How can i find out?

+1  A: 

If the low-level function is written in Ruby, reopen its class and use alias_method_chain:

class TheClass
  def low_level_with_debug_output
    puts "I am being called by #{caller.first.inspect}"
    low_level_without_debug_output
  end

  alias_method_chain :low_level, :debug_output
end

alias_method_chain is a Rails-ism.

If the low-level function is not written in Ruby, you may need to instead use ruby-debug or even gdb on the interpreter itself to get at the stack trace.

x1a4
Thanks! I did this, and it showed me the following error. Any idea what went wrong?"Expected /Users/mingyeow/mrtweet/lib/formatter/user_formatter.rb to define Formatter::UserFormatter"
ming yeow
You may have reopened the class incorrectly? Without seeing all the code I can't be sure
x1a4