2017-06-23 89 views

回答

0

有螺纹#回溯方法来获取功能回溯一些线索:

https://ruby-doc.org/core-2.4.1/Thread.html#method-i-backtrace

backtrace→阵列点击展开源

返回目标线程的当前回溯。

的使用示例检查项目:https://github.com/frsyuki/sigdump(它会显示回溯和红宝石和JRuby一些内存使用信息)

sigdump - 简而言之:Java虚拟机的SIGQUIT为Ruby(使用信号显示Ruby进程的堆栈跟踪而不重新启动它)。

...只要发送SIGCONT信号就会将回溯和内存配置文件转储到/tmp/sigdump-.log文件。

sigdump转储以下信息(见样本输出):

回溯所有线程

https://github.com/frsyuki/sigdump/blob/master/lib/sigdump.rb

dump_all_thread_backtrace(io) 
... 
    Thread.list.each do |thread| 
     dump_backtrace(thread, io) 
... 
    def self.dump_backtrace(thread, io) 
    status = thread.status 
    if status == nil 
     status = "finished" 
    elsif status == false 
     status = "error" 
    end 

    io.write " Thread #{thread} status=#{status} priority=#{thread.priority}\n" 
    if thread.backtrace 
     thread.backtrace.each {|bt| 
     io.write "  #{bt}\n" 
     } 
    end 

    io.flush 
    nil 
    end 
+0

或查看的:http://itreallymatters.net/post/ 29549982905/generate-thread-dumps-for-ruby-scripts(and about thread#backtrace:“*此方法存在于1.9中。对于较早的Ruby版本,有一个不同的解决方案,这不是很好,因为它只适用于当前线。*”) – osgx

相关问题