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