nikademus79 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

get_cpu_percent issue when interval = 0 #251

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. >>> psutil.Process(20852).get_cpu_percent(interval=1)
   3.0
2. >>> psutil.Process(20852).get_cpu_percent(interval=0)
   0.0
3. Wait 1 second
4. >>> psutil.Process(20852).get_cpu_percent(interval=0)
   0.0
5. >>> psutil.Process(20852).get_cpu_percent(interval=1)
   3.0

What is the expected output?

The psutil.Process(20852).get_cpu_percent(interval=0) should return 3.0

What do you see instead?

The psutil.Process(20852).get_cpu_percent(interval=0) should return 0.0

What version of psutil are you using? What Python version?

>>> psutil.__version__
'0.4.1'
>>> import sys
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=2, releaselevel='final', serial=0)

On what operating system? Is it 32bit or 64bit version?

Ubuntu 11.10 32bit

Please provide any additional information below.

Original issue reported on code.google.com by nicolash...@gmail.com on 30 Jan 2012 at 2:52

GoogleCodeExporter commented 8 years ago
From the doc:

        When interval is 0.0 or None compares process times to system CPU
        times elapsed since last call, returning immediately.

In summary, you are not supposed to expect > 0.0 percentage if you call 
get_cpu_percent(interval=0) rapidly or do nothing between a call and another.
See this:

>>> import psutil, os
>>> p = psutil.Process(os.getpid())
>>> p.get_cpu_percent(interval=0)  # first call
0.0
>>> for x in range(10000000):
...     pass
... 
>>>
>>> # second call (compares CPU times elapsed since first call)
>>> p.get_cpu_percent(interval=0)  
8.7
>>>

Original comment by g.rodola on 30 Jan 2012 at 3:04