class Test::Unit::Util::MemoryUsage

Attributes

physical[R]
virtual[R]

Public Class Methods

new() click to toggle source
# File test-unit-3.6.1/lib/test/unit/util/memory-usage.rb, line 7
def initialize
  @virtual = nil
  @physical = nil
  collect_data
end

Public Instance Methods

collected?() click to toggle source
# File test-unit-3.6.1/lib/test/unit/util/memory-usage.rb, line 13
def collected?
  return false if @virtual.nil?
  return false if @physical.nil?
  true
end

Private Instance Methods

collect_data() click to toggle source
# File test-unit-3.6.1/lib/test/unit/util/memory-usage.rb, line 20
def collect_data
  collect_data_proc
end
collect_data_proc() click to toggle source
# File test-unit-3.6.1/lib/test/unit/util/memory-usage.rb, line 24
def collect_data_proc
  status_file = "/proc/self/status"
  return false unless File.exist?(status_file)

  data = File.binread(status_file)
  data.each_line do |line|
    case line
    when /\AVm(Size|RSS):\s*(\d+)\s*kB/
      name = $1
      value = Integer($2, 10) * 1024
      case name
      when "Size"
        @virtual = value
      when "RSS"
        @physical = value
      end
    end
  end
  collected?
end