pydvl.utils.monitor
¶
This module implements a simple memory monitoring utility for the whole application.
With start_memory_monitoring() one can monitor global memory usage, including the memory of child processes. The monitoring runs in a separate thread and keeps track of the maximum* memory usage observed.
Monitoring stops automatically when the process exits or receives common termination signals (SIGINT, SIGTERM, SIGHUP). It can also be stopped manually by calling end_memory_monitoring().
When monitoring stops, the maximum memory usage is both logged and returned (in bytes).
Note
This is intended to report peak memory usage for the whole application, including child processes. It is not intended to be used for profiling memory usage of individual functions or modules. Given that there exist numerous profiling tools, it probably doesn't make sense to extend this module further.
end_memory_monitoring
¶
Ends the memory monitoring thread and logs the maximum memory usage.
PARAMETER | DESCRIPTION |
---|---|
log_level
|
The logging level to use.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
tuple[int, dict[int, int]]
|
A tuple with the maximum memory usage observed globally, and for each pid separately as a dict. The dict will be empty if monitoring is disabled. |
Source code in src/pydvl/utils/monitor.py
log_memory_usage_report
¶
Generates a nicely tabulated memory usage report and logs it.
PARAMETER | DESCRIPTION |
---|---|
peak_mem
|
The maximum memory usage observed during the monitoring period.
TYPE:
|
mem_usage
|
A dictionary mapping process IDs (pid) to memory usage in bytes. |
log_level
|
The log level used for logging the report.
DEFAULT:
|
Source code in src/pydvl/utils/monitor.py
memory_monitor_run
¶
Monitors the memory usage of the process and its children.
This function runs in a separate thread and updates the global variable
__max_memory_usage
with the maximum memory usage observed during the monitoring
period.
The monitoring stops when the __monitoring_enabled event is cleared, which can be achieved either by calling end_memory_monitoring(), or when the process is terminated or exits.
Source code in src/pydvl/utils/monitor.py
start_memory_monitoring
¶
start_memory_monitoring(auto_stop: bool = True)
Starts a memory monitoring thread.
The monitor runs in a separate thread and keeps track of maximum memory usage observed during the monitoring period.
The monitoring stops by calling
end_memory_monitoring() or, if
auto_stop
is True
when the process is terminated or exits.
PARAMETER | DESCRIPTION |
---|---|
auto_stop
|
If True, the monitoring will stop when the process exits normally or receives common termination signals (SIGINT, SIGTERM, SIGHUP).
TYPE:
|