Skip to content

Commit

Permalink
Waiter: clarify thread dump logging
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle committed Nov 20, 2016
1 parent 4611615 commit 77c2a20
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/hutch/waiter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

module Hutch
# Signal-handling class.
#
# Currently, the signal USR2 performs a thread dump,
# while QUIT, TERM and INT all perform a graceful shutdown.
class Waiter
include Logging

Expand Down Expand Up @@ -45,29 +48,34 @@ def handle_signal(sig)
end
end

def handle_shutdown_signal(sig)
logger.info "caught SIG#{sig}, stopping hutch..."
end

# @raises ContinueProcessingSignals
def handle_user_signal(sig)
case sig
when 'USR2' then handle_usr2
when 'USR2' then log_thread_backtraces
else raise "Assertion failed - unhandled signal: #{sig.inspect}"
end
raise ContinueProcessingSignals
end

def handle_shutdown_signal(sig)
logger.info "caught SIG#{sig}, stopping hutch..."
end

private

def handle_usr2
def log_thread_backtraces
logger.info 'Requested a VM-wide thread stack trace dump...'
Thread.list.each do |thread|
logger.warn "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
if thread.backtrace
logger.warn thread.backtrace.join("\n")
else
logger.warn '<no backtrace available>'
end
logger.info "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
logger.info backtrace_for(thread)
end
end

def backtrace_for(thread)
if thread.backtrace
thread.backtrace.join("\n")
else
'<no backtrace available>'
end
end

Expand Down

0 comments on commit 77c2a20

Please sign in to comment.