Question about cpu_times_percent

63 views
Skip to first unread message

Thiago Andrade

unread,
Jun 6, 2021, 5:19:00 PM6/6/21
to psutil
Hi guys,

I have the following question: When I use the "cpu_times_percent" function to get the nice, iowait, idle value. The values ​​when I run inside python they are returned but when I run inside a .py file for example psutil.cpu_times_percent().user or psutil.cpu_times_percent().idle the values ​​are reset. Does anyone know the reason? 

Exemple:
Inside python:

>>> psutil.cpu_times_percent()
scputimes(user=0.4, nice=0.0, system=0.7, idle=98.9, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)

Out of pyhon:

python3.7 test.py 
scputimes(user=0.0, nice=0.0, system=0.0, idle=0.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)

Thanks!

Giampaolo Rodola'

unread,
Jun 6, 2021, 5:26:08 PM6/6/21
to psu...@googlegroups.com
Hey there,
from the doc:
<<Warning: the first time this function is called with interval = 0.0 or None it will return a meaningless 0.0 value which you are supposed to ignore.>>
That's because in order to calculate percent you need a time window to compare CPU timings (numbers) between the first and the second call.


--
You received this message because you are subscribed to the "Python process utilities (psutil)" project group:
https://groups.google.com/g/psutil
To post to this group, send email to psu...@googlegroups.com
To unsubscribe from this group, send email to psutil-un...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "psutil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psutil+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psutil/d05a693d-5d3f-40cd-9c66-5d77f67b8aadn%40googlegroups.com.


--
Giampaolo - gmpy.dev

Reply all
Reply to author
Forward
0 new messages