Record op-level timing and memory traces from the C++ engine.
Drives the engine's profiling hook so that every dispatched op
becomes an OpEvent. Suitable for both interactive use
(with block) and programmatic control via explicit
start / stop. Recorded events can be exported as a
Chrome / Perfetto trace for visual inspection.
Parameters
with_memorybool= TrueTrue (default), also capture allocator stats via
MemoryStats.Notes
Total recorded time can be summarised per op as
via key_averages. Only one Profiler may be active
at a time; entering a nested instance overwrites the engine's
current profiler pointer until the outer context exits.
Examples
>>> import lucid
>>> with lucid.profiler.profile() as prof:
... y = lucid.randn(64, 64) @ lucid.randn(64, 64)
>>> top = prof.key_averages()[:5]Used by 1
Constructors
1Instance methods
7Clear all recorded events.
Return all recorded OpEvents.
Export events as a Chrome trace JSON file.
Open with chrome://tracing or https://ui.perfetto.dev.
key_averages()Return per-operation-name summaries sorted by total time.
memory_stats()Return memory stats if available.
Start recording operations.
Stop recording operations.