oasislmf.execution.resource_monitor

Resource monitor for pytools processes during model runs.

Uses psutil to poll all active pytools processes at a configurable interval, capturing CPU%, cumulative CPU time (user + system), RSS, USS (private memory), and PSS (proportional memory, Linux only). Writes raw data to CSV and optionally generates a markdown report with plots (requires matplotlib).

USS (Unique Set Size) is the primary memory metric — it represents memory private to each process and avoids the double-counting problem that RSS has with shared memory and memory-mapped files.

CPU time (user + system) from psutil.Process.cpu_times() gives the actual processor time consumed, equivalent to TIME+ in top.

Attributes

Classes

ResourceMonitor

Daemon-thread based resource monitor for pytools processes.

Module Contents

oasislmf.execution.resource_monitor.logger[source]
oasislmf.execution.resource_monitor.MONITORED_TOOLS[source]
oasislmf.execution.resource_monitor.CSV_HEADER = ['timestamp', 'tool', 'pid', 'cpu_pct', 'cpu_user_s', 'cpu_sys_s', 'rss_kb', 'uss_kb', 'pss_kb'][source]
oasislmf.execution.resource_monitor.TOOL_COLORS[source]
class oasislmf.execution.resource_monitor.ResourceMonitor(output_dir, poll_interval=1.0)[source]

Daemon-thread based resource monitor for pytools processes.

Args:

output_dir (str): Directory to write resource_monitor.csv into. poll_interval (float): Seconds between polls (default 1.0).

output_dir[source]
poll_interval[source]
start(bash_pid)[source]

Start the monitor in a daemon thread.

Args:

bash_pid (int): PID of the bash process running the kernel script.

stop()[source]

Signal the monitor to stop, wait for the thread, generate report.