diff --git a/doc/runner.rst b/doc/runner.rst index da724864..6e9dbf4c 100644 --- a/doc/runner.rst +++ b/doc/runner.rst @@ -146,7 +146,7 @@ Option:: There is no time out by default. * ``--tracemalloc``: Use the ``tracemalloc`` module to track Python memory allocation and get the peak of memory usage in metadata - (``tracemalloc_peak``). The module is only available on Python 3.4 and newer. + (``tracemalloc_peak``). See the `tracemalloc module `_. * ``--track-memory``: get the memory peak usage. it is less accurate than diff --git a/pyperf/_cpu_utils.py b/pyperf/_cpu_utils.py index f810df25..3199e845 100644 --- a/pyperf/_cpu_utils.py +++ b/pyperf/_cpu_utils.py @@ -17,20 +17,10 @@ def get_logical_cpu_count(): if psutil is not None: # Number of logical CPUs cpu_count = psutil.cpu_count() - elif hasattr(os, 'cpu_count'): + else: # Python 3.4 + # Python 3.13+: capped by -X cpu_count=n or $PYTHON_CPU_COUNT if set cpu_count = os.cpu_count() - else: - cpu_count = None - try: - import multiprocessing - except ImportError: - pass - else: - try: - cpu_count = multiprocessing.cpu_count() - except NotImplementedError: - pass if cpu_count is not None and cpu_count < 1: return None @@ -148,7 +138,7 @@ def get_isolated_cpus(): def set_cpu_affinity(cpus): - # Python 3.3 or newer? + # Availability: some Unix platforms if hasattr(os, 'sched_setaffinity'): os.sched_setaffinity(0, cpus) return True @@ -161,6 +151,8 @@ def set_cpu_affinity(cpus): except ImportError: return + # Availability: Linux, Windows, FreeBSD (psutil 2.2.0+) + # https://psutil.rtfd.io/en/latest/index.html#psutil.Process.cpu_affinity proc = psutil.Process() if not hasattr(proc, 'cpu_affinity'): return diff --git a/pyperf/_runner.py b/pyperf/_runner.py index 8000bc60..d87a2f69 100644 --- a/pyperf/_runner.py +++ b/pyperf/_runner.py @@ -416,12 +416,14 @@ def _cpu_affinity(self): else: if not isolated: print("ERROR: CPU affinity not available.", file=sys.stderr) - print("Use Python 3.3 or newer, or install psutil dependency") + print("Install psutil dependency and check " + "psutil.Process.cpu_affinity is available on your OS.") sys.exit(1) elif not self.args.quiet: print("WARNING: unable to pin worker processes to " "isolated CPUs, CPU affinity not available") - print("Use Python 3.3 or newer, or install psutil dependency") + print("Install psutil dependency and check " + "psutil.Process.cpu_affinity is available on your OS.") def _process_priority(self): if not MS_WINDOWS: diff --git a/pyperf/_utils.py b/pyperf/_utils.py index ef542d9d..540e7eed 100644 --- a/pyperf/_utils.py +++ b/pyperf/_utils.py @@ -174,22 +174,7 @@ def sysfs_path(path): def python_implementation(): - if hasattr(sys, 'implementation'): - # PEP 421, Python 3.3 - name = sys.implementation.name - else: - # Code extracted from platform.python_implementation(). - # Don't import platform to avoid the subprocess import. - sys_version = sys.version - if 'IronPython' in sys_version: - name = 'IronPython' - elif sys.platform.startswith('java'): - name = 'Jython' - elif "PyPy" in sys_version: - name = "PyPy" - else: - name = 'CPython' - return name.lower() + return sys.implementation.name.lower() def python_has_jit():