Class: Sys::ProcTable::Smaps
- Inherits:
-
Object
- Object
- Sys::ProcTable::Smaps
- Defined in:
- lib/linux/sys/proctable/smaps.rb
Overview
Smaps represents a process’ memory size for all mapped files
A single mapped file memory entry looks like this:
00400000-004d4000 r-xp 00000000 fd:00 785 /bin/bash
Size: 848 kB
Rss: 572 kB
Pss: 572 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 572 kB
Private_Dirty: 0 kB
Referenced: 572 kB
Anonymous: 0 kB
AnonHugePages: 0 kB
Swap: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Have a look at ‘man 5 proc` on a linux distribution, to get some more information about the lines and fields in `/proc//smaps`.
Example:
smaps = Smaps.new(123, IO.read("/proc/1234/smaps")
# result
#<Sys::ProcTable::Smaps:0x007f8ac5930768
@pid=123,
@pss=107000,
@rss=368000,
@uss=96000,
@swap=192000,
@vss=136752000
>
smaps.pss # => 109568
smaps.rss # => 376832
smaps.uss # => 98304
smaps.swap # => 196608
smaps.vss # => 140034048
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Process ID for this smaps.
-
#pss ⇒ Object
(also: #proportional_set_size)
readonly
Proportional set size.
-
#rss ⇒ Object
(also: #resident_set_size)
readonly
Resident set size.
-
#swap ⇒ Object
readonly
Swap.
-
#uss ⇒ Object
(also: #unique_set_size)
readonly
Unique set size.
-
#vss ⇒ Object
(also: #virtual_set_size)
readonly
Virtual set size.
Instance Method Summary collapse
-
#initialize(pid, smaps_contents) ⇒ Smaps
constructor
Create a new smaps object.
Constructor Details
#initialize(pid, smaps_contents) ⇒ Smaps
Create a new smaps object
This expects a process id and a string containing the contents of /proc/PID/smaps - see ‘man 5 proc` for a reference.
The smaps contents are parsed and memory sizes are calculated in bytes.
100 101 102 103 104 105 106 107 108 |
# File 'lib/linux/sys/proctable/smaps.rb', line 100 def initialize(pid, smaps_contents) @pid = pid @pss = 0 @rss = 0 @uss = 0 @swap = 0 @vss = 0 smaps_contents.each_line { |line| parse_smaps_line(line) } end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Process ID for this smaps
50 51 52 |
# File 'lib/linux/sys/proctable/smaps.rb', line 50 def pid @pid end |
#pss ⇒ Object (readonly) Also known as: proportional_set_size
Proportional set size
PSS is the size of private pages added to each shared mapping’s size divided by the number of processes that share it. It is meant to provide a better representation of the amount of memory actually used by a process.
If a process has 4k of private pages, 4k of shared pages shared with one other process, and 3k of pages shared with two other processes, the PSS is:
4k + (4k / 2) + (3k / 3) = 7k
65 66 67 |
# File 'lib/linux/sys/proctable/smaps.rb', line 65 def pss @pss end |
#rss ⇒ Object (readonly) Also known as: resident_set_size
Resident set size
RSS is the total size of all pages, shared or not, mapped to a process.
71 72 73 |
# File 'lib/linux/sys/proctable/smaps.rb', line 71 def rss @rss end |
#swap ⇒ Object (readonly)
Swap
Swap is the total size of all swapped pages mapped to a process.
83 84 85 |
# File 'lib/linux/sys/proctable/smaps.rb', line 83 def swap @swap end |
#uss ⇒ Object (readonly) Also known as: unique_set_size
Unique set size
USS is the total size of all private pages mapped to a process.
77 78 79 |
# File 'lib/linux/sys/proctable/smaps.rb', line 77 def uss @uss end |
#vss ⇒ Object (readonly) Also known as: virtual_set_size
Virtual set size
VSS is the total accessible address space in a process. Since files are lazily loaded, this value represents the total size of all mapped files if they were all loaded.
90 91 92 |
# File 'lib/linux/sys/proctable/smaps.rb', line 90 def vss @vss end |