1

I am trying to write a program that can measure the overall CPU usage.

I tried using psutil.cpu_percent(), but it is returning the CPU usage for only the python process.

Alexander L. Hayes
  • 3,892
  • 4
  • 13
  • 34
  • 2
    According to the documentation `psutil.cpu_percent()` returns the CPU utilization for the whole system. What makes you belive this isn't true in your case? – eandersson Dec 31 '22 at 18:03
  • when I look at the windows task manager it will show something like 45 percent cpu usage and it will show that python is using 5 percent and that is what python is shoing for me – Walker Lester Jan 02 '23 at 00:52

1 Answers1

1
import psutil
psutil.cpu_percent(5)

Count it for multiple seconds, will return the average cpu usage in 5 seconds. psutil.cpu_percent() Only gets the usage in the current moment, Which can go from 1 to 50+ in a few ms.