Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu percent of process always 0.0 #691

Closed
aipv opened this issue Sep 28, 2015 · 1 comment
Closed

cpu percent of process always 0.0 #691

aipv opened this issue Sep 28, 2015 · 1 comment

Comments

@aipv
Copy link

aipv commented Sep 28, 2015

Hi,

I am using psutil in python 2.7 to get the cpu percent of the process, however, it always get 0.0 for current process. The system cpu percent is correct, and the cpu_time per process is also increased.

here is the test code which I am using:

def test_monitor():
    while True:
        cpu_times = psutil.cpu_times()
        print(cpu_times)
        cpu_percent = psutil.cpu_percent()
        print(cpu_percent)
        p = psutil.Process()
        p_cpu_times = p.cpu_times()
        print(p_cpu_times)
        cpu_percent = p.cpu_percent(1)
        print(cpu_percent)
        for i in range(10000000):
            j = i * i
        time.sleep(0.1)

Here is the output of the test code:

scputimes(user=3659.16, nice=36.96, system=971.1, idle=45878.04, iowait=1802.11, irq=1.34, softirq=18.26, steal=0.0, guest=0.0, guest_nice=0.0)
0.0
pcputimes(user=0.06, system=0.01)
0.0
scputimes(user=3661.55, nice=36.96, system=971.24, idle=45882.6, iowait=1802.11, irq=1.34, softirq=18.26, steal=0.0, guest=0.0, guest_nice=0.0)
35.6
pcputimes(user=2.39, system=0.12)
0.0
scputimes(user=3663.96, nice=36.96, system=971.33, idle=45886.99, iowait=1802.16, irq=1.34, softirq=18.26, steal=0.0, guest=0.0, guest_nice=0.0)
36.8
pcputimes(user=4.72, system=0.17)
0.0
....

Can anybody help to check where's the problem? thank you.

Best Regards,
Qing

@giampaolo
Copy link
Owner

Try this:

def test_monitor():
    p = psutil.Process()
    while True:
         print(p.cpu_percent(interval=1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants