How to measure total memory usage of all processes of a user in Python
It's pretty simple using psutil
. You can just iterate over all processes, select the ones that are owned by you and sum the memory returned by memory_info()
.
import psutil
import getpass
user = getpass.getuser()
total = sum(p.memory_info()[0] for p in psutil.process_iter()
if p.username() == user)
print('Total memory usage in bytes: ', total)