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 return a bunch o 0s #1378

Closed
KaduUlson opened this issue Dec 10, 2018 · 4 comments
Closed

cpu_percent return a bunch o 0s #1378

KaduUlson opened this issue Dec 10, 2018 · 4 comments

Comments

@KaduUlson
Copy link

I'm running a python script in Red Hat 7.3.1-5 to log the Memory and CPU usage for each second.

import datetime
import psutil
import pandas as pd

def writeusage(delt) :
    i = 1 
    usageLog = []
    for i in range(delt):
        usageNow = {"Time" : datetime.datetime.now(),
                    "CPU" : psutil.cpu_percent(interval = 1),
                    "MEMu": psutil.virtual_memory().used / (1024.0 ** 3),       
                    "MEMt": psutil.virtual_memory().total / (1024.0 ** 3),       
                    }
        usageLog.append(usageNow)
    return usageLog

dfusage = pd.DataFrame(writeusage(60))

But it returns a lot of 0s for the cpu_percent.
Is that a expected behavior?

    CPU            ...                                   Time
0   0.0            ...             2018-12-10 13:15:18.510315
1   0.0            ...             2018-12-10 13:15:19.512034
2   0.0            ...             2018-12-10 13:15:20.513665
3   0.0            ...             2018-12-10 13:15:21.514604
4   0.0            ...             2018-12-10 13:15:22.516246
5   0.0            ...             2018-12-10 13:15:23.517942
6   0.0            ...             2018-12-10 13:15:24.519579
7   0.0            ...             2018-12-10 13:15:25.521220
8   0.0            ...             2018-12-10 13:15:26.522852
9   0.0            ...             2018-12-10 13:15:27.524489
10  0.0            ...             2018-12-10 13:15:28.526169
11  0.0            ...             2018-12-10 13:15:29.527820
12  0.0            ...             2018-12-10 13:15:30.529541
13  0.0            ...             2018-12-10 13:15:31.531167
14  0.0            ...             2018-12-10 13:15:32.532778
15  1.0            ...             2018-12-10 13:15:33.534429
16  0.0            ...             2018-12-10 13:15:34.536053
17  0.0            ...             2018-12-10 13:15:35.537690
18  0.0            ...             2018-12-10 13:15:36.539335

Thanks in advance.

@giampaolo
Copy link
Owner

Mmmm I cannot reproduce that.

@bshen-telesign
Copy link

bshen-telesign commented Dec 13, 2018

This is happening in python3.6 on CentOS 6.9 for me as well. The same code above reproduces it on my machine.

Edit: As a note, I installed from source instead of using a binary wheel.

@Sygyzmundovych
Copy link

Try adding percpu=False like psutil.cpu_percent(percpu=False, interval = 1)

@giampaolo
Copy link
Owner

I'm gonna close this out as outdated. If the problem still occurs please paste the output below and we can reopen

import psutil, time
print(psutil.cpu_times())
stop_at = time.time() + 1
while time.time() < stop_at:
    psutil.cpu_times()
print(psutil.cpu_times())

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

4 participants