Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/runner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://docs.python.org/dev/library/tracemalloc.html>`_.
* ``--track-memory``: get the memory peak usage. it is less accurate than
Expand Down
18 changes: 5 additions & 13 deletions pyperf/_cpu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pyperf/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 1 addition & 16 deletions pyperf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down