def global_backtrace_report
if Kernel.respond_to?(:caller_for_all_threads)
all_thread_stacks = caller_for_all_threads
elsif Thread.respond_to?(:list) && Thread.public_method_defined?(:backtrace)
all_thread_stacks = {}
Thread.list.each do |thread|
all_thread_stacks[thread] = thread.backtrace
end
end
output = "========== Process #{Process.pid}: backtrace dump ==========\n"
if all_thread_stacks
all_thread_stacks.each_pair do |thread, stack|
if thread_name = thread[:name]
thread_name = "(#{thread_name})"
end
output << ("-" * 60) << "\n"
output << "# Thread: #{thread.inspect}#{thread_name}, "
if thread == Thread.main
output << "[main thread], "
end
if thread == Thread.current
output << "[current thread], "
end
output << "alive = #{thread.alive?}\n"
output << ("-" * 60) << "\n"
output << " " << stack.join("\n ")
output << "\n\n"
end
else
output << ("-" * 60) << "\n"
output << "# Current thread: #{Thread.current.inspect}\n"
output << ("-" * 60) << "\n"
output << " " << caller.join("\n ")
end
return output
end