summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-01-20 16:24:57 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-01-20 16:24:57 +0100
commit76690f2a5495b405e5574edc09f6d0d90790a05e (patch)
tree4af2801ea91fa225deec5a0bf12266bf20d058f5
parent12a2a793f45a445275ec667feb701692621a875f (diff)
parente8c3b6af1e8495367dfc3bcb5312996f73a4d5d1 (diff)
downloadpsutil-76690f2a5495b405e5574edc09f6d0d90790a05e.tar.gz
Merge branch 'master' into 941-cpu-freq
-rw-r--r--.travis.yml1
-rw-r--r--CREDITS5
-rw-r--r--HISTORY.rst2
-rw-r--r--INSTALL.rst13
-rw-r--r--Makefile2
-rw-r--r--appveyor.yml11
-rw-r--r--docs/index.rst5
-rw-r--r--psutil/__init__.py9
-rwxr-xr-xpsutil/tests/test_linux.py115
-rwxr-xr-xscripts/internal/winmake.py14
-rwxr-xr-xsetup.py1
11 files changed, 122 insertions, 56 deletions
diff --git a/.travis.yml b/.travis.yml
index 17206c58..48c84a7b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@ matrix:
- python: 3.3
- python: 3.4
- python: 3.5
+ - python: 3.6
- "pypy"
# XXX - commented because OSX builds are deadly slow
# - language: generic
diff --git a/CREDITS b/CREDITS
index ccc4515f..031548ae 100644
--- a/CREDITS
+++ b/CREDITS
@@ -420,3 +420,8 @@ I: 919
N: Max BĂ©langer
W: https://github.com/maxbelanger
I: 936
+
+N: Pierre Fersing
+C: France
+E: pierre.fersing@bleemeo.com
+I: 950
diff --git a/HISTORY.rst b/HISTORY.rst
index 92413ec1..c6db2aa0 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -10,6 +10,8 @@
- 687_: [Linux] pid_exists() no longer returns True if passed a process thread
ID.
- 948_: cannot install psutil with PYTHONOPTIMIZE=2.
+- 950_: [Windows] Process.cpu_percent() was calculated incorrectly and showed
+ higher number than real usage.
5.0.1
diff --git a/INSTALL.rst b/INSTALL.rst
index fcbc3736..d731bd3d 100644
--- a/INSTALL.rst
+++ b/INSTALL.rst
@@ -5,12 +5,13 @@ pip is the easiest way to install psutil.
It is shipped by default with Python 2.7.9+ and 3.4+. If you're using an
older Python version `install pip <https://pip.pypa.io/en/latest/installing/>`__
first.
-If you GIT cloned psutil source code you can also install pip with::
+If you GIT cloned psutil source code you can also install pip and/or upgrade
+it to latest version with::
make install-pip
Unless you're on Windows, in order to install psutil with pip you'll also need
-a C compiler installed.
+a C compiler installed (e.g. gcc).
pip will retrieve psutil source code or binaries from
`PYPI <https://pypi.python.org/pypi/psutil>`__ repository.
@@ -137,6 +138,14 @@ Install:
pkg install gcc
python -m pip install psutil
+Install from sources
+====================
+
+ git clone https://github.com/giampaolo/psutil.git
+ cd psutil
+ python setup.py install
+
+
Dev Guide
=========
diff --git a/Makefile b/Makefile
index 9224a0bb..95db068c 100644
--- a/Makefile
+++ b/Makefile
@@ -210,7 +210,7 @@ win-download-exes:
# Upload exes/wheels in dist/* directory to PYPI.
win-upload-exes:
$(PYTHON) -m twine upload dist/*.exe
- $(PYTHON) -m twine upload dist/*.wheel
+ $(PYTHON) -m twine upload dist/*.whl
# All the necessary steps before making a release.
pre-release:
diff --git a/appveyor.yml b/appveyor.yml
index 927d9cb3..4428f776 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -30,6 +30,10 @@ environment:
PYTHON_VERSION: "3.5.x"
PYTHON_ARCH: "32"
+ - PYTHON: "C:\\Python36"
+ PYTHON_VERSION: "3.6.x"
+ PYTHON_ARCH: "32"
+
# 64 bits
- PYTHON: "C:\\Python27-x64"
@@ -51,6 +55,13 @@ environment:
VS_VER: "2015"
INSTANCENAME: "SQL2012SP1"
+ - PYTHON: "C:\\Python36-x64"
+ PYTHON_VERSION: "3.6.x"
+ PYTHON_ARCH: "64"
+ ARCH: x86_64
+ VS_VER: "2015"
+ INSTANCENAME: "SQL2012SP1"
+
# Also build on a Python version not pre-installed by Appveyor.
# See: https://github.com/ogrisel/python-appveyor-demo/issues/10
diff --git a/docs/index.rst b/docs/index.rst
index 022c6a6b..270124b7 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -39,11 +39,12 @@ The psutil documentation you're reading is distributed as a single HTML page.
Install
-------
-On Windows, or on UNIX if you have a C compiler installed, the easiest way to
-install psutil is via ``pip``::
+The easiest way to install psutil is via ``pip``::
pip install psutil
+On UNIX this requires a C compiler (e.g. gcc) installed. On Windows pip will
+automatically retrieve a pre-compiled wheel version.
Alternatively, see more detailed
`install <https://github.com/giampaolo/psutil/blob/master/INSTALL.rst>`_
instructions.
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 94ace42a..4fed9fea 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -1007,13 +1007,8 @@ class Process(object):
raise ValueError("interval is not positive (got %r)" % interval)
num_cpus = cpu_count() or 1
- if POSIX:
- def timer():
- return _timer() * num_cpus
- else:
- def timer():
- t = cpu_times()
- return sum((t.user, t.system))
+ def timer():
+ return _timer() * num_cpus
if blocking:
st1 = timer()
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 028a41d9..37352ecf 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -581,7 +581,8 @@ class TestSystemNetwork(unittest.TestCase):
except RuntimeError:
pass
else:
- self.assertEqual(stats.isup, 'RUNNING' in out, msg=out)
+ # Not always reliable.
+ # self.assertEqual(stats.isup, 'RUNNING' in out, msg=out)
self.assertEqual(stats.mtu,
int(re.findall('MTU:(\d+)', out)[0]))
@@ -1037,49 +1038,6 @@ class TestProcess(unittest.TestCase):
tearDown = setUp
- def test_compare_stat_and_status_files(self):
- # /proc/pid/stat and /proc/pid/status have many values in common.
- # Whenever possible, psutil uses /proc/pid/stat (it's faster).
- # For all those cases we check that the value found in
- # /proc/pid/stat (by psutil) matches the one found in
- # /proc/pid/status.
- p = psutil.Process()
- with psutil._psplatform.open_text('/proc/%s/status' % p.pid) as f:
- for line in f:
- line = line.strip()
- if line.startswith('Name:'):
- name = line.split()[1]
- # Name is truncated to 15 chars
- self.assertEqual(p.name()[:15], name[:15])
- elif line.startswith('State:'):
- status = line[line.find('(') + 1:line.rfind(')')]
- status = status.replace(' ', '-')
- self.assertEqual(p.status(), status)
- elif line.startswith('PPid:'):
- ppid = int(line.split()[1])
- self.assertEqual(p.ppid(), ppid)
- # The ones below internally are determined by reading
- # 'status' file but we use a re to extract the info
- # so it makes sense to check them.
- elif line.startswith('Threads:'):
- num_threads = int(line.split()[1])
- self.assertEqual(p.num_threads(), num_threads)
- elif line.startswith('Uid:'):
- uids = tuple(map(int, line.split()[1:4]))
- self.assertEqual(tuple(p.uids()), uids)
- elif line.startswith('Gid:'):
- gids = tuple(map(int, line.split()[1:4]))
- self.assertEqual(tuple(p.gids()), gids)
- elif line.startswith('voluntary_ctxt_switches:'):
- vol = int(line.split()[1])
- self.assertAlmostEqual(
- p.num_ctx_switches().voluntary, vol, delta=2)
- elif line.startswith('nonvoluntary_ctxt_switches:'):
- invol = int(line.split()[1])
- self.assertAlmostEqual(
- p.num_ctx_switches().involuntary, invol,
- delta=2)
-
def test_memory_full_info(self):
src = textwrap.dedent("""
import time
@@ -1251,5 +1209,74 @@ class TestProcess(unittest.TestCase):
self.assertRaises(psutil.ZombieProcess, psutil.Process().exe)
+@unittest.skipUnless(LINUX, "LINUX only")
+class TestProcessAgainstStatus(unittest.TestCase):
+ """/proc/pid/stat and /proc/pid/status have many values in common.
+ Whenever possible, psutil uses /proc/pid/stat (it's faster).
+ For all those cases we check that the value found in
+ /proc/pid/stat (by psutil) matches the one found in
+ /proc/pid/status.
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ cls.proc = psutil.Process()
+
+ def read_status_file(self, linestart):
+ with psutil._psplatform.open_text(
+ '/proc/%s/status' % self.proc.pid) as f:
+ for line in f:
+ line = line.strip()
+ if line.startswith(linestart):
+ value = line.partition('\t')[2]
+ try:
+ return int(value)
+ except ValueError:
+ return value
+ else:
+ raise ValueError("can't find %r" % linestart)
+
+ def test_name(self):
+ value = self.read_status_file("Name:")
+ self.assertEqual(self.proc.name(), value)
+
+ def test_status(self):
+ value = self.read_status_file("State:")
+ value = value[value.find('(') + 1:value.rfind(')')]
+ value = value.replace(' ', '-')
+ self.assertEqual(self.proc.status(), value)
+
+ def test_ppid(self):
+ value = self.read_status_file("PPid:")
+ self.assertEqual(self.proc.ppid(), value)
+
+ def test_num_threads(self):
+ value = self.read_status_file("Threads:")
+ self.assertEqual(self.proc.num_threads(), value)
+
+ def test_uids(self):
+ value = self.read_status_file("Uid:")
+ value = tuple(map(int, value.split()[1:4]))
+ self.assertEqual(self.proc.uids(), value)
+
+ def test_gids(self):
+ value = self.read_status_file("Gid:")
+ value = tuple(map(int, value.split()[1:4]))
+ self.assertEqual(self.proc.gids(), value)
+
+ @retry_before_failing()
+ def test_num_ctx_switches(self):
+ value = self.read_status_file("voluntary_ctxt_switches:")
+ self.assertEqual(self.proc.num_ctx_switches().voluntary, value)
+ value = self.read_status_file("nonvoluntary_ctxt_switches:")
+ self.assertEqual(self.proc.num_ctx_switches().involuntary, value)
+
+ def test_cpu_affinity(self):
+ value = self.read_status_file("Cpus_allowed_list:")
+ min_, max_ = map(int, value.split('-'))
+ self.assertEqual(
+ self.proc.cpu_affinity(), list(range(min_, max_ + 1)))
+
+
if __name__ == '__main__':
run_test_module_by_name(__file__)
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index bbe73e0d..e2c1f086 100755
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -171,6 +171,20 @@ def build():
@cmd
+def build_exe():
+ """Create exe file."""
+ build()
+ sh("%s setup.py bdist_wininst" % PYTHON)
+
+
+@cmd
+def build_wheel():
+ """Create wheel file."""
+ build()
+ sh("%s setup.py bdist_wheel" % PYTHON)
+
+
+@cmd
def install_pip():
"""Install pip"""
try:
diff --git a/setup.py b/setup.py
index 426b7eb7..80521a48 100755
--- a/setup.py
+++ b/setup.py
@@ -301,6 +301,7 @@ def main():
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Programming Language :: Python',