File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed
Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -77,16 +77,20 @@ def read_env_positive_int(key, default_value)
7777# Get the total size of the physical memory available on the host machine.
7878def total_physical_memory
7979 platform = RbConfig::CONFIG[" host_os" ].downcase
80- if platform.include? (" linux" )
81- mem_info = ` free -b | grep Mem`
82- mem_info.split[1].to_i
83- elsif platform.include? (" darwin" )
84- mem_info = ` sysctl -n hw.memsize`
85- mem_info.to_i
86- elsif platform.include? (" mingw" ) || platform.include? (" mswin" )
87- mem_info = ` wmic ComputerSystem get TotalPhysicalMemory`
88- mem_info.split[1].to_i
80+
81+ case
82+ when platform.include? (" linux" )
83+ File.foreach(" /proc/meminfo" ) do | line|
84+ m = line.match(/\b MemTotal\b\D + (\d +)/)
85+ return m[1].to_i * 1024 if m
86+ end
87+ when platform.include? (" darwin" )
88+ return ` sysctl -n hw.memsize` .to_i
89+ when platform.include? (" mingw" ) || platform.include? (" mswin" )
90+ return ` powershell -NoProfile -Command " (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory" ` .to_i
8991 end
92+
93+ nil
9094end
9195
9296# The default prefix for the root temporary directory. See TempDir.root.
@@ -359,6 +363,9 @@ def total_memory
359363 else
360364 @@cached_total_memory = result
361365 end
366+ if result.nil? || result < = 0
367+ warn(" failed to determine total physical memory" )
368+ end
362369 end
363370 @@cached_total_memory
364371 end
You can’t perform that action at this time.
0 commit comments