CallbackPrintHardwareUsage

class odl.solvers.util.callback.CallbackPrintHardwareUsage(step=1, fmt_cpu='CPU usage (% each core): {}', fmt_mem='RAM usage: {}', fmt_swap='SWAP usage: {}', **kwargs)[source]

Bases: odl.solvers.util.callback.Callback

Callback for printing memory and CPU usage.

This callback requires the psutil package.

Methods

reset(self)

Set iter to 0.

__init__(self, step=1, fmt_cpu='CPU usage (% each core): {}', fmt_mem='RAM usage: {}', fmt_swap='SWAP usage: {}', \*\*kwargs)[source]

Initialize a new instance.

Parameters
steppositive int, optional

Number of iterations between output.

fmt_cpustring, optional

Formating that should be applied. The CPU usage is printed as

print(fmt_cpu.format(cpu))

where cpu is a vector with the percentage of current CPU usaged for each core. An empty format string disables printing of CPU usage.

fmt_memstring, optional

Formating that should be applied. The RAM usage is printed as

print(fmt_mem.format(mem))

where mem is the current RAM memory usaged. An empty format string disables printing of RAM memory usage.

fmt_swapstring, optional

Formating that should be applied. The SWAP usage is printed as

print(fmt_swap.format(swap))

where swap is the current SWAP memory usaged. An empty format string disables printing of SWAP memory usage.

Other Parameters
kwargs :

Key word arguments passed to the print function.

Examples

Print memory and CPU usage

>>> callback = CallbackPrintHardwareUsage()

Only print every tenth step

>>> callback = CallbackPrintHardwareUsage(step=10)

Only print the RAM memory usage in every step, and with a non-default formatting

>>> callback = CallbackPrintHardwareUsage(step=1, fmt_cpu='',
...                                       fmt_mem='RAM {}',
...                                       fmt_swap='')