import json import platform import subprocess import sys from third_party import cpuinfo def _getBlenderDeviceInfo(ctx): PREFIX = "Benchmark Devices: " command = [ctx.blender, "--background", "--factory-startup", "-noaudio", "--enable-autoexec", "--engine", "CYCLES", "--python", ctx.configure_script, "--", "--benchmark-system-info"] process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = process.communicate() lines = stdout.decode().split("\n") for line in lines: if line.startswith(PREFIX): return json.loads(line[len(PREFIX):]) return [] def getBlenderVersion(ctx): INFO = ("build_date", "build_time", "build_commit_date", "build_commit_time", "build_hash") command = [ctx.blender, "--version"] process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = process.communicate() lines = stdout.decode().split("\n") info = {} for line in lines: line = line.strip() if line.startswith("Blender "): version = line[8:].strip() info['version'] = version if not line.startswith("build "): continue tokens = line.split(":", 1) tokens[0] = tokens[0].replace(" ", "_") if tokens[0] in INFO: info[tokens[0]] = tokens[1].strip() return info def getNumPhysicalCPUs_Linux(): ids = set() with open("/proc/cpuinfo") as f: for line in f.readlines(): if line.startswith("physical id"): id = int(line.split(":", 1)[1]) ids.add(id) return len(ids) def getNumPhysicalCPUs(): if sys.platform == 'linux': return getNumPhysicalCPUs_Linux() elif sys.platform == 'win32': # TODO(sergey): Currently all WIndows machines here are single socket. return 1 else: raise Exception("Needs implementation") def gatherSystemInfo(ctx): import psutil system_info = {} system_info['bitness'] = platform.architecture()[0] system_info['machine'] = platform.machine() system_info['system'] = platform.system() if system_info['system'] == "Linux": distro = platform.linux_distribution() system_info['dist_name'] = distro[0] system_info['dist_version'] = distro[1] # system_info['libc_version'] = "-".join(platform.libc_ver()) # TODO(sergey): Make this to work on Windows and macOS cpu_info = cpuinfo.get_cpu_info() system_info['cpu_brand'] = cpu_info['brand'] system_info["num_cpu_cores"] = psutil.cpu_count(logical=False) system_info["num_cpu_threads"] = psutil.cpu_count(logical=True) system_info["num_cpu_sockets"] = getNumPhysicalCPUs() system_info['devices'] = _getBlenderDeviceInfo(ctx) # TODO(sergey): query number of CPUs and threads. return system_info