nemo_gym.telemetry.memory
nemo_gym.telemetry.memory
Linux process-tree memory sampling for Gym-managed servers.
Module Contents
Classes
Functions
Data
API
Current host memory capacity and pressure.
Periodically report host memory and Gym-managed server process trees.
Record one host sample and one sample for every configured server.
Start background sampling after recording an initial sample.
Stop sampling and record final live host and process-tree values.
CPU time one process and the children it waited for have used since it started.
parent_pid is the parent pid the process reported when it was read. parent is that parent’s identity, or
None when the parent is not a known process of the tree.
One process tree’s current memory.
One configured Gym server and the root process Gym spawned for it.
The children of every thread of pid that can be read; a process that has gone has none.
Return a snapshot of a Linux process tree, including its root, each process before its children.
Whether /proc/<pid>/stat fields describe a process that has exited and has no thread still running.
A child being reaped shows X once its parent’s children times already include it, so it is not counted as
well. A zombie main thread whose other threads still run is a running process.
One process’s identity, CPU times and parent pid from one /proc/<pid>/stat read.
None if it cannot be read or has exited. The times include cutime/cstime: the kernel adds a child’s own
and children times to its parent’s when the parent waits for it, so a child that starts and exits between two
samples is still counted.
Return (rss, pss) bytes for one process, or None after an exit race.
The fields of /proc/<pid>/stat after the command name; raises FileNotFoundError once the pid is gone.
The CPU time a tree used since previous, and the baseline for the next sample.
A baseline never goes down, so time moved onto a parent before the parent’s own times show it (the parent was read just before it waited) is held back until they do, and the total never goes down either.
A parent that could not be read in this walk but still runs keeps its baseline, so a child naming it is linked to it: a running process’s reported parent pid always names its live parent. A process missing from this walk that still runs is linked to the parent it reports now, such as a child subreaper that adopted it, or to none when it was reparented outside the tree.
Measure current host memory using psutil’s cross-platform accounting.
CPU time used so far by a root process and each of its live descendants (Linux procfs).
Measure current RSS and PSS for a root process and its descendants.
CPU time the tree used between two samples: each live process’s increase, all of it for a new process.
The parent pid the process key names reports now, or None if it cannot be read or its pid was reused.
previous without the processes that have exited, each one’s counted time moved onto an ancestor’s baseline.
A process can drop out of one walk (an unreadable children file, a race with a fork); keeping its baseline
means it is not counted again from zero when it reappears. Only a process that has exited is forgotten.
When a parent waits for an exited child, the kernel adds the child’s whole total to the parent’s children times.
The part already counted is added to the baseline of the child’s nearest ancestor that has not exited (its parent,
or further up when the parent exited in the same interval after waiting for it), so it is not counted twice. An
ancestor that never received it (one that ignores SIGCHLD, or a child orphaned and reaped outside the tree)
then counts less than the tree used. A process whose ancestors all left the tree is not moved.
Whether the process key names is confirmed gone: its pid is free, belongs to a later process, or is dead.
An entry that cannot be read for another reason (permissions, I/O) is not proof of an exit, so it counts as running.
Return whether this host exposes Linux procfs memory accounting.
Record the host’s logical and physical CPU counts and the CPUs this process may run on.
Record current host memory and its sampled peak through Lens.
Add a server process tree’s CPU time since the previous sample to gym.server.cpu.time_total.
Record current and sampled-peak process-tree memory through Lens.