/// <summary> /// Parse the flags for an x86 machine /// TODO: in the future will need to overload this method with a variant for amr32 and arm64. /// </summary> /// <returns></returns> public List <int> ParseFlags() { uint[] raw = ProcessorInformation.CPUID(CPUIDOperation.GetProcessorInformation); //List of the every possible flag //Its impossible to do a list of enums (il2cpu errors). //You cannot cast by using methods like ToList()... //So we use the old friend "int". List <int> listOfFlags = new List <int>(); uint ecx = raw[2]; //Regular flags uint edx = raw[3]; //We need to convert edx to something that can be traslated to a bit array safely //We can't do (int)eax var edxBytes = BitConverter.GetBytes(edx); BitArray bitArrayEdx = new BitArray(edxBytes); //See: https://en.wikipedia.org/wiki/CPUID (this is where i got the information). mDebugger.Send("Bits parsed. Adding enums to table"); //TODO: this gives ilcpu error int offset = 0; //Foreach bit in ea for (int i = 0; i < 32; i++) { //Skip reserved flags if (i == 10 || i == 20) { offset--; continue; } mDebugger.Send("EDX: " + ((int)edx & (1 << i))); if (((int)edx & (1 << i)) > 0) { listOfFlags.Add(i + offset); } } for (int i = 0; i < 32; i++) { //Skip reserved flag if (i == 16) { offset--; } if (((int)ecx & (1 << i)) > 0) { listOfFlags.Add(i + offset + 32); } } mDebugger.Send("Strings added and parsed."); return(listOfFlags); }
public static long GetTimestamp() { if (Stopwatch.IsHighResolution) { // see https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx for more details return((long)(ProcessorInformation.GetCycleCount() / (double)ProcessorInformation.GetCycleRate() * 1000000d)); } else { return(DateTime.UtcNow.Ticks); } }
public string GetVendorName() { if (ProcessorInformation.CanReadCPUID() > 0) { uint[] raw = ProcessorInformation.CPUID(CPUIDOperation.GetVendorID); uint ebx = raw[1]; uint ecx = raw[2]; uint edx = raw[3]; //A little more inefficient but a lot clearer return(ConvertIntegerToString(ebx) + ConvertIntegerToString(edx) + ConvertIntegerToString(ecx)); } else { return("\0"); } }
/// <summary> /// Parses multiple information using eax = 1 and the returned eax register /// </summary> public void ParseInformation() { uint[] raw = ProcessorInformation.CPUID(CPUIDOperation.GetProcessorInformation); ///Position of the 96 bit signature uint eax = raw[0]; //NOTE: these equations are taken from the intel manual //We need the AND to get only the important bits //Get the first 4 bits this.Stepping = (int)eax & 15; //Sum the extended model to the standard model //Extended model: get bits 19:16 (base zero) and shift them 4 to the left //Standard model: get bits 7:4. this.ModelNumber = (((int)eax >> 16) & 15) << 4 + ((int)eax >> 4) & 15; //Get bits 27:20 of the extended family //Get bits 11:8 of the standard family this.Family = (((int)eax >> 20) & 511) + (((int)eax >> 8) & 15); }
public Processor() { //Old smbios calls /* * Speed = SMBIOSProcessor.CurrentSpeed; * ProcessorType = ParseType(SMBIOSProcessor.ProcessorType); * ProcessorFamily = ParseFamily(SMBIOSProcessor.ProcessorFamily); * SocketDesignation = SMBIOSProcessor.SocketDesignation; * Manufacturer = SMBIOSProcessor.ProcessorManufacturer; * ProcessorVersion = SMBIOSProcessor.ProcessorVersion; * Flags = ParseFlags(SMBIOSProcessor.CPUIDEAX, SMBIOSProcessor.CPUIDEDX); */ this.Manufacturer = GetVendorName(); this.Flags = ParseFlags(); //Parses stepping, model and family ParseInformation(); this.Frequency = ProcessorInformation.GetFrequency(); }
public static void SleepInternal(int ms) { // Implementation of http://referencesource.microsoft.com/#mscorlib/system/threading/thread.cs,6a577476abf2f437,references // see https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx for more details if ((ms > 0) && (ms != Timeout.Infinite)) { double fac = ProcessorInformation.GetCycleRate() / 1000d; double ticks = ms / 1000d * Stopwatch.Frequency + ProcessorInformation.GetCycleCount() * fac; while (ticks < ProcessorInformation.GetCycleCount() * fac) { new Action(() => { }).Invoke(); // execute an empty operation } } else if (ms < 0) { throw new ThreadInterruptedException(); } }
public string GetBrandName() { if (ProcessorInformation.CanReadCPUID() > 0) { uint[] raw = ProcessorInformation.CPUID(CPUIDOperation.GetProcessorBrand); return(ConvertIntegerToString(raw[0]) + ConvertIntegerToString(raw[1]) + ConvertIntegerToString(raw[2]) + ConvertIntegerToString(raw[3]) + ConvertIntegerToString(raw[4]) + ConvertIntegerToString(raw[5]) + ConvertIntegerToString(raw[6]) + ConvertIntegerToString(raw[8]) + ConvertIntegerToString(raw[9]) + ConvertIntegerToString(raw[10]) + ConvertIntegerToString(raw[11])); } else { return("\0"); } }
/// <summary> /// Try to get processor information /// </summary> /// <returns></returns> public ProcessorInformation GetProcessorInformation() { ProcessorInformation result = null; try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor"); foreach (ManagementObject queryObj in searcher.Get()) { result = new ProcessorInformation(); result.Caption = queryObj["Caption"].ToString(); result.CurrentClockSpeed = (queryObj["CurrentClockSpeed"] != null) ? Convert.ToUInt32(queryObj["CurrentClockSpeed"]) : 0; result.Description = queryObj["Description"].ToString(); result.ExtClock = (queryObj["ExtClock"] != null) ? Convert.ToUInt32(queryObj["ExtClock"]) : 0; result.L2CacheSize = (queryObj["L2CacheSize"] != null) ? Convert.ToUInt32(queryObj["L2CacheSize"]) : 0; result.L3CacheSize = (queryObj["L3CacheSize"] != null) ? Convert.ToUInt32(queryObj["L3CacheSize"]) : 0; result.Manufacturer = queryObj["Manufacturer"].ToString(); result.MaxClockSpeed = (queryObj["MaxClockSpeed"] != null) ? (0.001 * (UInt32)(queryObj["MaxClockSpeed"])).ToString("0.00") + " GHz" : "n.a."; result.Name = queryObj["Name"].ToString(); result.NumberOfCores = (queryObj["NumberOfCores"] != null) ? Convert.ToUInt32(queryObj["NumberOfCores"]) : 0; result.NumberOfLogicalProcessors = (queryObj["NumberOfLogicalProcessors"] != null) ? Convert.ToUInt32(queryObj["NumberOfLogicalProcessors"]) : 0; } } catch (ManagementException e) { // Log-Exception DependencyFactory.Resolve <ILoggingService>(ServiceNames.LoggingService).LogException("WmiHardwareInfoService: Fehler bei der Ermittlung der CPU-Informationen", e); // Show exception DependencyFactory.Resolve <IExceptionReporterService>(ServiceNames.ExceptionReporterService).ReportException(e); } return(result); }
static readonly IntPtr currentProcess = GetCurrentProcess(); // it returns a constant pseudo-handle, so we only need to call it once #endif static unsafe void InitializeProcessorInformation() { int cpuCores = 0, cpuThreads = 0, independentProcessors = 0; #if WINDOWS // TODO: this method only supports a maximum of 64 processors (32 on 32-bit systems), i.e. one processor group. we can use // GetLogicalProcessorInformationEx() to get information about all of the processor groups, but it might not even be helpful. // I'm not sure whether a single application can be scheduled across multiple processor groups anyway. also, that function is // only supported on Windows 7/2008 or later try { int length = 0; GetLogicalProcessorInformation(null, ref length); if (length != 0) { length /= sizeof(ProcessorInformation); // determine the number of structures from the byte length ProcessorInformation[] infos = new ProcessorInformation[length]; fixed(ProcessorInformation *pInfos = infos) { // TODO: test this on a single core machine to make sure all the relevant information is returned int byteLength = length * sizeof(ProcessorInformation); if (GetLogicalProcessorInformation(pInfos, ref byteLength)) { List <UIntPtr> coreMasks = new List <UIntPtr>(), independentProcessorMasks = new List <UIntPtr>(); // the information is returned as a list of information about features of groups of processors. the set of processors // that the information relates to are represented in the ProcessorMask field, and the information describes the // features shared by all of those processors. processors will usually be listed multiple times, in different sets, // as different sets of processors share different features, usually overlapping with other sets for (int i = 0; i < infos.Length; i++) { ProcessorInformation info = infos[i]; if (info.Sharing == ProcessorSharing.Core) // if the information describes a set of hardware threads sharing a core { int processorCount = BitCount((ulong)info.ProcessorMask); cpuThreads += processorCount; cpuCores++; coreMasks.Add(info.ProcessorMask); // treat the threads as independent processors if they don't share functional (computing) units if ((info.Relation.CoreFlags & CoreFlags.ShareFunctionalUnits) == 0) { independentProcessors += processorCount; AddMasks(independentProcessorMasks, (ulong)info.ProcessorMask); } else // otherwise, lump them together as a single independent processor { independentProcessors++; independentProcessorMasks.Add(info.ProcessorMask); } } } if (coreMasks.Count != 0) { cpuCoreMasks = coreMasks.ToArray(); } if (independentProcessorMasks.Count != 0) { SystemInformation.independentProcessorMasks = independentProcessorMasks.ToArray(); } } } } } catch { } // the GetLogicalProcessorInformation call is not available on all systems #else #warning Retrieving specific CPU information has not been implemented for this OS or the approprate preprocessor flag was not set. Falling back to Environment.ProcessorCount. #endif // fall back on using Environment.ProcessorCount if the information was not available if (cpuThreads == 0) { cpuThreads = Math.Max(1, Environment.ProcessorCount); } if (independentProcessors == 0) { independentProcessors = cpuThreads; } if (cpuCores == 0) { cpuCores = cpuThreads; } _cpuCores = cpuCores; _cpuThreads = cpuThreads; _independentProcessors = independentProcessors; }
public SMBIOS() { int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { this.raw = null; this.table = null; string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor"); string boardName = ReadSysFS("/sys/class/dmi/id/board_name"); string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version"); this.baseBoardInformation = new BaseBoardInformation( boardVendor, boardName, boardVersion, null); string systemVendor = ReadSysFS("/sys/class/dmi/id/sys_vendor"); string productName = ReadSysFS("/sys/class/dmi/id/product_name"); string productVersion = ReadSysFS("/sys/class/dmi/id/product_version"); this.systemInformation = new SystemInformation(systemVendor, productName, productVersion, null, null); string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor"); string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version"); this.biosInformation = new BIOSInformation(biosVendor, biosVersion); this.memoryDevices = new MemoryDevice[0]; } else { List<Structure> structureList = new List<Structure>(); List<MemoryDevice> memoryDeviceList = new List<MemoryDevice>(); raw = null; byte majorVersion = 0; byte minorVersion = 0; try { ManagementObjectCollection collection; using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSMBios_RawSMBiosTables")) { collection = searcher.Get(); } foreach (ManagementObject mo in collection) { raw = (byte[])mo["SMBiosData"]; majorVersion = (byte)mo["SmbiosMajorVersion"]; minorVersion = (byte)mo["SmbiosMinorVersion"]; break; } } catch { } if (majorVersion > 0 || minorVersion > 0) version = new Version(majorVersion, minorVersion); if (raw != null && raw.Length > 0) { int offset = 0; byte type = raw[offset]; while (offset + 4 < raw.Length && type != 127) { type = raw[offset]; int length = raw[offset + 1]; ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]); if (offset + length > raw.Length) break; byte[] data = new byte[length]; Array.Copy(raw, offset, data, 0, length); offset += length; List<string> stringsList = new List<string>(); if (offset < raw.Length && raw[offset] == 0) offset++; while (offset < raw.Length && raw[offset] != 0) { StringBuilder sb = new StringBuilder(); while (offset < raw.Length && raw[offset] != 0) { sb.Append((char)raw[offset]); offset++; } offset++; stringsList.Add(sb.ToString()); } offset++; switch (type) { case 0x00: this.biosInformation = new BIOSInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.biosInformation); break; case 0x01: this.systemInformation = new SystemInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.systemInformation); break; case 0x02: this.baseBoardInformation = new BaseBoardInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.baseBoardInformation); break; case 0x04: this.processorInformation = new ProcessorInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.processorInformation); break; case 0x11: MemoryDevice m = new MemoryDevice( type, handle, data, stringsList.ToArray()); memoryDeviceList.Add(m); structureList.Add(m); break; default: structureList.Add(new Structure( type, handle, data, stringsList.ToArray())); break; } } } memoryDevices = memoryDeviceList.ToArray(); table = structureList.ToArray(); } }
public SMBIOS() { if (OperatingSystem.IsUnix) { this.raw = null; this.table = null; string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor"); string boardName = ReadSysFS("/sys/class/dmi/id/board_name"); string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version"); this.baseBoardInformation = new BaseBoardInformation( boardVendor, boardName, boardVersion, null); string systemVendor = ReadSysFS("/sys/class/dmi/id/sys_vendor"); string productName = ReadSysFS("/sys/class/dmi/id/product_name"); string productVersion = ReadSysFS("/sys/class/dmi/id/product_version"); this.systemInformation = new SystemInformation(systemVendor, productName, productVersion, null, null); string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor"); string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version"); this.biosInformation = new BIOSInformation(biosVendor, biosVersion); this.memoryDevices = new MemoryDevice[0]; } else { List <Structure> structureList = new List <Structure>(); List <MemoryDevice> memoryDeviceList = new List <MemoryDevice>(); raw = null; byte majorVersion = 0; byte minorVersion = 0; try { // Get bios raw information ManagementObjectCollection collection; using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSMBios_RawSMBiosTables")) { collection = searcher.Get(); } foreach (ManagementObject mo in collection) { raw = (byte[])mo["SMBiosData"]; majorVersion = (byte)mo["SmbiosMajorVersion"]; minorVersion = (byte)mo["SmbiosMinorVersion"]; break; } } catch { } if (majorVersion > 0 || minorVersion > 0) { version = new Version(majorVersion, minorVersion); } if (raw != null && raw.Length > 0) { int offset = 0; byte type = raw[offset]; while (offset + 4 < raw.Length && type != 127) { // each iteration finds the structure inforamtion which are seperated by two zero bytes // first byte in structure is the type of information type = raw[offset]; // second byte in structure is the length of the structure header int length = raw[offset + 1]; ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]); if (offset + length > raw.Length) { break; } // data is the structure header not the actual values byte[] data = new byte[length]; Array.Copy(raw, offset, data, 0, length); // moves offset to the start of the structure values offset += length; // moves over all the zeros after the structure header List <string> stringsList = new List <string>(); if (offset < raw.Length && raw[offset] == 0) { offset++; } // Convert bytes to strings seperated by one zero byte, puts them in 'stringsList' // Structure ends at two successive zero bytes while (offset < raw.Length && raw[offset] != 0) { StringBuilder sb = new StringBuilder(); while (offset < raw.Length && raw[offset] != 0) { sb.Append((char)raw[offset]); offset++; } offset++; stringsList.Add(sb.ToString()); } offset++; switch (type) { case 0x00: this.biosInformation = new BIOSInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.biosInformation); break; case 0x01: this.systemInformation = new SystemInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.systemInformation); break; case 0x02: this.baseBoardInformation = new BaseBoardInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.baseBoardInformation); break; case 0x04: this.processorInformation = new ProcessorInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.processorInformation); break; case 0x07: //CPU Internal //LCachenum = (data[5] ^ 0x80) + 1 //LCacheNum = data[16] - 3 //LCacheNum = (data[16] ^ 0x04) + 1 //LCacheSize = data[8] << 8 //LCacheSize = data[10] << 8 //LCacheAssociativity = 0 //switch (data[18]) { //case 5: LCacheAssociativity = 4; break; //case 7: LCacheAssociativity = 8; break; //case 9: LCacheAssociativity = 12; break; //} break; case 0x11: MemoryDevice m = new MemoryDevice( type, handle, data, stringsList.ToArray()); memoryDeviceList.Add(m); structureList.Add(m); break; default: structureList.Add(new Structure( type, handle, data, stringsList.ToArray())); break; // type 8 = peripherals } } } memoryDevices = memoryDeviceList.ToArray(); table = structureList.ToArray(); } }
public SMBIOS() { int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { this.raw = null; this.table = null; string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor"); string boardName = ReadSysFS("/sys/class/dmi/id/board_name"); string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version"); this.baseBoardInformation = new BaseBoardInformation( boardVendor, boardName, boardVersion, null); string systemVendor = ReadSysFS("/sys/class/dmi/id/sys_vendor"); string productName = ReadSysFS("/sys/class/dmi/id/product_name"); string productVersion = ReadSysFS("/sys/class/dmi/id/product_version"); this.systemInformation = new SystemInformation(systemVendor, productName, productVersion, null, null); string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor"); string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version"); this.biosInformation = new BIOSInformation(biosVendor, biosVersion); this.memoryDevices = new MemoryDevice[0]; } else { List <Structure> structureList = new List <Structure>(); List <MemoryDevice> memoryDeviceList = new List <MemoryDevice>(); raw = null; byte majorVersion = 0; byte minorVersion = 0; try { ManagementObjectCollection collection; using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSMBios_RawSMBiosTables")) { collection = searcher.Get(); } foreach (ManagementObject mo in collection) { raw = (byte[])mo["SMBiosData"]; majorVersion = (byte)mo["SmbiosMajorVersion"]; minorVersion = (byte)mo["SmbiosMinorVersion"]; break; } } catch { } if (majorVersion > 0 || minorVersion > 0) { version = new Version(majorVersion, minorVersion); } if (raw != null && raw.Length > 0) { int offset = 0; byte type = raw[offset]; while (offset + 4 < raw.Length && type != 127) { type = raw[offset]; int length = raw[offset + 1]; ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]); if (offset + length > raw.Length) { break; } byte[] data = new byte[length]; Array.Copy(raw, offset, data, 0, length); offset += length; List <string> stringsList = new List <string>(); if (offset < raw.Length && raw[offset] == 0) { offset++; } while (offset < raw.Length && raw[offset] != 0) { StringBuilder sb = new StringBuilder(); while (offset < raw.Length && raw[offset] != 0) { sb.Append((char)raw[offset]); offset++; } offset++; stringsList.Add(sb.ToString()); } offset++; switch (type) { case 0x00: this.biosInformation = new BIOSInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.biosInformation); break; case 0x01: this.systemInformation = new SystemInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.systemInformation); break; case 0x02: this.baseBoardInformation = new BaseBoardInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.baseBoardInformation); break; case 0x04: this.processorInformation = new ProcessorInformation( type, handle, data, stringsList.ToArray()); structureList.Add(this.processorInformation); break; case 0x11: MemoryDevice m = new MemoryDevice( type, handle, data, stringsList.ToArray()); memoryDeviceList.Add(m); structureList.Add(m); break; default: structureList.Add(new Structure( type, handle, data, stringsList.ToArray())); break; } } } memoryDevices = memoryDeviceList.ToArray(); table = structureList.ToArray(); } }
public Smbios() { if (OperatingSystem.IsLinux) { raw = null; table = null; var boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor"); var boardName = ReadSysFS("/sys/class/dmi/id/board_name"); var boardVersion = ReadSysFS("/sys/class/dmi/id/board_version"); Board = new BaseBoardInformation( boardVendor, boardName, boardVersion, null); var systemVendor = ReadSysFS("/sys/class/dmi/id/sys_vendor"); var productName = ReadSysFS("/sys/class/dmi/id/product_name"); var productVersion = ReadSysFS("/sys/class/dmi/id/product_version"); System = new SystemInformation(systemVendor, productName, productVersion, null, null); var biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor"); var biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version"); BIOS = new BIOSInformation(biosVendor, biosVersion); MemoryDevices = new MemoryDevice[0]; } else { var structureList = new List <Structure>(); var memoryDeviceList = new List <MemoryDevice>(); raw = null; byte majorVersion = 0; byte minorVersion = 0; try { ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSSMBios_RawSMBiosTables")) { collection = searcher.Get(); } foreach (ManagementObject mo in collection) { raw = (byte[])mo["SMBiosData"]; majorVersion = (byte)mo["SmbiosMajorVersion"]; minorVersion = (byte)mo["SmbiosMinorVersion"]; break; } } catch { } if (majorVersion > 0 || minorVersion > 0) { version = new Version(majorVersion, minorVersion); } if (raw != null && raw.Length > 0) { var offset = 0; var type = raw[offset]; while (offset + 4 < raw.Length && type != 127) { type = raw[offset]; int length = raw[offset + 1]; var handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]); if (offset + length > raw.Length) { break; } var data = new byte[length]; Array.Copy(raw, offset, data, 0, length); offset += length; var stringsList = new List <string>(); if (offset < raw.Length && raw[offset] == 0) { offset++; } while (offset < raw.Length && raw[offset] != 0) { var sb = new StringBuilder(); while (offset < raw.Length && raw[offset] != 0) { sb.Append((char)raw[offset]); offset++; } offset++; stringsList.Add(sb.ToString()); } offset++; switch (type) { case 0x00: BIOS = new BIOSInformation( type, handle, data, stringsList.ToArray()); structureList.Add(BIOS); break; case 0x01: System = new SystemInformation( type, handle, data, stringsList.ToArray()); structureList.Add(System); break; case 0x02: Board = new BaseBoardInformation( type, handle, data, stringsList.ToArray()); structureList.Add(Board); break; case 0x04: Processor = new ProcessorInformation( type, handle, data, stringsList.ToArray()); structureList.Add(Processor); break; case 0x11: var m = new MemoryDevice( type, handle, data, stringsList.ToArray()); memoryDeviceList.Add(m); structureList.Add(m); break; default: structureList.Add(new Structure( type, handle, data, stringsList.ToArray())); break; } } } MemoryDevices = memoryDeviceList.ToArray(); table = structureList.ToArray(); } }
public static extern void GetSystemInfo(ref ProcessorInformation info);
static void Main(string[] args) { ProcessorInformation processor = new ProcessorInformation(); GetSystemInfo(ref processor); String architecture = ""; switch (processor.ProcessorArchitecture) { case 0: { architecture = "x86"; break; } case 5: { architecture = "ARM"; break; } case 6: { architecture = "Intel Itanium-based"; break; } case 9: { architecture = "x64(AMD or Intel)"; break; } case 12: { architecture = "ARM64"; break; } default: { architecture = "Unknown architecture"; break; } } Console.WriteLine("Processor architecture: {0}", architecture); Console.WriteLine("Processor type: {0}", processor.ProcessorType); Console.WriteLine("Number of CPUs: {0}", processor.NumberOfProcessors); Console.WriteLine("Processor level: {0}", processor.ProcessorLevel); Console.WriteLine("Processor revision: {0}", processor.ProcessorRevision); Console.WriteLine("Active processor mask: {0}", processor.ActiveProcessorMask); Console.WriteLine("Page size: {0}", processor.PageSize); Console.WriteLine("Allocation granularity: {0}", processor.AllocationGranularity); MemoryStatus memory = new MemoryStatus(); memory.Length = (uint)Marshal.SizeOf(typeof(MemoryStatus)); GlobalMemoryStatusEx(ref memory); Console.WriteLine($"\n\nThere is {memory.MemoryLoad}% of memory in use."); Console.WriteLine($"There are {memory.TotalPhys / 1024} total KB of physical memory " + $"({Math.Round(((double)memory.TotalPhys / Math.Pow(2, 30)), 2)} GB)."); Console.WriteLine($"There are {memory.AvailPhys / 1024} free KB of physical memory" + $"({Math.Round(((double)memory.AvailPhys / Math.Pow(2, 30)), 2)} GB)."); Console.WriteLine($"There are {memory.TotalPageFile / 1024} total KB of paging file" + $"({Math.Round(((double)memory.TotalPageFile / Math.Pow(2, 30)), 2)} GB)."); Console.WriteLine($"There are {memory.AvailPageFile / 1024} free KB of paging file" + $"({Math.Round(((double)memory.AvailPageFile / Math.Pow(2, 30)), 2)} GB)."); Console.WriteLine($"There are {memory.TotalVirtual / 1024} total KB of virtual memory" + $"({Math.Round(((double)memory.TotalVirtual / Math.Pow(2, 30)), 2)} GB)."); Console.WriteLine($"There are {memory.AvailVirtual / 1024} free KB of virtual memory" + $"({Math.Round(((double)memory.AvailVirtual / Math.Pow(2, 30)), 2)} GB)."); Console.WriteLine($"There are {memory.AvailExtendedVirtual / 1024} free KB of extended memory."); }