ProfilerBackend
Implement this protocol when registering a custom collector through
register_backend. Select built-in collectors with profile(backend=...).
Define the minimal pluggable measurement lifecycle.
| Attributes |
name : str | Backend Built-in backend identifier or registered custom collector name.
capabilities : BackendCapabilities Measurements supported by this collector. |
See Also
Example
Use the built-in Trace collector as a concrete protocol implementation. Reject all filenames here to demonstrate the lifecycle without capturing source or depending on measured timings.
>>> from linescope.backends import ProfilerBackend
>>> from linescope.backends.trace import TraceBackend
>>> backend: ProfilerBackend = TraceBackend(
... accepts=lambda filename: False, on_source=lambda filename: None
... )
>>> backend.start()
>>> try:
... total = sum(range(10))
... finally:
... backend.stop()
>>> snapshot = backend.result()
>>> (str(backend.name), backend.capabilities.hit_counts, snapshot.lines)
('trace', True, [])
Methods
start |
Begin collecting measurements. |
stop |
Stop collecting and release instrumentation. |
result |
Return a detached measurement snapshot. |
Begin collecting measurements.
Install only the instrumentation needed by this collector.
Stop collecting and release instrumentation.
Restore hooks owned by this collector, including after workload failures.
Return a detached measurement snapshot.
Return normalized raw measurements for source attribution by the session.