Skip to main content

Python class

CPUMetricsCollector

CPUMetricsCollector​

class max.diagnostics.cpu.CPUMetricsCollector(pids)

source

Bases: object

Collects aggregate CPU time across a set of PIDs.

Use as a context manager around the workload, then call get_stats() to obtain the CPUMetrics summary.

collector = CPUMetricsCollector(pids)
with collector:
    run_workload()
metrics = collector.get_stats()

Parameters:

pids (list[int]) – The PIDs of the processes to collect CPU times from.

get_stats()​

get_stats()

source

Computes and returns CPU metrics aggregated across the tracked PIDs.

Returns:

The aggregated user and system CPU times along with their utilization percentages over the elapsed wall-clock interval.

Raises:

RuntimeError – If the context manager was not used, or if elapsed time is non-positive.

Return type:

CPUMetrics