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

Process.get_cpu_percent() gives wrong values #390

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

Process.get_cpu_percent() gives wrong values #390

giampaolo opened this issue May 23, 2014 · 5 comments

Comments

@giampaolo
Copy link
Owner

From steve.ko...@gmail.com on June 06, 2013 14:26:08

What steps will reproduce the problem?  
1. get any valid Process instance
2. call get_cpu_percent on this instance with interval == 0
3. value will be zero, even when the process is not idle 

What is the expected output?  
get_cpu_percent(interval=0) should return values > 0.0 at least some time 

What do you see instead?  
values at 0 

What version of psutil are you using? What Python version?  
I'm using psutil 0.7.1, directly from code.google.com (same from pypi), with 
python 2.7 

On what operating system? Is it 32bit or 64bit version?  
It's an Ubuntu 13.04 64bit 

Please provide any additional information below.  
There are 4 logical CPUs on this system.

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

@giampaolo
Copy link
Owner Author

From g.rodola on June 06, 2013 05:30:47

From psutil doc:

> When interval is 0.0 or None compares process times to system CPU 
> times elapsed since last call, returning immediately. In this case 
> is recommended for accuracy that this function be called with at 
> least 0.1 seconds between calls.

That means the very first get_cpu_percent(interval=0) call will produce a 
meaningless value as it has no previous value to compare against.
It therefore means you'll need at least TWO calls in order to produce a 
meaningful result and wait some time between one call and the other.

@giampaolo
Copy link
Owner Author

From steve.ko...@gmail.com on June 06, 2013 05:40:39

Thank you for your quick answer Giampaolo. I forgot to tell that several calls, 
for the same process, with 5 sec. intervals, always give 0.
Is it relevant to say that everytime I call get_cpu_percent, I create a new 
instance of Process ?

@giampaolo
Copy link
Owner Author

From g.rodola on June 06, 2013 06:04:53

You should not create new Process instance every time. That's the problem.

@giampaolo
Copy link
Owner Author

From g.rodola on June 06, 2013 07:08:00

Status: Invalid

@giampaolo
Copy link
Owner Author

From steve.ko...@gmail.com on June 06, 2013 07:08:14

Yes, you are right, this was the problem.

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