It's been a while since this has been revised. This revision seeks to make the following easier: It's hard to find the beginning and end of thread dumps, particularly if they are consecutive. Solution: add `--BEGIN...` and `--END...` framing, plus a disambiguating timestamp that matches between the two. The rough inspiration is MIME format of email. The thread dumps are often triggered by apoptosis, which needs to exit the entire process in a timely manner to maintain mutual exclusion. In doing so, it does collatoral damage to other threads that happen to be running in the same process at the time. The thread dump emitted likewise includes every thread, not just the problematic one. So, print the thread age, when available. The oldest are most likely to be implicated. To make the thread age available in the case I care about most, the `created_at` thread local variable is set in the dispatcher which runs Strands.
19 lines
414 B
Ruby
19 lines
414 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ThreadPrinter
|
|
def self.run
|
|
now = Time.now
|
|
puts "--BEGIN THREAD DUMP, #{now}"
|
|
Thread.list.each do |thread|
|
|
puts "Thread: #{thread.inspect}"
|
|
|
|
if (created_at = thread[:created_at])
|
|
puts "Created at: #{created_at}, #{now - created_at} ago"
|
|
end
|
|
|
|
puts thread.backtrace&.join("\n")
|
|
end
|
|
puts "--END THREAD DUMP, #{now}"
|
|
end
|
|
end
|