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.

2
  • 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? Commented Dec 31, 2022 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 Commented Jan 2, 2023 at 0:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.