Reputation: 91
I have a multi processing program. I need to check it's CPU usage and other variables like heap memory usage and number of processes used.. number of thread used. how to do this? I just want to know how my code is effecting my system.
Upvotes: 0
Views: 352
Reputation: 1201
Using the psutil
library saves a lot of work here.
You can install it via the various methods described on this page
Getting CPU usage, heap usage, thread count, and process count:
import psutil
import threading
print("CPU usage", psutil.cpu_percent())
print("HEAP usage", psutil.virtual_memory())
print("Active thread count", threading.active_count())
print("Process count", len([*psutil.process_iter()]))
Upvotes: 1