Permalink
Browse files

Improved stack dumper

  • Loading branch information...
1 parent 9c038df commit 5fc84e0e77d86beffc083aa050df6cbc68d8fe71 @tarcieri tarcieri committed Sep 21, 2012
Showing with 21 additions and 2 deletions.
  1. +6 −0 lib/celluloid.rb
  2. +15 −2 lib/celluloid/stack_dumper.rb
View
@@ -38,6 +38,12 @@ def cores
alias_method :cpus, :cores
alias_method :ncpus, :cores
+ # Perform a stack dump of all actors to the given output object
+ def stack_dump(output = STDERR)
+ Celluloid::StackDumper.dump(output)
+ end
+ alias_method :dump, :stack_dump
+
# Define an exception handler for actor crashes
def exception_handler(&block)
Logger.exception_handler(&block)
@@ -15,18 +15,31 @@ def self.dump(output = STDERR)
actors.each do |_, actor|
output << "Celluloid::Actor 0x#{actor.subject.object_id.to_s(16)}: #{actor.subject.class}"
output << " [#{actor.name}]" if actor.name
+ output << "\n"
+
+ tasks = actor.tasks
+ if tasks.empty?
+ output << "State: Idle (waiting for messages)\n"
+ else
+ output << "State: Running (executing tasks)\n"
+ output << "Tasks:\n"
+
+ tasks.each_with_index do |task, i|
+ output << " #{i+1}) #{task.class}: #{task.status}\n"
+ end
+ end
display_backtrace actor.thread, output
end
threads.each do |thread|
- output << "Thread 0x#{object_id.to_s(16)}:"
+ output << "Thread 0x#{object_id.to_s(16)}:\n"
display_backtrace thread, output
end
end
def self.display_backtrace(thread, output)
- output << "\n\t" << thread.backtrace.join("\n\t") << "\n\n"
+ output << "\t" << thread.backtrace.join("\n\t") << "\n\n"
end
end
end

0 comments on commit 5fc84e0

Please sign in to comment.