2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-22 15:47:25 -04:00
|
|
|
class MemInfo
|
2013-03-23 11:57:47 -04:00
|
|
|
# Total memory in kb. On Mac OS uses "sysctl", elsewhere expects the system has /proc/meminfo.
|
2013-03-22 15:47:25 -04:00
|
|
|
# Returns nil if it cannot be determined.
|
|
|
|
def mem_total
|
2013-03-23 11:57:47 -04:00
|
|
|
@mem_total ||=
|
|
|
|
begin
|
|
|
|
system = `uname`.strip
|
|
|
|
if system == "Darwin"
|
|
|
|
s = `sysctl -n hw.memsize`.strip
|
2013-11-13 11:30:48 -05:00
|
|
|
s.to_i / 1.kilobyte
|
2013-03-23 11:57:47 -04:00
|
|
|
else
|
|
|
|
s = `grep MemTotal /proc/meminfo`
|
|
|
|
/(\d+)/.match(s)[0].try(:to_i)
|
|
|
|
end
|
|
|
|
rescue StandardError
|
2013-03-22 15:47:25 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2024-03-13 22:55:01 -04:00
|
|
|
|
|
|
|
def unknown?
|
|
|
|
mem_total.nil?
|
|
|
|
end
|
2013-03-23 11:57:47 -04:00
|
|
|
end
|