Sha256: d1a5132cd8992b2baa899a6f8e114590324b76de458d93907b4a1c79b367624d

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

module RorVsWild
  class Section
    attr_reader :started_at
    attr_accessor :kind, :file, :line, :calls, :command, :children_runtime, :total_runtime, :appendable_command

    def self.start(&block)
      section = Section.new
      block.call(section) if block_given?
      stack.push(section)
      section
    end

    def self.stop(&block)
      section = stack.pop
      block.call(section) if block_given?
      section.total_runtime = (Time.now.utc - section.started_at) * 1000
      current.children_runtime += section.total_runtime if current
      RorVsWild.agent.add_section(section)
    end

    def self.stack
      RorVsWild.agent.data[:section_stack] ||= []
    end

    def self.current
      stack.last
    end

    def initialize
      @calls = 1
      @total_runtime = 0
      @children_runtime = 0
      @started_at = Time.now.utc
      location = RorVsWild.agent.find_most_relevant_location(caller_locations)
      @file = RorVsWild.agent.relative_path(location.path)
      @line = location.lineno
      @appendable_command = false
    end

    def sibling?(section)
      kind == section.kind && line == section.line && file == section.file
    end

    MAX_COMMAND_HISTORY = 5

    def merge(section)
      self.calls += section.calls
      self.total_runtime += section.total_runtime
      self.children_runtime += section.children_runtime
      if section
        self.command << "\n".freeze + section.command if appendable_command
      else
        self.command = section.command
      end
      self.appendable_command = appendable_command && section.appendable_command
    end

    def self_runtime
      total_runtime - children_runtime
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rorvswild-1.1.1 lib/rorvswild/section.rb
rorvswild-1.1.0 lib/rorvswild/section.rb
rorvswild-1.0.1 lib/rorvswild/section.rb
rorvswild-1.0.0 lib/rorvswild/section.rb
rorvswild-1.0.0.pre.alpha8 lib/rorvswild/section.rb
rorvswild-1.0.0.pre.alpha7 lib/rorvswild/section.rb
rorvswild-1.0.0.pre.alpha6 lib/rorvswild/section.rb
rorvswild-1.0.0.pre.alpha5 lib/rorvswild/section.rb
rorvswild-1.0.0.pre.alpha4 lib/rorvswild/section.rb