Class: Process::Metrics::Memory
- Inherits:
-
Struct
- Object
- Struct
- Process::Metrics::Memory
- Defined in:
- lib/process/metrics/memory.rb
Overview
Represents memory usage for a process, sizes are in bytes.
Defined Under Namespace
Instance Attribute Summary collapse
-
#anonymous_size ⇒ Object
Returns the value of attribute anonymous_size.
-
#major_faults ⇒ Object
Returns the value of attribute major_faults.
-
#map_count ⇒ Object
Returns the value of attribute map_count.
-
#minor_faults ⇒ Object
Returns the value of attribute minor_faults.
-
#private_clean_size ⇒ Object
Returns the value of attribute private_clean_size.
-
#private_dirty_size ⇒ Object
Returns the value of attribute private_dirty_size.
-
#proportional_size ⇒ Object
Returns the value of attribute proportional_size.
-
#proportional_swap_size ⇒ Object
Returns the value of attribute proportional_swap_size.
-
#referenced_size ⇒ Object
Returns the value of attribute referenced_size.
-
#resident_size ⇒ Object
Returns the value of attribute resident_size.
-
#shared_clean_size ⇒ Object
Returns the value of attribute shared_clean_size.
-
#shared_dirty_size ⇒ Object
Returns the value of attribute shared_dirty_size.
-
#swap_size ⇒ Object
Returns the value of attribute swap_size.
Class Method Summary collapse
-
.capture ⇒ Object
Capture memory metrics for a process.
-
.supported? ⇒ Boolean
Whether memory capture is supported on this platform.
-
.total_size ⇒ Object
Total system/host memory in bytes.
-
.zero ⇒ Object
Create a zero-initialized Memory instance.
Instance Method Summary collapse
-
#private_size ⇒ Object
(also: #unique_size)
The private set size, the size of completely private (unshared) data.
-
#shared_size ⇒ Object
The total size of shared (potentially shared with other processes) memory.
-
#to_json(*arguments) ⇒ Object
Convert the object to a JSON string.
-
#total_size ⇒ Object
The total size of the process in memory.
Instance Attribute Details
#anonymous_size ⇒ Object
Returns the value of attribute anonymous_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def anonymous_size @anonymous_size end |
#major_faults ⇒ Object
Returns the value of attribute major_faults
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def major_faults @major_faults end |
#map_count ⇒ Object
Returns the value of attribute map_count
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def map_count @map_count end |
#minor_faults ⇒ Object
Returns the value of attribute minor_faults
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def minor_faults @minor_faults end |
#private_clean_size ⇒ Object
Returns the value of attribute private_clean_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def private_clean_size @private_clean_size end |
#private_dirty_size ⇒ Object
Returns the value of attribute private_dirty_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def private_dirty_size @private_dirty_size end |
#proportional_size ⇒ Object
Returns the value of attribute proportional_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def proportional_size @proportional_size end |
#proportional_swap_size ⇒ Object
Returns the value of attribute proportional_swap_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def proportional_swap_size @proportional_swap_size end |
#referenced_size ⇒ Object
Returns the value of attribute referenced_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def referenced_size @referenced_size end |
#resident_size ⇒ Object
Returns the value of attribute resident_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def resident_size @resident_size end |
#shared_clean_size ⇒ Object
Returns the value of attribute shared_clean_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def shared_clean_size @shared_clean_size end |
#shared_dirty_size ⇒ Object
Returns the value of attribute shared_dirty_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def shared_dirty_size @shared_dirty_size end |
#swap_size ⇒ Object
Returns the value of attribute swap_size
12 13 14 |
# File 'lib/process/metrics/memory.rb', line 12 def swap_size @swap_size end |
Class Method Details
.capture ⇒ Object
Capture memory metrics for a process.
68 69 70 |
# File 'lib/process/metrics/memory.rb', line 68 def self.capture(pid, **) return nil end |
.supported? ⇒ Boolean
Whether memory capture is supported on this platform.
63 64 65 |
# File 'lib/process/metrics/memory.rb', line 63 def self.supported? false end |
.total_size ⇒ Object
Total system/host memory in bytes. Delegates to Host::Memory.capture.
58 59 60 |
# File 'lib/process/metrics/memory.rb', line 58 def self.total_size Host::Memory.capture&.total_size end |
.zero ⇒ Object
Create a zero-initialized Memory instance.
52 53 54 |
# File 'lib/process/metrics/memory.rb', line 52 def self.zero self.new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) end |
Instance Method Details
#private_size ⇒ Object Also known as: unique_size
The private set size, the size of completely private (unshared) data. This is the sum of Private_Clean and Private_Dirty pages.
29 30 31 |
# File 'lib/process/metrics/memory.rb', line 29 def private_size self.private_clean_size + self.private_dirty_size end |
#shared_size ⇒ Object
The total size of shared (potentially shared with other processes) memory. This is the sum of Shared_Clean and Shared_Dirty pages.
When tracking Copy-on-Write (CoW) activity in forked processes:
-
Initially, most memory is shared between parent and child.
-
As the child writes to memory, CoW triggers and shared pages become private.
-
Tracking shared_size decrease vs unique_size increase can indicate CoW activity.
-
If shared_size decreases by X and unique_size increases by ~X, it’s likely CoW.
46 47 48 |
# File 'lib/process/metrics/memory.rb', line 46 def shared_size self.shared_clean_size + self.shared_dirty_size end |
#to_json(*arguments) ⇒ Object
Convert the object to a JSON string.
17 18 19 |
# File 'lib/process/metrics/memory.rb', line 17 def to_json(*arguments) as_json.to_json(*arguments) end |
#total_size ⇒ Object
The total size of the process in memory.
22 23 24 |
# File 'lib/process/metrics/memory.rb', line 22 def total_size self.resident_size + self.swap_size end |