Bug 930808 - Upgrade to psutil 2.1.3; r=glandium

psutil 2.1.3 is replacing psutil 1.0.1. There are numerous bug fixes and
feature enhancements in psutil worth obtaining.

Source code was obtained from
https://pypi.python.org/packages/source/p/psutil/psutil-2.1.3.tar.gz and
uncompressed into python/psutil without modification except for the
removal of the egg-info directory and the .travis.yml file.
This commit is contained in:
Gregory Szorc
2014-12-23 10:45:15 -08:00
parent af58a95a53
commit 5881d1a65d
88 changed files with 13624 additions and 7313 deletions

View File

@@ -4,23 +4,27 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# TODO: add test for comparing connections with 'sockstat' cmd
"""BSD specific tests. These are implicitly run by test_psutil.py."""
import unittest
import subprocess
import time
import re
import sys
import os
import psutil
from psutil._compat import PY3
from test_psutil import *
from test_psutil import (TOLERANCE, sh, get_test_subprocess, which,
retry_before_failing, reap_children, unittest)
PAGESIZE = os.sysconf("SC_PAGE_SIZE")
MUSE_AVAILABLE = which('muse')
if os.getuid() == 0: # muse requires root privileges
MUSE_AVAILABLE = which('muse')
else:
MUSE_AVAILABLE = False
def sysctl(cmdline):
@@ -34,9 +38,10 @@ def sysctl(cmdline):
except ValueError:
return result
def muse(field):
"""Thin wrapper around 'muse' cmdline utility."""
out = sh('muse', stderr=DEVNULL)
out = sh('muse')
for line in out.split('\n'):
if line.startswith(field):
break
@@ -47,27 +52,29 @@ def muse(field):
class BSDSpecificTestCase(unittest.TestCase):
def setUp(self):
self.pid = get_test_subprocess().pid
@classmethod
def setUpClass(cls):
cls.pid = get_test_subprocess().pid
def tearDown(self):
@classmethod
def tearDownClass(cls):
reap_children()
def test_BOOT_TIME(self):
def test_boot_time(self):
s = sysctl('sysctl kern.boottime')
s = s[s.find(" sec = ") + 7:]
s = s[:s.find(',')]
btime = int(s)
self.assertEqual(btime, psutil.BOOT_TIME)
self.assertEqual(btime, psutil.boot_time())
def test_process_create_time(self):
cmdline = "ps -o lstart -p %s" %self.pid
cmdline = "ps -o lstart -p %s" % self.pid
p = subprocess.Popen(cmdline, shell=1, stdout=subprocess.PIPE)
output = p.communicate()[0]
if PY3:
output = str(output, sys.stdout.encoding)
start_ps = output.replace('STARTED', '').strip()
start_psutil = psutil.Process(self.pid).create_time
start_psutil = psutil.Process(self.pid).create_time()
start_psutil = time.strftime("%a %b %e %H:%M:%S %Y",
time.localtime(start_psutil))
self.assertEqual(start_ps, start_psutil)
@@ -101,7 +108,7 @@ class BSDSpecificTestCase(unittest.TestCase):
def test_memory_maps(self):
out = sh('procstat -v %s' % self.pid)
maps = psutil.Process(self.pid).get_memory_maps(grouped=False)
maps = psutil.Process(self.pid).memory_maps(grouped=False)
lines = out.split('\n')[1:]
while lines:
line = lines.pop()