Class: Memstat::Proc::Status

Inherits:
Base
  • Object
show all
Defined in:
lib/memstat/proc/status.rb

Constant Summary collapse

FIELDS =
%w[peak size lck pin hwm rss data stk exe lib pte swap]

Instance Attribute Summary

Attributes inherited from Base

#path, #pid

Instance Method Summary collapse

Methods inherited from Base

#pid?

Constructor Details

#initialize(options = {}) ⇒ Status

Returns a new instance of Status.



7
8
9
10
11
12
# File 'lib/memstat/proc/status.rb', line 7

def initialize(options = {})
  super
  @path ||= "/proc/#{@pid}/status"

  run
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/memstat/proc/status.rb', line 14

def run
  @lines = File.readlines(@path).map(&:strip)
  @hash = {}

  @lines.each do |line|
    match = line.match(/(\w+):(.+)/)
    key = match[1]
    value = match[2]

    @hash[key] = value

    if match = key.match(/Vm(\w+)/)
      field = match[1].downcase
      if respond_to? "#{field}="
        send("#{field}=", Integer(value.strip.split.first) * 1024)
      end
    end
  end
end