Class: GitLab::Monitor::MemStats::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_monitor/memstats/mapping.rb

Overview

Parses one entry in /proc//smaps. For example:

00400000-00401000 r-xp 00000000 08:01 541055 /opt/gitlab/embedded/bin/ruby Size: 4 kB Rss: 4 kB Pss: 0 kB Shared_Clean: 4 kB Shared_Dirty: 0 kB Private_Clean: 0 kB Private_Dirty: 0 kB Referenced: 4 kB Anonymous: 0 kB AnonHugePages: 0 kB Shared_Hugetlb: 0 kB Private_Hugetlb: 0 kB Swap: 0 kB SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd ex mr mw me dw sd

Constant Summary collapse

FIELDS =
%w(size rss shared_clean shared_dirty private_clean private_dirty swap pss).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ Mapping

Returns a new instance of Mapping.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 48

def initialize(lines)
  FIELDS.each do |field|
    send("#{field}=", 0)
  end

  parse_first_line(lines.shift)

  lines.each do |l|
    parse_field_line(l)
  end
end

Instance Attribute Details

#address_endObject (readonly)

Returns the value of attribute address_end.



31
32
33
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 31

def address_end
  @address_end
end

#address_startObject (readonly)

Returns the value of attribute address_start.



30
31
32
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 30

def address_start
  @address_start
end

#device_majorObject (readonly)

Returns the value of attribute device_major.



34
35
36
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 34

def device_major
  @device_major
end

#device_minorObject (readonly)

Returns the value of attribute device_minor.



35
36
37
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 35

def device_minor
  @device_minor
end

#inodeObject (readonly)

Returns the value of attribute inode.



36
37
38
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 36

def inode
  @inode
end

#offsetObject (readonly)

Returns the value of attribute offset.



33
34
35
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 33

def offset
  @offset
end

#permsObject (readonly)

Returns the value of attribute perms.



32
33
34
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 32

def perms
  @perms
end

#private_cleanObject

Returns the value of attribute private_clean.



44
45
46
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 44

def private_clean
  @private_clean
end

#private_dirtyObject

Returns the value of attribute private_dirty.



43
44
45
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 43

def private_dirty
  @private_dirty
end

#pssObject

Returns the value of attribute pss.



46
47
48
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 46

def pss
  @pss
end

#regionObject (readonly)

Returns the value of attribute region.



37
38
39
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 37

def region
  @region
end

#rssObject

Returns the value of attribute rss.



40
41
42
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 40

def rss
  @rss
end

#shared_cleanObject

Returns the value of attribute shared_clean.



41
42
43
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 41

def shared_clean
  @shared_clean
end

#shared_dirtyObject

Returns the value of attribute shared_dirty.



42
43
44
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 42

def shared_dirty
  @shared_dirty
end

#sizeObject

Returns the value of attribute size.



39
40
41
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 39

def size
  @size
end

#swapObject

Returns the value of attribute swap.



45
46
47
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 45

def swap
  @swap
end

Instance Method Details

#parse_field_line(line) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 72

def parse_field_line(line)
  line.strip!

  parts = line.split

  return unless parts

  parts[0].downcase!
  parts[0].sub!(":", "")
  field = parts[0]

  return unless respond_to? "#{field}="

  value = Float(parts[1]).to_i
  send("#{field}=", value)
end

#parse_first_line(line) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gitlab_monitor/memstats/mapping.rb', line 60

def parse_first_line(line)
  line.strip!

  parts = line.split
  @address_start, @address_end = parts[0].split("-")
  @perms = parts[1]
  @offset = parts[2]
  @device_major, @device_minor = parts[3].split(":")
  @inode = parts[4]
  @region = parts[5] || "anonymous"
end