Class: WindowsSystemMemory

Inherits:
SystemMemory show all
Defined in:
lib/memory.rb

Overview

Memory probe for Windows

Constant Summary collapse

@@mem_type =

rubocop:disable Style/ClassVars noinspection RubyClassVariableUsageInspection

['Unknown', 'Other', 'DRAM', 'Synchronous DRAM',
'Cache DRAM', 'EDO', 'EDRAM', 'VRAM', 'SRAM', 'RAM',
'ROM', 'Flash', 'EEPROM', 'FEPROM', 'EPROM', 'CDRAM',
'3DRAM', 'SDRAM', 'SGRAM', 'RDRAM', 'DDR', 'DDR2',
'DDR2 FB-DIMM', 'Undefined', 'DDR3', 'FBD2']

Constants inherited from SystemMemory

SystemMemory::UNLIMITED

Instance Attribute Summary

Attributes inherited from SystemMemory

#is_ecc, #size, #speed, #swap_size, #type

Instance Method Summary collapse

Methods inherited from SystemMemory

probe

Constructor Details

#initializeWindowsSystemMemory

rubocop:enable Style/ClassVars



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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