PSUtilProfiler#
- class caput.util.profiler.PSUtilProfiler(use_profiler: bool = True, label: str = '', logger: logging.Logger | None = None, comm: mpi4py.MPI.Comm | None = None, path: os.PathLike | None = None)[source]#
Bases:
psutil.ProcessA context manager that profiles using psutil.
To access the profiling data the context manager object must be created and bound to a variable before the with statement.
Dumps results into csv file, one for each rank.
>>> p = PSUtilProfiler(label="task-label") >>> with p: ... print("do some task in here") do some task in here >>> print(p.usage) {...}
start and stop can be used to use the PSUtilProfiler outside of cotnext management.
>>> p = PSUtilProfiler(label="task-label") >>> p.start() >>> print("do some task in here") do some task in here >>> p.stop() >>> print(p.usage) {...}
- Parameters:
- use_profilerbool
Whether to run the profiler or not.
- label
str, optional Default description of what is being profiled.
- logger
logging.Logger|None, optional If no None, the values of the IO done counters will be logged at INFO level.
- comm
MPI.Comm|None, optional An optional MPI communicator. This is only used for labelling the output files.
- path
os.PathLike|None, optional The optional directory path under which to write the profile csvs. If not set use the current directory.
- property usage: dict[str, float][source]#
The memory and cpu usage within the block.
- Returns:
- usage
dict Usage dictionary with the following keys:
cpu_timesdictdict version of psutil.cpu_times. Process CPU times since start was called in seconds.
cpu_percentfloatProcess CPU utilization since start was called as a percentage. Can be >100 if multiple threads run on different cores. See PSUtil.cpu_count for available cores.
disk_iodictdict version of psutil.io_counters (on Linux) or psutil.disk_io_counters (on MacOS). Difference since start was called.
memorystrDifference of memory in use by this process since start was called. If negative, less memory is in use now.
used_memorystrCurrent used memory at the time of the task’s end.
available_memorystrCurrent memory available to the system at the time of the task’s end.
- usage