pyxfem.core.exec_tools module

Code profiling utilities.

This module provides a singleton-style wrapper around Python’s built-in cProfile and pstats modules to toggle and inspect profiling data across code sections. Created on Fri Dec 29 16:58:47 2023

@author: nchevaug

class pyxfem.core.exec_tools.Profile[source]

Bases: object

Static controller for runtime performance profiling.

Wraps a global cProfile.Profile instance, allowing selective activation, deactivation, and reporting of cumulative execution statistics.

doprofile

Global toggle flag. When set to False, all profiling calls are bypassed (default is True).

Type:

bool

pr

Underlying profiler instance.

Type:

cProfile.Profile

classmethod disable()[source]

Stop collecting profiling data if doprofile is enabled.

doprofile = True
classmethod enable()[source]

Start collecting profiling data if doprofile is enabled.

pr = <cProfile.Profile object>
classmethod print_stats(nlines=50)[source]

Print profiling statistics sorted by cumulative runtime.

Parameters:

nlines (int, optional) – Maximum number of top-ranked lines/functions to display (default is 50).