1

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?

meow
  • 27,476
  • 33
  • 116
  • 177

1 Answers1

1

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
  • 19,417
  • 5
  • 40
  • 40
  • 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" – meow May 19 '10 at 02:02
  • You may have reopened the class incorrectly? Without seeing all the code I can't be sure – x1a4 May 19 '10 at 08:02