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

Everything cpu_percent seems to be 0 #67

Closed
giampaolo opened this issue May 23, 2014 · 15 comments
Closed

Everything cpu_percent seems to be 0 #67

giampaolo opened this issue May 23, 2014 · 15 comments

Comments

@giampaolo
Copy link
Owner

From CShadow...@googlemail.com on January 07, 2010 00:31:14

What steps will reproduce the problem?  
1. import psutil
2. psutil.cpu_percent()
3. 0.0 

What is the expected output?  


What do you see instead?  
Something higher than 0.0, like 14. What version of psutil are you using? On what operating system? 0.1.2 on Ubuntu 9.10 Karmic Koala (amd64) 

Please provide any additional information below.  
p.get_cpu_percent() also always returns 0.
Just looked at the example on your front page, everything cpu_percent on
the front page is 0 too, hehe.

Thanks :)

Original issue: http://code.google.com/p/psutil/issues/detail?id=67

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on January 06, 2010 16:57:21

Not sure what broke, but I can see the same issue on my OS X system too, in
cpu_percent() it looks like the code is hitting this: 

    # invalid data, will not be accurate so return 0.0 to avoid an overflow
    if time_delta < idle_delta:

The idle time is coming up way higher than the CPU time, so we're returning 0.0
instead of invalid data. I think the idle time might need to be divided by the number
of CPUs if there's more than one CPU.

CShadowRun, can you post the output of time.time() on your system and the output of
psutil.NUM_CPUS for confirmation? 

Thanks!

Status: Accepted

@giampaolo
Copy link
Owner Author

From CShadow...@googlemail.com on January 06, 2010 17:01:08

>>> import psutil, time
>>> print psutil.NUM_CPUS, psutil.cpu_percent(), time.time()
4 0.0 1262826006.23

There you go :)

@giampaolo
Copy link
Owner Author

From CShadow...@googlemail.com on January 08, 2010 06:24:56

I tried commenting out the invalid data stuff. That seems to make it work.

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on January 08, 2010 06:44:54

Indeed... I'm trying very hard to figure out why I added that line in the first place
and I can't come up with it. Possibly I had originally intended to test for the
opposite condition, but it seems to work without that line so I'm going to comment it
out of a future release I think. 

I'll start looking at get_cpu_percent() also

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on January 08, 2010 06:56:50

Looks like get_cpu_percent() was just needlessly dividing by NUM_CPUS which isn't
necessary. I've removed that for now as well, you can update to the trunk build from
SVN if you want to get the changes, after some testing we'll probably release this as
a bugfix release as well.

Thanks for the report!

Status: FixedInSVN

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on January 08, 2010 06:57:14

Labels: OpSys-All

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on January 24, 2010 10:37:18

I think we made a mistake here.
By running the test suite with my brand new dual core CPU I get a failure:

======================================================================
FAIL: test_system_cpu_percent (__main__.TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_psutil.py", line 124, in test_system_cpu_percent
    self.assertTrue(percent >= 0.0)
AssertionError

----------------------------------------------------------------------

By putting a print in there it turns out that the value is < 0.0.

Status: Started

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on January 24, 2010 18:31:29

Hmmm... if you roll back to the previous revision does it work properly for you? What
OS were you running it on? I have a dual core CPU on OS X and it works properly with
the current revision, so it's not just the dual-core CPU that's a factor evidently.

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on January 26, 2010 10:56:18

Yes, the test passes by rolling back to the previous revision.
The reason why it fails (I mean r437 ) is because the returning value can be a
negative float.
I'd say to revert everything to r436 .
Plus it seems I'm not able to reproduce the issue as everything seems to be fine here
( r436 ):

>>> psutil.cpu_percent()
1.4814142052562147
>>> psutil.cpu_percent()
5.0546903297230159
>>> psutil.cpu_percent()
5.7484403333479293
>>> psutil.cpu_percent()
3.1794161524182272
>>> psutil.cpu_percent()
5.2365247353658333
>>> psutil.cpu_percent()
1.7968535155163892
>>> psutil.cpu_percent()
1.6753533230840674
>>> psutil.cpu_percent()
8.5243699237857982
>>> psutil.cpu_percent()

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on January 30, 2010 16:34:25

FreeBSD 32bit is returning negative values with this section commented out

    if time_delta < idle_delta:
        return 0.0

Single CPU system in this case. I suspect that what's happening is idle time is
reporting idle for both CPUs and so idle_time can end up >= actual time delta. We
probably need to multiple the time_delta by the number of CPUs but I will need to do
some more checking to confirm.

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on February 04, 2010 05:40:33

Labels: Milestone-0.1.3

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on February 17, 2010 12:35:40

This appears to be resolved in the latest revision and work safely on OS X, FreeBSD,
Windows and Linux in various combinations of dual and single core processors. Think
we can close this (finally).

Status: FixedInSVN

@giampaolo
Copy link
Owner Author

From g.rodola on November 12, 2010 19:14:59

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on June 09, 2011 15:33:50

Labels: -OpSys-All

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 03:50:56

Updated csets after the SVN -> Mercurial migration: r436 == revision b202046cbee3 r437 == revision 19050afe6b6f

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

No branches or pull requests

1 participant