Profiler#

class caput.util.profiler.Profiler(profile: bool = True, profiler: str = 'cprofile', comm: mpi4py.MPI.Comm | None = None, path: os.PathLike | None = None)[source]#

A context manager to profile a block of code using various profilers.

Parameters:
profilebool, optional

Whether to run the profiler or not. Default is True.

profiler{“cprofile”, “pyinstrument”}, optional

Which profiler to run. Currently cProfile and pyinstrument are supported. Default is “cprofile”.

commMPI.Comm | None

An optional MPI communicator. This is only used for labelling the output files.

pathos.PathLike | None

The optional path under which to write the profiles. If not set, use the current directory.