Class: Celluloid::Internals::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/internals/stack.rb,
lib/celluloid/internals/stack/dump.rb,
lib/celluloid/internals/stack/states.rb,
lib/celluloid/internals/stack/summary.rb

Direct Known Subclasses

Dump, Summary

Defined Under Namespace

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(threads) ⇒ Stack

Returns a new instance of Stack.



6
7
8
9
10
# File 'lib/celluloid/internals/stack.rb', line 6

def initialize(threads)
  @group = threads
  @actors  = []
  @threads = []
end

Instance Attribute Details

#actorsObject

Returns the value of attribute actors.



4
5
6
# File 'lib/celluloid/internals/stack.rb', line 4

def actors
  @actors
end

#threadsObject

Returns the value of attribute threads.



4
5
6
# File 'lib/celluloid/internals/stack.rb', line 4

def threads
  @threads
end

Instance Method Details



57
58
59
60
61
62
63
64
65
# File 'lib/celluloid/internals/stack.rb', line 57

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

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

#snapshot(backtrace = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/celluloid/internals/stack.rb', line 12

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

#snapshot_actor(actor, backtrace = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/celluloid/internals/stack.rb', line 22

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

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

  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 backtrace && actor.thread
  state
end

#snapshot_cell(behavior) ⇒ Object



41
42
43
44
45
46
# File 'lib/celluloid/internals/stack.rb', line 41

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, backtrace = nil) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/celluloid/internals/stack.rb', line 48

def snapshot_thread(thread, backtrace=nil)
  backtrace = begin
                thread.backtrace
              rescue NoMethodError # for Rubinius < 2.5.2.c145
                []
              end if backtrace
  ThreadState.new(thread.object_id, backtrace, thread.role)
end