STATS#

Classes#

class utils.stats.track_system_stats(logger=None, disabled=False)[source]#

Bases: object

A context manager that tracks the memory usage of the system. Tracks both CPU and GPU memory usage if available.

Usage:

with track_system_stats() as t:
    for i in range(100):
    ... # Do something
    t()

    cpu_res, gpu_res = t.cpu_res, t.gpu_res
Parameters:
  • logger (Logger) – external logger.

  • disabled (bool) – If True, the context manager will not track the memory usage.

get_stats()[source]#

Get the memory usage of the system.

Returns:

(cpu_res, gpu_res) where cpu_res is the memory usage of the CPU and gpu_res is the memory usage of the GPU.

Return type:

tuple

print_stats()[source]#

Print the memory usage statistics.

update_stats(cpu_res, gpu_res)[source]#

Update the memory usage statistics.

Parameters:
  • cpu_res (float) – The memory usage of the CPU.

  • gpu_res (list) – The memory usage of the GPUs.

Functions#

utils.stats.get_memory_mb()[source]#

Get the memory usage of the current process and its children.

Returns:

A dictionary containing the memory usage of the current process and its children.

The dictionary has the following keys:
  • self: The memory usage of the current process.

  • children: The memory usage of the children of the current process.

  • total: The total memory usage of the current process and its children.

Return type:

dict