Initial implementation of blender benchmark addon
Just some glue logic to query progress and results from benchmark. Needed to move files around, so oth standalone and addon are happy.
This commit is contained in:
9
benchmark/foundation/third_party/cpu_cores/__init__.py
vendored
Normal file
9
benchmark/foundation/third_party/cpu_cores/__init__.py
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# This file is part of cpu_cores released under the MIT license.
|
||||
# See the LICENSE file for more information.
|
||||
|
||||
version_info = (0, 1, 3)
|
||||
__version__ = ".".join([str(x) for x in version_info])
|
||||
|
||||
from .common import CPUCoresCounter
|
||||
|
||||
__all__ = ['CPUCoresCounter']
|
43
benchmark/foundation/third_party/cpu_cores/common.py
vendored
Normal file
43
benchmark/foundation/third_party/cpu_cores/common.py
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
# This file is part of cpu_cores released under the MIT license.
|
||||
# See the LICENSE file for more information.
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
class CPUCoresCounter(object):
|
||||
|
||||
platform = None
|
||||
_physical_cores_count = None
|
||||
_physical_processors_count = None
|
||||
|
||||
def _count(self, *args, **kwargs):
|
||||
raise NotImplementedError()
|
||||
|
||||
@classmethod
|
||||
def factory(cls, force_platform=None):
|
||||
if force_platform is not None:
|
||||
cls.platform = force_platform
|
||||
else:
|
||||
cls.platform = sys.platform
|
||||
if cls.platform.startswith('darwin'):
|
||||
from .darwin import DarwinCPUCoresCounter
|
||||
return DarwinCPUCoresCounter()
|
||||
elif cls.platform.startswith('linux'):
|
||||
from .linux import LinuxCPUCoresCounter
|
||||
return LinuxCPUCoresCounter()
|
||||
else:
|
||||
raise NotImplementedError("unsupported platform type [%s]" %
|
||||
cls.platform)
|
||||
|
||||
def _check_counting_or_do_it(self):
|
||||
if self._physical_processors_count is None or \
|
||||
self._physical_cores_count is None:
|
||||
self._count()
|
||||
|
||||
def get_physical_cores_count(self):
|
||||
self._check_counting_or_do_it()
|
||||
return self._physical_cores_count
|
||||
|
||||
def get_physical_processors_count(self):
|
||||
self._check_counting_or_do_it()
|
||||
return self._physical_processors_count
|
35
benchmark/foundation/third_party/cpu_cores/darwin.py
vendored
Normal file
35
benchmark/foundation/third_party/cpu_cores/darwin.py
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# This file is part of cpu_cores released under the MIT license.
|
||||
# See the LICENSE file for more information.
|
||||
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
from .common import CPUCoresCounter
|
||||
|
||||
CPUINFO_COMMAND = "/usr/sbin/system_profiler" \
|
||||
" -detailLevel full SPHardwareDataType"
|
||||
|
||||
|
||||
class DarwinCPUCoresCounter(CPUCoresCounter):
|
||||
|
||||
def _count(self, command=None):
|
||||
if command is None:
|
||||
command = CPUINFO_COMMAND
|
||||
s = subprocess.Popen(shlex.split(command),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
if s:
|
||||
out, err = s.communicate()
|
||||
if len(err.strip()) > 0 or len(out.strip()) == 0:
|
||||
raise Exception('impossible to get the cpu cores count' +
|
||||
'(darwin) (error message = %s)' % err.strip())
|
||||
lines = out.split(b'\n')
|
||||
for line in lines:
|
||||
tmp = line.strip()
|
||||
if tmp.startswith(b'Total Number of Cores:'):
|
||||
self._physical_cores_count = int(tmp.split(b':')[1])
|
||||
if tmp.startswith(b'Number of Processors:'):
|
||||
self._physical_processors_count = int(tmp.split(b':')[1])
|
||||
if self._physical_processors_count is None or \
|
||||
self._physical_cores_count is None:
|
||||
raise Exception('impossible to get the cpu cores count (darwin)')
|
54
benchmark/foundation/third_party/cpu_cores/linux.py
vendored
Normal file
54
benchmark/foundation/third_party/cpu_cores/linux.py
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
# This file is part of cpu_cores released under the MIT license.
|
||||
# See the LICENSE file for more information.
|
||||
|
||||
from .common import CPUCoresCounter
|
||||
|
||||
CPUINFO_FILEPATH = "/proc/cpuinfo"
|
||||
|
||||
|
||||
def _core_hash(cpu_infos):
|
||||
if 'core id' not in cpu_infos and 'physical id' not in cpu_infos:
|
||||
return "%i" % cpu_infos['processor']
|
||||
if 'core id' in cpu_infos and 'physical id' not in cpu_infos:
|
||||
raise Exception("incorrect cpuinfo file :"
|
||||
" we have a core_id without physical_id")
|
||||
if 'core id' in cpu_infos:
|
||||
return "%i_%i" % (cpu_infos['physical id'], cpu_infos['core id'])
|
||||
else:
|
||||
return "%i" % cpu_infos['physical id']
|
||||
|
||||
|
||||
def _processor_hash(cpu_infos):
|
||||
if 'core id' not in cpu_infos and 'physical id' not in cpu_infos:
|
||||
return "%i" % cpu_infos['processor']
|
||||
if 'core id' in cpu_infos and 'physical id' not in cpu_infos:
|
||||
raise Exception("incorrect cpuinfo file :"
|
||||
" we have a core_id without physical_id")
|
||||
return "%i" % cpu_infos['physical id']
|
||||
|
||||
|
||||
class LinuxCPUCoresCounter(CPUCoresCounter):
|
||||
|
||||
def _count(self, cpuinfo_filepath=None):
|
||||
if cpuinfo_filepath is None:
|
||||
cpuinfo_filepath = CPUINFO_FILEPATH
|
||||
with open(cpuinfo_filepath, 'r') as f:
|
||||
# we read lines in reversed order to be sure to end with a
|
||||
# "processor:" line
|
||||
lines = reversed(f.readlines())
|
||||
cores = set()
|
||||
processors = set()
|
||||
cpu_infos = {}
|
||||
for line in lines:
|
||||
tmp = line.strip()
|
||||
for key in ('processor', 'physical id', 'core id'):
|
||||
if tmp.startswith(key):
|
||||
cpu_infos[key] = int(tmp.split(':')[1].strip())
|
||||
if key == 'processor':
|
||||
cores.add(_core_hash(cpu_infos))
|
||||
processors.add(_processor_hash(cpu_infos))
|
||||
cpu_infos = {}
|
||||
if len(cores) == 0 or len(processors) == 0:
|
||||
raise Exception("can't get the cpu cores count (linux)")
|
||||
self._physical_cores_count = len(cores)
|
||||
self._physical_processors_count = len(processors)
|
Reference in New Issue
Block a user