Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions check/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ def read_env_positive_int(key, default_value)
# Get the total size of the physical memory available on the host machine.
def total_physical_memory
platform = RbConfig::CONFIG["host_os"].downcase
if platform.include?("linux")
mem_info = `free -b | grep Mem`
mem_info.split[1].to_i
elsif platform.include?("darwin")
mem_info = `sysctl -n hw.memsize`
mem_info.to_i
elsif platform.include?("mingw") || platform.include?("mswin")
mem_info = `wmic ComputerSystem get TotalPhysicalMemory`
mem_info.split[1].to_i

case
when platform.include?("linux")
File.foreach("/proc/meminfo") do |line|
m = line.match(/\bMemTotal\b\D+(\d+)/)
return m[1].to_i * 1024 if m
end
when platform.include?("darwin")
return `sysctl -n hw.memsize`.to_i
when platform.include?("mingw") || platform.include?("mswin")
return `powershell -NoProfile -Command "(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory"`.to_i
end

nil
end

# The default prefix for the root temporary directory. See TempDir.root.
Expand Down Expand Up @@ -359,6 +363,9 @@ def total_memory
else
@@cached_total_memory = result
end
if result.nil? || result <= 0
warn("failed to determine total physical memory")
end
end
@@cached_total_memory
end
Expand Down
Loading