Parent

Class/Module Index [+]

Quicksearch

Celluloid::StackDump

Attributes

actors[RW]
threads[RW]

Public Class Methods

new() click to toggle source
# File lib/celluloid/stack_dump.rb, line 18
def initialize
  @actors  = []
  @threads = []

  snapshot
end

Public Instance Methods

display_backtrace(backtrace, output) click to toggle source
# File lib/celluloid/stack_dump.rb, line 89
def display_backtrace(backtrace, output)
  if backtrace
    output << "\t" << backtrace.join("\n\t") << "\n\n"
  else
    output << "EMPTY BACKTRACE\n\n"
  end
end
dump(output = STDERR) click to toggle source
# File lib/celluloid/stack_dump.rb, line 57
def dump(output = STDERR)
  @actors.each do |actor|
    string = ""
    string << "Celluloid::Actor 0x#{actor.subject_id.to_s(16)}: #{actor.subject_class}"
    string << " [#{actor.name}]" if actor.name
    string << "\n"

    if actor.status == :idle
      string << "State: Idle (waiting for messages)\n"
      display_backtrace actor.backtrace, string
    else
      string << "State: Running (executing tasks)\n"
      display_backtrace actor.backtrace, string
      string << "Tasks:\n"

      actor.tasks.each_with_index do |task, i|
        string << "  #{i+1}) #{task.task_class}: #{task.status}\n"
        display_backtrace task.backtrace, string
      end
    end

    output.print string
  end

  @threads.each do |thread|
    string = ""
    string << "Thread 0x#{thread.thread_id.to_s(16)}:\n"
    display_backtrace thread.backtrace, string
    output.print string
  end
end
snapshot() click to toggle source
# File lib/celluloid/stack_dump.rb, line 25
def snapshot
  Thread.list.each do |thread|
    if thread.celluloid?
      next unless thread.role == :actor
      @actors << snapshot_actor(thread.actor) if thread.actor
    else
      @threads << snapshot_thread(thread)
    end
  end
end
snapshot_actor(actor) click to toggle source
# File lib/celluloid/stack_dump.rb, line 36
def snapshot_actor(actor)
  state = ActorState.new
  state.subject_id = actor.subject.object_id
  state.subject_class = actor.subject.class

  tasks = actor.tasks
  if tasks.empty?
    state.status = :idle
  else
    state.status = :running
    state.tasks = tasks.collect { |t| TaskState.new(t.class, t.status, t.backtrace) }
  end

  state.backtrace = actor.thread.backtrace if actor.thread
  state
end
snapshot_thread(thread) click to toggle source
# File lib/celluloid/stack_dump.rb, line 53
def snapshot_thread(thread)
  ThreadState.new(thread.object_id, thread.backtrace)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.