giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.37k forks source link

Fix too low cpu_times_percent values when interval < ~1 second (#1586) #2413

Open frankkusters opened 2 months ago

frankkusters commented 2 months ago

Summary

Description

Implement suggestion by @ulxasc in https://github.com/giampaolo/psutil/issues/1586#issuecomment-896261172 . This fixes that cpu_times_percent() reports much too low values if the interval is less than 1 second (with percpu=True) or less than 1/cpu_count() seconds (with percpu=False).

giampaolo commented 2 weeks ago

With this change I get one failure:

======================================================================
FAIL: psutil.tests.test_linux.TestMisc.test_cpu_steal_decrease
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/giampaolo/svn/psutil/psutil/tests/test_linux.py", line 1569, in test_cpu_steal_decrease
    self.assertNotEqual(sum(cpu_times_percent), 100.0)
AssertionError: 100.0 == 100.0