Class: Celluloid::StackDump

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/stack_dump.rb

Defined Under Namespace

Modules: DisplayBacktrace Classes: ActorState, CellState, TaskState, ThreadState

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(internal_pool) ⇒ StackDump

Returns a new instance of StackDump.


72
73
74
75
76
77
78
79
# File 'lib/celluloid/stack_dump.rb', line 72

def initialize(internal_pool)
  @internal_pool = internal_pool

  @actors  = []
  @threads = []

  snapshot
end

Instance Attribute Details

#actorsObject

Returns the value of attribute actors


70
71
72
# File 'lib/celluloid/stack_dump.rb', line 70

def actors
  @actors
end

#threadsObject

Returns the value of attribute threads


70
71
72
# File 'lib/celluloid/stack_dump.rb', line 70

def threads
  @threads
end

Instance Method Details


123
124
125
126
127
128
129
130
131
# File 'lib/celluloid/stack_dump.rb', line 123

def print(output = STDERR)
  @actors.each do |actor|
    output.print actor.dump
  end

  @threads.each do |thread|
    output.print thread.dump
  end
end

#snapshotObject


81
82
83
84
85
86
87
88
89
# File 'lib/celluloid/stack_dump.rb', line 81

def snapshot
  @internal_pool.each do |thread|
    if thread.role == :actor
      @actors << snapshot_actor(thread.actor) if thread.actor
    else
      @threads << snapshot_thread(thread)
    end
  end
end

#snapshot_actor(actor) ⇒ Object


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/celluloid/stack_dump.rb', line 91

def snapshot_actor(actor)
  state = ActorState.new
  state.id = actor.object_id

  # TODO: delegate to the behavior
  if actor.behavior.is_a?(Cell)
    state.cell = snapshot_cell(actor.behavior)
  end

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

  state.backtrace = actor.thread.backtrace if actor.thread
  state
end

#snapshot_cell(behavior) ⇒ Object


112
113
114
115
116
117
# File 'lib/celluloid/stack_dump.rb', line 112

def snapshot_cell(behavior)
  state = CellState.new
  state.subject_id = behavior.subject.object_id
  state.subject_class = behavior.subject.class
  state
end

#snapshot_thread(thread) ⇒ Object


119
120
121
# File 'lib/celluloid/stack_dump.rb', line 119

def snapshot_thread(thread)
  ThreadState.new(thread.object_id, thread.backtrace, thread.role)
end