Process::MetricsSourceProcessMetricsMemory

class Memory

Represents memory usage for a process, sizes are in bytes.

Nested

Definitions

def to_json(*arguments)

Convert the object to a JSON string.

Implementation

def to_json(*arguments)
	as_json.to_json(*arguments)
end

def total_size

The total size of the process in memory.

Implementation

def total_size
	self.resident_size + self.swap_size
end

def self.total_size

Total system/host memory in bytes. Delegates to Host::Memory.capture.

Signature

returns Integer | Nil

Implementation

def self.total_size
	Host::Memory.capture&.total_size
end

def private_size

The private set size, the size of completely private (unshared) data. This is the sum of Private_Clean and Private_Dirty pages.

Signature

returns Integer

Total private memory in bytes.

Implementation

def private_size
	self.private_clean_size + self.private_dirty_size
end

alias unique_size private_size

The private set size is also known as the unique set size.

def shared_size

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.

Signature

returns Integer

Total shared memory in bytes.

Implementation

def shared_size
	self.shared_clean_size + self.shared_dirty_size
end

def self.zero

Create a zero-initialized Memory instance.

Signature

returns Memory

A new Memory object with all fields set to zero.

Implementation

def self.zero
	self.new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
end

def self.supported?

Whether the memory usage can be captured on this system.

Implementation

def self.supported?
	false
end

def self.capture(pid, **options)

Capture memory usage for the given process IDs.

Implementation

def self.capture(pid, **options)
	return nil
end