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