Class: LinuxProcessMemory
- Inherits:
-
Object
- Object
- LinuxProcessMemory
- Defined in:
- lib/linux_process_memory.rb
Overview
This class will read the smap files for a process on a Linux system and report the memory usage for that process.
Constant Summary collapse
- VERSION =
File.read(File.("../VERSION", __dir__)).strip.freeze
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Class Method Summary collapse
-
.supported? ⇒ Boolean
Returns true if the current platform is Linux.
Instance Method Summary collapse
-
#initialize(pid = Process.pid) ⇒ LinuxProcessMemory
constructor
Create a memory snapshot for the specified process.
-
#pss(units = :bytes) ⇒ Numberic
(also: #proportional)
Returns the proportional set size for the process.
-
#referenced(units = :bytes) ⇒ Numberic
Returns the referenced memory size for the process (i.e. memory that is actively being used) that cannot be reclaimed.
-
#rss(units = :bytes) ⇒ Numberic
(also: #resident)
Returns the resident set size for the process.
-
#shared(units = :bytes) ⇒ Numberic
Returns the shared memory used by the process.
-
#swap(units = :bytes) ⇒ Numberic
Returns the swap used by the process.
-
#total(units = :bytes) ⇒ Numberic
Returns the total memory usage for the process.
-
#uss(units = :bytes) ⇒ Numberic
(also: #unique)
Returns the uniq set size for the process.
Constructor Details
#initialize(pid = Process.pid) ⇒ LinuxProcessMemory
Create a memory snapshot for the specified process.
39 40 41 42 |
# File 'lib/linux_process_memory.rb', line 39 def initialize(pid = Process.pid) @pid = pid @stats = (self.class.supported? ? read_smaps : Hash.new(-1)) end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
25 26 27 |
# File 'lib/linux_process_memory.rb', line 25 def pid @pid end |
Class Method Details
.supported? ⇒ Boolean
Returns true if the current platform is Linux.
31 32 33 |
# File 'lib/linux_process_memory.rb', line 31 def supported? RUBY_PLATFORM.match?(LINUX_MATCHER) end |
Instance Method Details
#pss(units = :bytes) ⇒ Numberic Also known as: proportional
Returns the proportional set size for the process.
72 73 74 |
# File 'lib/linux_process_memory.rb', line 72 def pss(units = :bytes) convert_units(@stats[:Pss], units) end |
#referenced(units = :bytes) ⇒ Numberic
Returns the referenced memory size for the process (i.e. memory that is actively being used) that cannot be reclaimed.
117 118 119 |
# File 'lib/linux_process_memory.rb', line 117 def referenced(units = :bytes) convert_units(@stats[:Referenced], units) end |
#rss(units = :bytes) ⇒ Numberic Also known as: resident
Returns the resident set size for the process.
60 61 62 |
# File 'lib/linux_process_memory.rb', line 60 def rss(units = :bytes) convert_units(@stats[:Rss], units) end |
#shared(units = :bytes) ⇒ Numberic
Returns the shared memory used by the process.
106 107 108 |
# File 'lib/linux_process_memory.rb', line 106 def shared(units = :bytes) convert_units(@stats[:Shared_Clean] + @stats[:Shared_Dirty], units) end |
#swap(units = :bytes) ⇒ Numberic
Returns the swap used by the process.
96 97 98 |
# File 'lib/linux_process_memory.rb', line 96 def swap(units = :bytes) convert_units(@stats[:Swap], units) end |
#total(units = :bytes) ⇒ Numberic
Returns the total memory usage for the process.
50 51 52 |
# File 'lib/linux_process_memory.rb', line 50 def total(units = :bytes) convert_units(@stats[:Rss] + @stats[:Swap], units) end |
#uss(units = :bytes) ⇒ Numberic Also known as: unique
Returns the uniq set size for the process.
84 85 86 |
# File 'lib/linux_process_memory.rb', line 84 def uss(units = :bytes) convert_units(@stats[:Private_Clean] + @stats[:Private_Dirty], units) end |