Is there a Python package that can be used to find out if swap space was used during the execution of a function, and if it was used, the peak amount of usage? I know that psutil
can be used to check the status quo of swap space as mentioned in this answer.
>>> import psutil
>>> psutil.swap_memory()
sswap(total=2097147904L, used=886620160L, free=1210527744L, percent=42.3, sin=1050411008, sout=1906720768)
However, I can't figure out the way to use measure the peak usage of swap space in a specific function. I found that below method can be used to measure the peak usage of memory for a specific function, but I think this only includes in-memory usage, not the swap space.
from memory_profiler import memory_usage
from time import sleep
def f():
# a function that with growing
# memory consumption
a = [0] * 1000
sleep(.1)
b = a * 100
sleep(.1)
c = b * 100
return a
mem_usage = memory_usage(f)
print('Memory usage (in chunks of .1 seconds): %s' % mem_usage)
print('Maximum memory usage: %s' % max(mem_usage))
Is there any way to find out whether swap space was used, and if it was used, the peak swap space usage for a specific function in Python?