2
是否有可能从另一个线程得到一个线程的Kernel#caller
输出?或者甚至更好的是来自后台的主线程的堆栈,这对于我来说可以用作一种分析器。如何获得另一个线程的调用堆栈?
是否有可能从另一个线程得到一个线程的Kernel#caller
输出?或者甚至更好的是来自后台的主线程的堆栈,这对于我来说可以用作一种分析器。如何获得另一个线程的调用堆栈?
有螺纹#回溯方法来获取功能回溯一些线索:
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
或查看的:http://itreallymatters.net/post/ 29549982905/generate-thread-dumps-for-ruby-scripts(and about thread#backtrace:“*此方法存在于1.9中。对于较早的Ruby版本,有一个不同的解决方案,这不是很好,因为它只适用于当前线。*”) – osgx