nemo_gym.telemetry.memory

View as Markdown

Linux process-tree memory sampling for Gym-managed servers.

Module Contents

Classes

NameDescription
HostMemoryCurrent host memory capacity and pressure.
MemoryProfilerPeriodically report host memory and Gym-managed server process trees.
ProcessTreeMemoryOne process tree’s current memory.
ServerMemoryTargetOne configured Gym server and the root process Gym spawned for it.

Functions

NameDescription
_descendant_pidsReturn a snapshot of a Linux process tree, including its root.
_get_instruments-
_read_process_memoryReturn (rss, pss) bytes for one process, or None after an exit race.
collect_host_memoryMeasure current host memory using psutil’s cross-platform accounting.
collect_process_tree_memoryMeasure current RSS and PSS for a root process and its descendants.
process_tree_memory_supportedReturn whether this host exposes Linux procfs memory accounting.
record_host_memoryRecord current host memory and its sampled peak through Lens.
record_server_memoryRecord current and sampled-peak process-tree memory through Lens.

Data

_INSTRUMENTS

logger

API

class nemo_gym.telemetry.memory.HostMemory(
used_bytes: int,
available_bytes: int,
total_bytes: int
)
Dataclass

Current host memory capacity and pressure.

available_bytes
int
total_bytes
int
used_bytes
int
class nemo_gym.telemetry.memory.MemoryProfiler(
interval_seconds: float,
collector: collections.abc.Callable[[int], nemo_gym.telemetry.memory.ProcessTreeMemory] = collect_process_tree_memory,
host_collector: collections.abc.Callable[[], nemo_gym.telemetry.memory.HostMemory] = collect_host_memory
)

Periodically report host memory and Gym-managed server process trees.

_host_peaks
dict[str, int] = {}
_peaks
dict[tuple[str, str], int] = {}
_stop
= threading.Event()
_thread
Thread | None = None
nemo_gym.telemetry.memory.MemoryProfiler._run() -> None
nemo_gym.telemetry.memory.MemoryProfiler.sample_once() -> None

Record one host sample and one sample for every configured server.

nemo_gym.telemetry.memory.MemoryProfiler.start() -> None

Start background sampling after recording an initial sample.

nemo_gym.telemetry.memory.MemoryProfiler.stop() -> None

Stop sampling and record final live host and process-tree values.

class nemo_gym.telemetry.memory.ProcessTreeMemory(
rss_bytes: int,
pss_bytes: int | None,
process_count: int
)
Dataclass

One process tree’s current memory.

process_count
int
pss_bytes
int | None
rss_bytes
int
class nemo_gym.telemetry.memory.ServerMemoryTarget(
name: str,
server_type: str,
pid: int
)
Dataclass

One configured Gym server and the root process Gym spawned for it.

name
str
pid
int
server_type
str
nemo_gym.telemetry.memory._descendant_pids(
root_pid: int
) -> set[int]

Return a snapshot of a Linux process tree, including its root.

nemo_gym.telemetry.memory._get_instruments(
meter
) -> dict
nemo_gym.telemetry.memory._read_process_memory(
pid: int
) -> tuple[int, int | None] | None

Return (rss, pss) bytes for one process, or None after an exit race.

nemo_gym.telemetry.memory.collect_host_memory() -> nemo_gym.telemetry.memory.HostMemory

Measure current host memory using psutil’s cross-platform accounting.

nemo_gym.telemetry.memory.collect_process_tree_memory(
root_pid: int

Measure current RSS and PSS for a root process and its descendants.

nemo_gym.telemetry.memory.process_tree_memory_supported() -> bool

Return whether this host exposes Linux procfs memory accounting.

nemo_gym.telemetry.memory.record_host_memory(
peaks: dict[str, int]
) -> None

Record current host memory and its sampled peak through Lens.

nemo_gym.telemetry.memory.record_server_memory(
peaks: dict[tuple[str, str], int]
) -> None

Record current and sampled-peak process-tree memory through Lens.

nemo_gym.telemetry.memory._INSTRUMENTS: WeakKeyDictionary = weakref.WeakKeyDictionary()
nemo_gym.telemetry.memory.logger = logging.getLogger(__name__)