Skip to content

novaphy.PerformanceMonitor

Thread-local profiling utility. Wrap a step in with monitor.scoped(): ... to capture aggregate per-phase timings and (optionally) emit a Chrome / Perfetto trace. Outside the with block every C++ phase scope is a zero-cost no-op, so solver public APIs stay free of profiling parameters.

This mirrors Newton's EventTracer / event_scope pattern.

Attributes

Attribute Description
enabled Master toggle for capture.
trace_enabled Enable per-frame trace recording for write_trace_json.

Methods

Method Description
scoped() Context manager. Capture the wrapped block.
phase_stats() Aggregate stats list (PerformancePhaseStat).
last_frame_metrics() Per-frame metric list (PerformanceMetric).
write_trace_json(path) Write a Chrome / Perfetto trace JSON.

Example

import novaphy

monitor = novaphy.PerformanceMonitor()
monitor.enabled = True
monitor.trace_enabled = True

for _ in range(120):
    with monitor.scoped():
        solver.step(state, state, control, contacts, dt)

for stat in monitor.phase_stats():
    print(stat.name, stat.avg_ms)

monitor.write_trace_json("trace.json")

See Also