class Memstat::Proc::Smaps
Constants
- FIELDS
Attributes
items[RW]
lines[RW]
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
Memstat::Proc::Base::new
# File lib/memstat/proc/smaps.rb, line 8 def initialize(options = {}) super @path ||= "/proc/#{@pid}/smaps" FIELDS.each do |field| send("#{field}=", 0) end run end
Public Instance Methods
command()
click to toggle source
# File lib/memstat/proc/smaps.rb, line 57 def command return unless pid? commandline = File.read("/proc/#{@pid}/cmdline").split("\0") if commandline.first =~ /java$/ then loop { break if commandline.shift == "-jar" } return "[java] #{commandline.shift}" end return commandline.join(' ') end
number_with_delimiter(n)
click to toggle source
# File lib/memstat/proc/smaps.rb, line 67 def number_with_delimiter(n) n.to_s.gsub(/(\d)(?=\d{3}+$)/, '\\1,') end
print()
click to toggle source
# File lib/memstat/proc/smaps.rb, line 44 def print @print ||= begin lines = [] lines << "#{"Process:".ljust(20)} #{@pid || '[unspecified]'}" lines << "#{"Command Line:".ljust(20)} #{command || '[unspecified]'}" lines << "Memory Summary:" FIELDS.each do |field| lines << " #{field.ljust(20)} #{number_with_delimiter(send(field)/1024).rjust(12)} kB" end lines.join("\n") end end
run()
click to toggle source
# File lib/memstat/proc/smaps.rb, line 19 def run @lines = File.readlines(@path).map(&:strip) @items = [] item = nil @lines.each.with_index do |line, index| case line when /[0-9a-f]+:[0-9a-f]+\s+/ item = Item.new @items << item item.parse_first_line(line) when /\w+:\s+/ item.parse_field_line(line) else raise Error.new("invalid format at line #{index + 1}: #{line}") end end @items.each do |item| FIELDS.each do |field| send "#{field}=", (send(field) + item.send(field)) end end end