Is there any way to print the runtime stack trace of a Ruby 1.9.x process? I know that there was a utility called pstack for Ruby 1.8, but the project appears to have been abandoned a couple years ago: https://github.com/ice799/pstack. Does anything like this exist for Ruby 1.9? Thanks a lot!
EDIT: I'm interested in using an external tool to generate the stack trace (not running in the same memory space as the Ruby process).
As @mosch pointed out, the Kernal#caller method works from within the running Ruby process.
You could even build in support to your Ruby code that traps process signals and prints a stack trace:
Signal.trap("SIGTERM") { p caller }
Reference: http://www.ruby-doc.org/core-1.9.3/Signal.html
I could build this functionality into my code, but I'd prefer to use a more generalized, external solution. Thanks.
Whenever you call the Kernel method caller, you will get the current call stack as an Array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With