diff --git a/CREDITS b/CREDITS index baff0c089..eaeec114d 100644 --- a/CREDITS +++ b/CREDITS @@ -831,3 +831,6 @@ I: 2376 N: Anthony Ryan W: https://github.com/anthonyryan1 I: 2272 + +N: Frank Kusters +I: 1586 diff --git a/HISTORY.rst b/HISTORY.rst index d290221f2..04b6cfd48 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,7 +1,18 @@ *Bug tracker at https://github.com/giampaolo/psutil/issues* -6.0.0 2024-06-18 -================ +6.0.1 +===== + +**Bug fixes** + +- 1586_, `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``). + +6.0.0 +===== + +2024-06-18 **Enhancements** diff --git a/psutil/__init__.py b/psutil/__init__.py index 3a503503c..8230cac7f 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -1851,10 +1851,9 @@ def calculate(t1, t2): times_delta = _cpu_times_deltas(t1, t2) all_delta = _cpu_tot_time(times_delta) # "scale" is the value to multiply each delta with to get percentages. - # We use "max" to avoid division by zero (if all_delta is 0, then all - # fields are 0 so percentages will be 0 too. all_delta cannot be a - # fraction because cpu times are integers) - scale = 100.0 / max(1, all_delta) + # Avoid division by zero (if all_delta is 0, then all fields are 0 so + # percentages will be 0 too). + scale = 100.0 / all_delta if all_delta > 0 else 100.0 for field_delta in times_delta: field_perc = field_delta * scale field_perc = round(field_perc, 1)