mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-01-13 14:19:12 +00:00
Create only one session of CimSession
This commit is contained in:
parent
8abab7689c
commit
9345d284d9
1 changed files with 20 additions and 12 deletions
|
@ -10,15 +10,26 @@ namespace Ryujinx.Common.SystemInfo
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
partial class WindowsSystemInfo : SystemInfo
|
partial class WindowsSystemInfo : SystemInfo
|
||||||
{
|
{
|
||||||
|
private CimSession _cimSession;
|
||||||
|
|
||||||
internal WindowsSystemInfo()
|
internal WindowsSystemInfo()
|
||||||
{
|
{
|
||||||
CpuName = $"{GetCpuidCpuName() ?? GetCpuNameMMI()} ; {GetPhysicalCoreCount()} physical ; {LogicalCoreCount} logical"; // WMI is very slow
|
try
|
||||||
(RamTotal, RamAvailable) = GetMemoryStatsMMI();
|
{
|
||||||
|
//Inefficient to create a session for each query do it all at once
|
||||||
|
_cimSession = CimSession.Create(null);
|
||||||
|
CpuName = $"{GetCpuNameMMI() ?? GetCpuidCpuName()} ; {GetPhysicalCoreCount()} physical ; {LogicalCoreCount} logical";
|
||||||
|
(RamTotal, RamAvailable) = GetMemoryStatsMMI();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_cimSession?.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetCpuNameMMI()
|
private string GetCpuNameMMI()
|
||||||
{
|
{
|
||||||
var cpuObjs = GetMMIObjects(@"root\cimv2", "SELECT * FROM Win32_Processor");
|
var cpuObjs = GetMMIObjects(@"root\cimv2", "SELECT Name FROM Win32_Processor");
|
||||||
|
|
||||||
if (cpuObjs != null)
|
if (cpuObjs != null)
|
||||||
{
|
{
|
||||||
|
@ -31,10 +42,10 @@ namespace Ryujinx.Common.SystemInfo
|
||||||
return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")?.Trim();
|
return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")?.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static (ulong TotalPhys, ulong AvailPhys) GetMemoryStatsMMI()
|
private (ulong TotalPhys, ulong AvailPhys) GetMemoryStatsMMI()
|
||||||
{
|
{
|
||||||
var memObjs = GetMMIObjects(@"root\cimv2", "SELECT * FROM Win32_ComputerSystem");
|
var memObjs = GetMMIObjects(@"root\cimv2", "SELECT TotalPhysicalMemory FROM Win32_ComputerSystem");
|
||||||
var memObjs2 = GetMMIObjects(@"root\cimv2", "SELECT * FROM Win32_OperatingSystem");
|
var memObjs2 = GetMMIObjects(@"root\cimv2", "SELECT FreePhysicalMemory FROM Win32_OperatingSystem");
|
||||||
|
|
||||||
ulong TotalPhys = 0;
|
ulong TotalPhys = 0;
|
||||||
ulong AvailPhys = 0;
|
ulong AvailPhys = 0;
|
||||||
|
@ -58,14 +69,11 @@ namespace Ryujinx.Common.SystemInfo
|
||||||
return (TotalPhys, AvailPhys);
|
return (TotalPhys, AvailPhys);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<CimInstance> GetMMIObjects(string namespaceName, string query)
|
private IEnumerable<CimInstance> GetMMIObjects(string namespaceName, string query)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (CimSession session = CimSession.Create(null))
|
return _cimSession.QueryInstances(namespaceName, "WQL", query).ToList();
|
||||||
{
|
|
||||||
return session.QueryInstances(namespaceName, "WQL", query).ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (CimException ex)
|
catch (CimException ex)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue