类 Test::Unit::Util::MemoryUsage

属性

physical[R]
virtual[R]

公共类方法

new() 点击切换源代码
# File test-unit-3.6.7/lib/test/unit/util/memory-usage.rb, line 7
def initialize
  @virtual = nil
  @physical = nil
  collect_data
end

公共实例方法

collected?() 点击切换源代码
# File test-unit-3.6.7/lib/test/unit/util/memory-usage.rb, line 13
def collected?
  return false if @virtual.nil?
  return false if @physical.nil?
  true
end

私有实例方法

collect_data() 点击切换源代码
# File test-unit-3.6.7/lib/test/unit/util/memory-usage.rb, line 20
def collect_data
  collect_data_proc
end
collect_data_proc() 点击切换源代码
# File test-unit-3.6.7/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