class WindowsSystemMemory

Memory probe for Windows

Public Class Methods

new() click to toggle source

rubocop:enable Style/ClassVars

# File lib/memory.rb, line 95
def initialize
  count = 0
  data_width = 0
  total_width = 0
  IO.popen('wmic MEMORYCHIP get Capacity,Speed,MemoryType,TotalWidth,DataWidth') do |io|
    while (line = io.gets)
      line = line.gsub(/\s+/m, ' ')
      values = line.split(' ')
      next if line.start_with?('Capacity') || values.empty?

      @size = values[0].to_i / 1_048_576
      data_width = values[1].to_i

      # noinspection RubyClassVariableUsageInspection
      @type = @@mem_type[values[2].to_i]
      @speed = values[3].to_i
      total_width = values[4].to_i
      count += 1
    end
  end

  @size = @size * count / 1024
  cmd = `systeminfo | find "Virtual Memory: Max Size:"`
  cmd = cmd.gsub(/\s+/m, ' ')
  @swap_size = cmd.split(' ')[4].to_i
  @is_ecc = data_width != total_width
end