Platform
- Ubuntu 16.04.6 LTS
- psutil Version: 5.6.3
Bug description
psutil.cpu_times_percent(interval=1, percpu=True) retrieves the wrong idle value on my machine
Examples
Example 1 (BUG):
import psutil
psutil.cpu_times_percent(interval=1, percpu=True)
Results - Example 1
[scputimes(user=2.0, nice=0.0, system=1.0, idle=64.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=1.0, nice=0.0, system=1.0, idle=64.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=9.0, nice=0.0, system=0.0, idle=56.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=67.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=3.0, nice=0.0, system=2.0, idle=62.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=66.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0)]
idle is around 66
idle should be around 95-100
Example 2 (BUG):
import psutil
psutil.cpu_times_percent(interval=0.5, percpu=True)
Results - Example 2
[scputimes(user=1.0, nice=0.0, system=0.0, idle=33.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=34.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=33.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=33.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=33.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=33.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0)]
idle is around 33
idle should be around 95-100
Example 3 (BUG):
import psutil
psutil.cpu_times_percent(interval=0.25, percpu=True)
Results - Example 3
[scputimes(user=0.0, nice=0.0, system=0.0, idle=17.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=17.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=17.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=17.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=17.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=17.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0)]
idle is around 17
idle should be around 95-100
Example 4 (BUG):
import psutil
psutil.cpu_times_percent(interval=0.125, percpu=True)
Results - Example 4
[scputimes(user=0.0, nice=0.0, system=0.0, idle=8.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=8.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=8.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=8.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=8.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=8.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0)]
idle is around 8
idle should be around 95-100
Example 5 (BUG):
import psutil
psutil.cpu_times_percent(interval=1.1, percpu=True)
Results - Example 5
[scputimes(user=5.0, nice=0.0, system=1.0, idle=69.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=73.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=73.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=73.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=73.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=73.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0)]
idle is around 70
idle should be around 95-100
Example 6 (OK):
import psutil
psutil.cpu_times_percent(interval=2, percpu=True)
Results - Example 6
[scputimes(user=0.0, nice=0.0, system=0.0, idle=100.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=100.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=100.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.8, nice=0.0, system=0.0, idle=99.2, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=100.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0),
scputimes(user=0.0, nice=0.0, system=0.0, idle=100.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0)]
idle is around 100 (OK)
idle should be around 95-100
Other Examples and observations:
- between with
0 < interval < 2.0 the values of idle increase
- values >= 1.5 seem better and better
- values >= 2.0 seem OK

- without the Parameter
percpu=True, we have NO problem with ANY interval:

Platform
Bug description
psutil.cpu_times_percent(interval=1, percpu=True)retrieves the wrongidlevalue on my machineExamples
Example 1 (BUG):
Results - Example 1
idleis around 66idleshould be around 95-100Example 2 (BUG):
Results - Example 2
idleis around 33idleshould be around 95-100Example 3 (BUG):
Results - Example 3
idleis around 17idleshould be around 95-100Example 4 (BUG):
Results - Example 4
idleis around 8idleshould be around 95-100Example 5 (BUG):
Results - Example 5
idleis around 70idleshould be around 95-100Example 6 (OK):
Results - Example 6
idleis around 100 (OK)idleshould be around 95-100Other Examples and observations:
0 < interval < 2.0the values ofidleincreasepercpu=True, we have NO problem with ANY interval: