Sha256: 9ff8d840342ec60ff7397fefb7080518c1eb6ffd64a555dcc007e580df4f93f1

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

module Celluloid
  module Internals
    class Stack

      attr_accessor :actors, :threads

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

      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

      def snapshot_actor(actor,backtrace=nil)
        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 backtrace and actor.thread
        state
      end

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

      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

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

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

    end
  end
end

require 'celluloid/internals/stack/states'
require 'celluloid/internals/stack/dump'
require 'celluloid/internals/stack/summary'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
celluloid-essentials-0.20.0.pre14 lib/celluloid/internals/stack.rb
celluloid-essentials-0.20.0.pre13 lib/celluloid/internals/stack.rb
celluloid-essentials-0.20.0.pre12 lib/celluloid/internals/stack.rb