Profiler#

class lumopt2.utils.profiler.Profiler(enabled: bool = True)#

Aggregate wall-clock time per named category.

Categories are tracked hierarchically via a context-stack: nesting one measure() inside another produces a slash-joined full path such as "compute_gradient/dEps_phase/perturbation_loop". Each unique full path is its own bucket and gets its own count / total / min / max statistics.

The profiler is enabled by default and can be globally toggled with enable() / disable(). When disabled, measure() is a no-op with sub-microsecond overhead.

Parameters:
enabledbool, optional

If True (the default), measure() records timings. If False, measure() is a no-op and no statistics are accumulated.

Methods

Profiler.disable()

Disable timing measurements; subsequent measure calls are no-ops.

Profiler.enable()

Enable timing measurements.

Profiler.format_summary(*[, min_total_seconds])

Return a tree-formatted string summarizing recorded categories.

Profiler.get_stats()

Return a snapshot of the current statistics.

Profiler.log_summary([level, ...])

Log the formatted summary to a logger.

Profiler.measure(name)

Time the wrapped block and accumulate it under name.

Profiler.reset()

Clear all accumulated statistics and the active context stack.