This repository has been archived on 2023-02-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-benchmark-bundle/benchmark/third_party/cpu_cores/common.py

44 lines
1.4 KiB
Python
Raw Normal View History

# 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 cpu_cores.darwin import DarwinCPUCoresCounter
return DarwinCPUCoresCounter()
elif cls.platform.startswith('linux'):
from cpu_cores.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