pcdsutils.profile.profiler_context

pcdsutils.profile.profiler_context(module_names: Iterable[str], filename: str | None = None, use_global_profiler: bool = False, output_now: bool = True, min_threshold: float = 0) Iterator[LineProfiler][source]

Context manager for profiling a fixed span of an application.

Parameters:
module_namesiterable of str

The modules whose functions we’d like to include in the profile. If using the global profiler, these will persist between calls, only accumulating new modules and never clearing old ones.

filenamestr, optional

If provided, the results will be saved to this filename. If omitted, we’ll print the results to stdout.

use_global_profilerbool, optional

If False, the default, this will create a new profiler instance for this context manager block. If True, this will use the global profiler. Using the global profiler is appropriate if you want to accumulate statistics across multiple context manager blocks, or the same block multiple times.

output_nowbool, optional

If True, the default, we’ll print to screen or write to file the results upon exiting this block. If False, we will not. This is appropriate to change to False if you’d like to accumulate statistics across multiple context manager blocks, or perhaps the same context manager block multiple times.

min_thresholdfloat, optional

If provided, we will omit results from functions with total time less than this duration in seconds from the output.

Yields:
profilerLineProfiler

The profile instance that is active in this code block, in case you’d like to do something with it.