private void SetSupportedInstructions(CpuModel cpu, ushort architecture) { var cpuFeatures = WindowsProcessor.GetSupportedInstructions().ToList(); if (architecture == 9) { cpuFeatures.Add(cpu.Manufacturer == "GenuineIntel" ? "EM64T" : "x86-64"); } cpu.Instructions = cpuFeatures.ToArray(); }
private static CpuCaches SetCaches(CpuModel cpu) { var cachesData = WindowsProcessor.GetCacheByLevel(); var caches = new CpuCaches(); if (cachesData.ContainsKey(1)) { var l1Cache = cachesData[1]; WindowsProcessor.SYSTEM_LOGICAL_PROCESSOR_INFORMATION?l1Data = l1Cache.FirstOrDefault(c => c.ProcessorInformation.Cache.Type == WindowsProcessor.PROCESSOR_CACHE_TYPE.CacheData); if (l1Data != null) { caches.Level1Data = MapCacheItem(l1Data, cpu.NumberOfCores); } WindowsProcessor.SYSTEM_LOGICAL_PROCESSOR_INFORMATION?l1Instruction = l1Cache.FirstOrDefault(c => c.ProcessorInformation.Cache.Type == WindowsProcessor.PROCESSOR_CACHE_TYPE.CacheInstruction); if (l1Instruction != null) { caches.Level1Instructions = MapCacheItem(l1Instruction, cpu.NumberOfCores); } } if (cachesData.ContainsKey(2)) { var l2Cache = cachesData[2]; caches.Level2 = MapCacheItem(l2Cache.FirstOrDefault(), cpu.NumberOfCores); } if (cachesData.ContainsKey(3)) { var l3Cache = cachesData[3]; caches.Level3 = MapCacheItem(l3Cache.FirstOrDefault()); } cpu.Caches = caches; return(caches); }
public ComputerModel GetAllData() { CpuModel[] cpus = null; try { var cpusProperties = devicePropertiesAdapter.GetMultipleProperties("Win32_Processor"); cpus = cpusProperties.Select(cp => { var cpu = new CpuModel() { Specification = cp["Name"].ToString() ?? "Unknown", CpuClocks = new CpuClocks() { CoreSpeed = cp["CurrentClockSpeed"] != null ? Convert.ToSingle((uint)(cp["CurrentClockSpeed"])) : 0f, BusSpeed = cp["ExtClock"] != null ? Convert.ToSingle((uint)(cp["ExtClock"])) : 0f, }, NumberOfCores = cp["NumberOfCores"] != null ? (uint)(cp["NumberOfCores"]) : 1, NumberOfLogicalProcessors = cp["NumberOfLogicalProcessors"] != null ? (uint)(cp["NumberOfLogicalProcessors"]) : 1, Architecture = ArchitectureHelper.GetArchitecture((ushort)cp["Architecture"], (ushort)cp["DataWidth"]), Manufacturer = cp["Manufacturer"]?.ToString() }; cpu = SetModelFamilyStepping(cpu, cp["Caption"].ToString()); SetSupportedInstructions(cpu, (ushort)cp["Architecture"]); SetCaches(cpu); SetCpuDetails(cpu); return(cpu); }).ToArray(); WindowsProcessor.GetSupportedInstructions(); } finally { if (cpus == null || cpus.Length == 0) { cpus = new CpuModel[] { new CpuModel() { CpuClocks = new CpuClocks() { }, Caches = new CpuCaches() { Level1Data = new CpuCacheItem(), Level1Instructions = new CpuCacheItem(), Level2 = new CpuCacheItem(), Level3 = new CpuCacheItem() }, CpuFamilyModelStepping = new CpuFamilyModelStepping() { } }, }; } } return(new ComputerModel() { Cpus = new AllCpus() { Cpus = cpus, RootCpu = cpus[0], TotalOfCores = cpus.Length > 1 ? (uint)cpus.Sum(c => c.NumberOfCores) : cpus[0].NumberOfCores, TotalOfLogicalProcessors = cpus.Length > 1 ? (uint)cpus.Sum(c => c.NumberOfLogicalProcessors) : cpus[0].NumberOfLogicalProcessors, } }); }