aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
diff options
context:
space:
mode:
authormageven <62494521+mageven@users.noreply.github.com>2021-03-01 09:52:00 +0530
committerGitHub <noreply@github.com>2021-03-01 15:22:00 +1100
commit06a2b03cc91b38e3798d8cc1c57c186778c7e666 (patch)
tree1dd1cc0af8a79649053fe053c4246db8548f9230 /Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
parentd02eeed9c1ba8a8e4d18f18c24588f2953ad7ed6 (diff)
Revise SystemInfo (#2047)
* Revise SystemInfo Cleans up and adds a bit more info (logical core count and available mem at launch) to logs. - Extract CPU name from CPUID when supported. - Linux: Robust parsing of procfs files - Windows: Prefer native calls to WMI - Remove unnecessary virtual specifiers * Address gdkchan's comments * Address AcK's comments * Address formatting nits
Diffstat (limited to 'Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs')
-rw-r--r--Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs86
1 files changed, 64 insertions, 22 deletions
diff --git a/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs b/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
index 479dd25f..fdc8fb6a 100644
--- a/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
+++ b/Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
@@ -1,48 +1,90 @@
-using Ryujinx.Common.Logging;
using System;
+using System.Globalization;
using System.Management;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
+using Ryujinx.Common.Logging;
namespace Ryujinx.Common.SystemInfo
{
[SupportedOSPlatform("windows")]
- internal class WindowsSystemInfo : SystemInfo
+ class WindowsSystemInfo : SystemInfo
{
- public override string CpuName { get; }
- public override ulong RamSize { get; }
+ internal WindowsSystemInfo()
+ {
+ CpuName = $"{GetCpuidCpuName() ?? GetCpuNameWMI()} ; {LogicalCoreCount} logical"; // WMI is very slow
+ (RamTotal, RamAvailable) = GetMemoryStats();
+ }
- public WindowsSystemInfo()
+ private static (ulong Total, ulong Available) GetMemoryStats()
{
- bool wmiNotAvailable = false;
+ MemoryStatusEx memStatus = new MemoryStatusEx();
+ if (GlobalMemoryStatusEx(memStatus))
+ {
+ return (memStatus.TotalPhys, memStatus.AvailPhys); // Bytes
+ }
+ else
+ {
+ Logger.Error?.Print(LogClass.Application, $"GlobalMemoryStatusEx failed. Error {Marshal.GetLastWin32Error():X}");
+ }
- try
+ return (0, 0);
+ }
+
+ private static string GetCpuNameWMI()
+ {
+ ManagementObjectCollection cpuObjs = GetWMIObjects("root\\CIMV2", "SELECT * FROM Win32_Processor");
+
+ if (cpuObjs != null)
{
- foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor").Get())
+ foreach (var cpuObj in cpuObjs)
{
- CpuName = mObject["Name"].ToString();
+ return cpuObj["Name"].ToString().Trim();
}
+ }
- foreach (ManagementBaseObject mObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem").Get())
- {
- RamSize = ulong.Parse(mObject["TotalVisibleMemorySize"].ToString()) * 1024;
- }
+ return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER").Trim();
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
+ private class MemoryStatusEx
+ {
+ public uint Length;
+ public uint MemoryLoad;
+ public ulong TotalPhys;
+ public ulong AvailPhys;
+ public ulong TotalPageFile;
+ public ulong AvailPageFile;
+ public ulong TotalVirtual;
+ public ulong AvailVirtual;
+ public ulong AvailExtendedVirtual;
+
+ public MemoryStatusEx()
+ {
+ Length = (uint)Marshal.SizeOf(typeof(MemoryStatusEx));
}
- catch (PlatformNotSupportedException)
+ }
+
+ [return: MarshalAs(UnmanagedType.Bool)]
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ private static extern bool GlobalMemoryStatusEx([In, Out] MemoryStatusEx lpBuffer);
+
+ private static ManagementObjectCollection GetWMIObjects(string scope, string query)
+ {
+ try
{
- wmiNotAvailable = true;
+ return new ManagementObjectSearcher(scope, query).Get();
}
- catch (COMException)
+ catch (PlatformNotSupportedException ex)
{
- wmiNotAvailable = true;
+ Logger.Error?.Print(LogClass.Application, $"WMI isn't available : {ex.Message}");
}
-
- if (wmiNotAvailable)
+ catch (COMException ex)
{
- Logger.Error?.Print(LogClass.Application, "WMI isn't available, system informations will use default values.");
-
- CpuName = "Unknown";
+ Logger.Error?.Print(LogClass.Application, $"WMI isn't available : {ex.Message}");
}
+
+ return null;
}
}
} \ No newline at end of file