class Analyzer::Rss
Constants
- CONVERSION
- GB_TO_BYTE
- KB_TO_BYTE
- MB_TO_BYTE
Public Class Methods
new(pid = Process.pid)
click to toggle source
# File lib/analyzer/rss.rb, line 11 def initialize(pid = Process.pid) @pid = pid @status_file = "/proc/#{@pid}/status" @linux = File.exists?(@status_file) end
Public Instance Methods
bytes()
click to toggle source
# File lib/analyzer/rss.rb, line 17 def bytes @linux ? (linux_status_memory || ps_memory) : ps_memory end
inspect()
click to toggle source
# File lib/analyzer/rss.rb, line 21 def inspect "#<#{self.class}:0x%08x @bytes=#{bytes}>" % (object_id * 2) end
linux_status_memory()
click to toggle source
linux stores memory info in a file “/proc/#{@pid}/status” If it's available it uses less resources than shelling out to ps
# File lib/analyzer/rss.rb, line 27 def linux_status_memory line = File.new(@status_file).each_line.detect { |l| l.start_with?('VmRSS'.freeze) } if line line = line.split(nil) if line.length == 3 CONVERSION[line[1].downcase!] * line[2].to_i end end rescue Errno::EACCES, Errno::ENOENT 0 end
ps_memory()
click to toggle source
Pull memory from `ps` command, takes more resources and can freeze in low memory situations
# File lib/analyzer/rss.rb, line 41 def ps_memory KB_TO_BYTE * BigDecimal.new(`ps -o rss= -p #{@pid}`) end