TimingsCollector#

class ansys.cfx.mcp.common.timings.TimingsCollector#

Process-wide singleton. Thread-safe; no async required.

Overview#

record

Record timing information for an operation.

time

Context manager: with timings.time('tool', name): ....

snapshot

Return a JSON-friendly view, sorted by total_ms desc per scope.

summary

One row per scope with totals; cheap top-line metric.

uptime_s

Return process uptime in seconds.

reset

Reset collected timing information.

Import detail#

from ansys.cfx.mcp.common.timings import TimingsCollector

Method detail#

TimingsCollector.record(scope: str, key: str, elapsed_ms: float, *, errored: bool = False) None#

Record timing information for an operation.

Parameters:
scopestr

Scope supplied to the function.

keystr

Key used to look up or store the associated value.

elapsed_msfloat

Elapsed ms supplied to the function.

erroredbool

Whether to enable or apply errored.

Returns:
None

The function completes through its side effects.

TimingsCollector.time(scope: str, key: str) Iterator[None]#

Context manager: with timings.time('tool', name): ....

Parameters:
scopestr

Scope used to limit the field or API lookup.

keystr

Key supplied to the function.

Returns:
Iterator[None]

Result produced by the function.

TimingsCollector.snapshot() dict[str, list[dict[str, float | int | str]]]#

Return a JSON-friendly view, sorted by total_ms desc per scope.

This approach ensures the slow paths sit at the top.

Returns:
dict[str, list[dict[str, float | int | str]]]

Mapping containing the operation result.

TimingsCollector.summary() dict[str, dict[str, float | int]]#

One row per scope with totals; cheap top-line metric.

Returns:
dict[str, dict[str, float | int]]

Mapping containing the operation result.

TimingsCollector.uptime_s() float#

Return process uptime in seconds.

Returns:
float

Floating-point result produced by the operation.

TimingsCollector.reset() None#

Reset collected timing information.

Returns:
None

The function completes through its side effects.