Rev 4413: (vila) Add cpu # detection for windows and Solaris in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Jun 5 09:10:42 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4413
revision-id: pqm at pqm.ubuntu.com-20090605081039-abvojdsxjbg5i4ff
parent: pqm at pqm.ubuntu.com-20090605045030-yj7sm39ao623zoqo
parent: v.ladeuil+lp at free.fr-20090605071408-k88525mfezj0hnim
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2009-06-05 09:10:39 +0100
message:
(vila) Add cpu # detection for windows and Solaris
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
------------------------------------------------------------
revno: 4412.1.1
revision-id: v.ladeuil+lp at free.fr-20090605071408-k88525mfezj0hnim
parent: pqm at pqm.ubuntu.com-20090605045030-yj7sm39ao623zoqo
parent: v.ladeuil+lp at free.fr-20090605071013-2pfodtb8ye5chlt0
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: integration
timestamp: Fri 2009-06-05 09:14:08 +0200
message:
(vila) Add cpu # detection for windows and Solaris
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
------------------------------------------------------------
revno: 4398.4.4
revision-id: v.ladeuil+lp at free.fr-20090605071013-2pfodtb8ye5chlt0
parent: v.ladeuil+lp at free.fr-20090604110537-apsikpui9ufvke95
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: parallel-test-fix-for-mac
timestamp: Fri 2009-06-05 09:10:13 +0200
message:
Fixed as per John's review.
* bzrlib/osutils.py:
(local_concurrency): Cache the calculated value by default.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
------------------------------------------------------------
revno: 4398.4.3
revision-id: v.ladeuil+lp at free.fr-20090604110537-apsikpui9ufvke95
parent: john at szakmeister.net-20090604005741-96eyg38538vt9pwp
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: parallel-test-fix-for-mac
timestamp: Thu 2009-06-04 13:05:37 +0200
message:
Detect # cores on win32 and Solaris too.
* bzrlib/tests/test_osutils.py:
(TestConcurrency): Add a smoke test for local_concurrency().
* bzrlib/tests/__init__.py:
(local_concurrency): Moved to osutils, all calls updated.
* bzrlib/osutils.py:
(local_concurrency): Moved from tests/__init__.py, add more
platform specific implementations.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
=== modified file 'NEWS'
--- a/NEWS 2009-06-05 04:50:30 +0000
+++ b/NEWS 2009-06-05 07:14:08 +0000
@@ -112,6 +112,8 @@
* The number of cores is now correctly detected on OSX. (John Szakmeister)
+* The number of cores is also detected on Solaris and win32. (Vincent Ladeuil)
+
bzr 1.15
########
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2009-05-23 04:55:52 +0000
+++ b/bzrlib/osutils.py 2009-06-05 07:10:13 +0000
@@ -38,6 +38,7 @@
from shutil import (
rmtree,
)
+import subprocess
import tempfile
from tempfile import (
mkdtemp,
@@ -1826,3 +1827,54 @@
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, settings)
return ch
+
+
+if sys.platform == 'linux2':
+ def _local_concurrency():
+ concurrency = None
+ prefix = 'processor'
+ for line in file('/proc/cpuinfo', 'rb'):
+ if line.startswith(prefix):
+ concurrency = int(line[line.find(':')+1:]) + 1
+ return concurrency
+elif sys.platform == 'darwin':
+ def _local_concurrency():
+ return subprocess.Popen(['sysctl', '-n', 'hw.availcpu'],
+ stdout=subprocess.PIPE).communicate()[0]
+elif sys.platform == 'sunos5':
+ def _local_concurrency():
+ return subprocess.Popen(['psrinfo', '-p',],
+ stdout=subprocess.PIPE).communicate()[0]
+elif sys.platform == "win32":
+ def _local_concurrency():
+ # This appears to return the number of cores.
+ return os.environ.get('NUMBER_OF_PROCESSORS')
+else:
+ def _local_concurrency():
+ # Who knows ?
+ return None
+
+
+_cached_local_concurrency = None
+
+def local_concurrency(use_cache=True):
+ """Return how many processes can be run concurrently.
+
+ Rely on platform specific implementations and default to 1 (one) if
+ anything goes wrong.
+ """
+ global _cached_local_concurrency
+ if _cached_local_concurrency is not None and use_cache:
+ return _cached_local_concurrency
+
+ try:
+ concurrency = _local_concurrency()
+ except (OSError, IOError):
+ concurrency = None
+ try:
+ concurrency = int(concurrency)
+ except (TypeError, ValueError):
+ concurrency = 1
+ if use_cache:
+ _cached_concurrency = concurrency
+ return concurrency
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-06-04 21:25:46 +0000
+++ b/bzrlib/tests/__init__.py 2009-06-05 07:14:08 +0000
@@ -2753,7 +2753,7 @@
def fork_decorator(suite):
- concurrency = local_concurrency()
+ concurrency = osutils.local_concurrency()
if concurrency == 1:
return suite
from testtools import ConcurrentTestSuite
@@ -2762,7 +2762,7 @@
def subprocess_decorator(suite):
- concurrency = local_concurrency()
+ concurrency = osutils.local_concurrency()
if concurrency == 1:
return suite
from testtools import ConcurrentTestSuite
@@ -2954,7 +2954,7 @@
:return: An iterable of TestCase-like objects which can each have
run(result) called on them to feed tests to result.
"""
- concurrency = local_concurrency()
+ concurrency = osutils.local_concurrency()
result = []
from subunit import TestProtocolClient, ProtocolTestCase
class TestInOtherProcess(ProtocolTestCase):
@@ -3003,7 +3003,7 @@
:return: An iterable of TestCase-like objects which can each have
run(result) called on them to feed tests to result.
"""
- concurrency = local_concurrency()
+ concurrency = osutils.local_concurrency()
result = []
from subunit import TestProtocolClient, ProtocolTestCase
class TestInSubprocess(ProtocolTestCase):
@@ -3049,34 +3049,6 @@
return result
-def cpucount(content):
- lines = content.splitlines()
- prefix = 'processor'
- for line in lines:
- if line.startswith(prefix):
- concurrency = int(line[line.find(':')+1:]) + 1
- return concurrency
-
-
-def local_concurrency():
- try:
- content = file('/proc/cpuinfo', 'rb').read()
- concurrency = cpucount(content)
- return concurrency
- except IOError:
- pass
-
- try:
- output = Popen(['sysctl', '-n', 'hw.availcpu'],
- stdout=PIPE).communicate()[0]
- concurrency = int(output)
- return concurrency
- except (OSError, IOError):
- concurrency = 1
-
- return concurrency
-
-
class BZRTransformingResult(unittest.TestResult):
def __init__(self, target):
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2009-05-23 04:55:52 +0000
+++ b/bzrlib/tests/test_osutils.py 2009-06-04 11:05:37 +0000
@@ -1760,3 +1760,10 @@
def test_os_readlink_link_decoding(self):
self.assertEquals(self.target.encode(osutils._fs_enc),
os.readlink(self.link.encode(osutils._fs_enc)))
+
+
+class TestConcurrency(tests.TestCase):
+
+ def test_local_concurrency(self):
+ concurrency = osutils.local_concurrency()
+ self.assertIsInstance(concurrency, int)
More information about the bazaar-commits
mailing list