From: Robert Klemme Date: 2005-11-05T06:42:16+09:00 Subject: Re: Getting a stack trace of a running Ruby program. Ron M wrote: > Is there a way of displaying the stack trace of a running ruby > program without killing it? > Java virtual machines(*) will show the stack trace(s) of a running > program if you send them a QUIT signal (or on windows ) > without > stopping the program. On Linux, the "pstack" program gives you the same > capabilities for C programs. > > This is useful when a program runs for days and gets gradually > slower. By periodically sending QUIT signals you can essentally poll the > program's stack to see where it's getting slow. > > Is there any way to do similar in Ruby? Even if I need to attach > using GDB, it would help me - but I'd need someone to point me to what > data > structures I should look at with the debugger. Otherwise, I think > it'd be a really nice feature if, like java, a QUIT signal could show the > stack trace(s) of the existing nthread(s) without killing an > application > > Ron > > * > http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/ > * http://linuxcommand.org/man_pages/pstack1.html 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 robert