2020-12-01 21:26:00 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2021-03-01 04:22:00 +00:00
|
|
|
|
using System.Runtime.Intrinsics.X86;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-04 02:15:27 +00:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.SystemInfo
|
|
|
|
|
{
|
|
|
|
|
public class SystemInfo
|
|
|
|
|
{
|
2021-03-01 04:22:00 +00:00
|
|
|
|
public string OsDescription { get; protected set; }
|
|
|
|
|
public string CpuName { get; protected set; }
|
|
|
|
|
public ulong RamTotal { get; protected set; }
|
|
|
|
|
public ulong RamAvailable { get; protected set; }
|
|
|
|
|
protected static int LogicalCoreCount => Environment.ProcessorCount;
|
2020-05-04 02:15:27 +00:00
|
|
|
|
|
2021-03-01 04:22:00 +00:00
|
|
|
|
protected SystemInfo()
|
|
|
|
|
{
|
|
|
|
|
OsDescription = $"{RuntimeInformation.OSDescription} ({RuntimeInformation.OSArchitecture})";
|
|
|
|
|
CpuName = "Unknown";
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 22:27:42 +00:00
|
|
|
|
private static string ToMiBString(ulong bytesValue) => (bytesValue == 0) ? "Unknown" : $"{bytesValue / 1024 / 1024} MiB";
|
2021-03-01 04:22:00 +00:00
|
|
|
|
|
|
|
|
|
public void Print()
|
|
|
|
|
{
|
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Operating System: {OsDescription}");
|
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"CPU: {CpuName}");
|
2022-11-16 22:27:42 +00:00
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"RAM: Total {ToMiBString(RamTotal)} ; Available {ToMiBString(RamAvailable)}");
|
2021-03-01 04:22:00 +00:00
|
|
|
|
}
|
2020-05-04 02:15:27 +00:00
|
|
|
|
|
2021-03-01 04:22:00 +00:00
|
|
|
|
public static SystemInfo Gather()
|
2020-05-04 02:15:27 +00:00
|
|
|
|
{
|
2020-12-01 21:26:00 +00:00
|
|
|
|
if (OperatingSystem.IsWindows())
|
2020-05-04 02:15:27 +00:00
|
|
|
|
{
|
2021-03-01 04:22:00 +00:00
|
|
|
|
return new WindowsSystemInfo();
|
2020-05-04 02:15:27 +00:00
|
|
|
|
}
|
2020-12-01 21:26:00 +00:00
|
|
|
|
else if (OperatingSystem.IsLinux())
|
2020-05-04 02:15:27 +00:00
|
|
|
|
{
|
2021-03-01 04:22:00 +00:00
|
|
|
|
return new LinuxSystemInfo();
|
2020-05-04 02:15:27 +00:00
|
|
|
|
}
|
2020-12-01 21:26:00 +00:00
|
|
|
|
else if (OperatingSystem.IsMacOS())
|
2020-05-04 02:15:27 +00:00
|
|
|
|
{
|
2021-03-01 04:22:00 +00:00
|
|
|
|
return new MacOSSystemInfo();
|
2020-05-04 02:15:27 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-01 04:22:00 +00:00
|
|
|
|
Logger.Error?.Print(LogClass.Application, "SystemInfo unsupported on this platform");
|
|
|
|
|
|
|
|
|
|
return new SystemInfo();
|
2020-05-04 02:15:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-01 04:22:00 +00:00
|
|
|
|
|
|
|
|
|
// x86 exposes a 48 byte ASCII "CPU brand" string via CPUID leaves 0x80000002-0x80000004.
|
|
|
|
|
internal static string GetCpuidCpuName()
|
|
|
|
|
{
|
|
|
|
|
if (!X86Base.IsSupported)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if CPU supports the query
|
|
|
|
|
if ((uint)X86Base.CpuId(unchecked((int)0x80000000), 0).Eax < 0x80000004)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int[] regs = new int[12];
|
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < 3; ++i)
|
|
|
|
|
{
|
|
|
|
|
(regs[4 * i], regs[4 * i + 1], regs[4 * i + 2], regs[4 * i + 3]) = X86Base.CpuId((int)(0x80000002 + i), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string name = Encoding.ASCII.GetString(MemoryMarshal.Cast<int, byte>(regs)).Replace('\0', ' ').Trim();
|
|
|
|
|
|
|
|
|
|
return string.IsNullOrEmpty(name) ? null : name;
|
|
|
|
|
}
|
2020-05-04 02:15:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|