Dump each method called to stdout?

I’ve got a script that loops through a bunch of stuff and somewhere in the
middle (not the same place each time) it’s hanging.

Is there a quick way to hook each method call so I can output the method
name to stdout so I can see the last method called before the hang?
Debugging won’t work well – I’d have to step through every line numerous
times until it just happened to hang wherever it does, and I have no idea if
the debugging environ would affect it.

Chris
http://clabs.org

I've got a script that loops through a bunch of stuff and somewhere
in the middle (not the same place each time) it's hanging.

Is there a quick way to hook each method call so I can output the
method name to stdout so I can see the last method called before the
hang? Debugging won't work well -- I'd have to step through every
line numerous times until it just happened to hang wherever it does,
and I have no idea if the debugging environ would affect it.

What I've done before is set counters that only print goo every few
minutes + a stack trace.

count = 0
while true

  # do stuff
  begin
    if count == 100
      count = 0
      raise "Uga"
  rescue => e
    print e.backtrace.join("\n")
  end

  # do more stuff...

  count += 1
end

There are other ways of doing things, but I've found that to be a
decent way of figuring out what's going on in tight loops... you might
want to toss in counter that doesn't ever get reset and a time index
but I think you get the concept. -sc

···

--
Sean Chittenden

Chris Morris wrote:

Is there a quick way to hook each method call so I can output the method
name to stdout so I can see the last method called before the hang?

I think Kernel#set_trace_func will probably do what you want:

http://www.rubycentral.com/book/ref_m_kernel.html#Kernel.set_trace_func

Hope this helps,

Lyle

The simplest solution is to use:
require ‘tracer’

but that might give you more output than you want.

Paul

···

On Sat, Sep 14, 2002 at 05:11:29AM +0900, Chris Morris wrote:

I’ve got a script that loops through a bunch of stuff and somewhere in the
middle (not the same place each time) it’s hanging.

Is there a quick way to hook each method call so I can output the method
name to stdout so I can see the last method called before the hang?
Debugging won’t work well – I’d have to step through every line numerous
times until it just happened to hang wherever it does, and I have no idea if
the debugging environ would affect it.

What I’ve done before is set counters that only print goo every few
minutes + a stack trace.

I see what you mean … but my problem is that each loop basically calls one
method which encapsulates a ton of stuff, and it’s somewhere in that deep
tree of objects calling other objects that it hangs – I just don’t know
where. Your solution for my particular problem would simply let me know
which time through the loop it hung – but it’s already being inconsistent
on which time it hangs (sometimes it’s the 7th time through, sometimes the
10th…).

I did find this in pickaxe which works great, but unfortunately drastically
affected when my program hung (it hangs much earlier now … sigh):

http://www.rubycentral.com/book/ospace.html#S5

(In addition, AspectR was recommended for this sort of thing in previous
threads – but the above solution is much faster to add…)

Chris
http://clabs.org

In article 20020913171222.E26613@atdesk.com,

···

Paul Brannan pbrannan@atdesk.com wrote:

On Sat, Sep 14, 2002 at 05:11:29AM +0900, Chris Morris wrote:

I’ve got a script that loops through a bunch of stuff and somewhere in the
middle (not the same place each time) it’s hanging.

Is there a quick way to hook each method call so I can output the method
name to stdout so I can see the last method called before the hang?
Debugging won’t work well – I’d have to step through every line numerous
times until it just happened to hang wherever it does, and I have no idea if
the debugging environ would affect it.

The simplest solution is to use:
require ‘tracer’

but that might give you more output than you want.

    • ruby -r tracer rubyfile

does the same thing.

    • Booker C. Bense

Timeout it, and you’ll see where the exception pop’s up?

timeout(hangtime) {
problem_code
}

– Nikodemus

···

On Sat, 14 Sep 2002, Chris Morris wrote:

I see what you mean … but my problem is that each loop basically calls one
method which encapsulates a ton of stuff, and it’s somewhere in that deep
tree of objects calling other objects that it hangs – I just don’t know