01 Oct 2009, 17:35
Generic-user-small

Robert Winter (5 posts)

All,

I’m trying to use the trace_calls.rb module on the boot.rb file of Rails (Rails 2.3.4 on Ruby 1.8.7) in order to understand the startup of rails. I have some questions and observations:

- I added caller.first to the statement puts "==> calling #{method} with #{args.inspect} in #{caller.first}
This revealed that every method is being reported twice. Once for the original invocation and once for the invocation in trace_calls.rb. I solved it with an if caller.first !~ %r{lib/trace_calls\.rb} statement. Is there a better way?

- I added include TraceCalls statements as follows (reproducing a small portion of boot.rb for reference for below questions):


Module Rails
  include TraceCalls

  class << self
    include TraceCalls
    def boot!
      unless booted?
        preinitialize
        pick_boot.run
      end
    end

    def pick_boot
      (vendor_rails? ? VendorBoot : GemBoot).new
    end
  end

  class Boot
    include TraceCalls
    def run
      ; # stuff omitted
    end
  end

  class VendorBoot < Boot
    include TraceCalls
    ; # stuff omitted
  end

  ; #stuff omitted
end
Rails.boot!


The first two includes do not work. The last two includes do work. Trying to understand why has led me to wish for a chart comparing and contrasting the different ways of creating classes, methods, instance variables, and class variables. Perhaps I’ll build it. Does the above non-working code have anything to do with ‘instance methods’ versus ‘module methods’?

Anyone have a clue why the trace_calls module isn’t working in the top part of boot.rb?

- Is the final statement Rails.boot! a module method invocation?

- My last comment is a ‘wish list’ item. Is it possible for the trace_calls module to figure out when a method being invoked is from an ancestor of the current object? In the above code, since I’ve put rails in the vendor directory, from the pick_boot.run statement I get a VendorBoot object, but invoke the run method of the Boot class.

Thanks,
-Robert

01 Oct 2009, 20:06
Generic-user-small

Robert Winter (5 posts)

I’ve managed to figure that it’s related to the ‘singleton_method_added’ callback. Trace_calls.rb does not define that callback. But I’m not sure how to fix it – my first several attempts have not worked.

  You must be logged in to comment