Skip to content

ProfilerBackend


Implement this protocol when registering a custom collector through register_backend. Select built-in collectors with profile(backend=...).

class linescope.backends.base.ProfilerBackend(*args, **kwargs)[source]

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

BackendCapabilities

Describe measurements a collector can actually provide.

RawBackendResult

Return only collector measurements, independent of the report renderer.

register_backend

Register a collector factory without changing the rendering pipeline.


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.


method start()[source]

Begin collecting measurements.

Install only the instrumentation needed by this collector.



method stop()[source]

Stop collecting and release instrumentation.

Restore hooks owned by this collector, including after workload failures.



method result()[source]

Return a detached measurement snapshot.

Return normalized raw measurements for source attribution by the session.