Im trying to measure the cpu usage of a process tree.
Currently getting the cpu_usage of a process (without children) will do, but I'm getting weird results.
import psutil
p = psutil.Process(PID)
p.cpu_percent
gives me back float
>100
, how is that even possible?
btw PID
is the pid of something simple as
def foo():
i = 0
while True:
i += 1
which according to task manager its cpu usage is around 12%
I want to get an output of 12.5
or something like that.
I read some documentation about psutil and here is what I got:
So in order to get rid of >100 you should do something like this:
Since i got this answer from somewhere else, I'll give you a link to check it out: http://psutil.readthedocs.io/en/release-2.2.1/#psutil.Process.cpu_percent