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:
2018-08-02 17:38:10 +02:00
parent de682f8e8e
commit 7f42fdf5e8
40 changed files with 391 additions and 8998 deletions

View 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']

View 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

View 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)')

View 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)