On Sat, 5 Nov 2005, Ron M wrote:

> Robert Klemme wrote:
>> Ron M <rm_rails / cheapcomplexdevices.com> wrote:
>> 
>>> Is there a way of displaying the stack trace of a running ruby
>>> [like] Java  QUIT signal
>>> [or] the "pstack" program gives you the same capabilities for C programs.
>> 
>> I prefer to use real profiling tools instead of looking at a single 
>> stacktrace.  In Java that would be -Xrunhprof, OptimizeIt et al.  In Ruby 
>> you can use -r profile for profiling.  Also, there's module Benchmark which 
>> is less intrusive than the profiler.  Finally there's set_trace_func which 
>> can be used to generate call stacks for each thread and print them to 
>> console on a signal similarly to your Java approach.
>> 
>> HTH
>
> These all work fine for relatively short-lived programs; but
> do little to help in a progam that runs for days and only gets
> slow after many hours of running.
>
> On short runs (few hours) my program works fine (processes
> dozens of records per second) but after half a day or so
> it slows to taking a few seconds per record.  "-r profile"
> and set_trace_func are pretty intrusive and I fear my
> program that runs for days would take weeks.    Benchmark
> has the disadvantage of needing to know what piece of code
> to measure; rather than exposing the slow part.
>
> But the biggest advantage in my mind of sampling instantaneous
> snapshots of the stack is that it works on any program witout
> modification (well, linux's ptrace is most useful if you didn't
> strip signals); and it's  almost totally non-intrusive, and does
> not skew the timing results at all.

so send it a signal that makes it fork and dump core - then you can do

   gdb ruby core.1234

whamo.

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================