2021-02-28 20:22:00 -08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
2020-05-03 19:15:27 -07:00
|
|
|
using System.IO;
|
2020-11-27 09:57:20 -08:00
|
|
|
using System.Runtime.Versioning;
|
2021-02-28 20:22:00 -08:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-03 19:15:27 -07:00
|
|
|
|
|
|
|
namespace Ryujinx.Common.SystemInfo
|
|
|
|
{
|
2020-11-27 09:57:20 -08:00
|
|
|
[SupportedOSPlatform("linux")]
|
2021-02-28 20:22:00 -08:00
|
|
|
class LinuxSystemInfo : SystemInfo
|
2020-05-03 19:15:27 -07:00
|
|
|
{
|
2021-02-28 20:22:00 -08:00
|
|
|
internal LinuxSystemInfo()
|
|
|
|
{
|
|
|
|
string cpuName = GetCpuidCpuName();
|
|
|
|
|
|
|
|
if (cpuName == null)
|
|
|
|
{
|
|
|
|
var cpuDict = new Dictionary<string, string>(StringComparer.Ordinal)
|
|
|
|
{
|
|
|
|
["model name"] = null,
|
|
|
|
["Processor"] = null,
|
|
|
|
["Hardware"] = null
|
|
|
|
};
|
|
|
|
|
|
|
|
ParseKeyValues("/proc/cpuinfo", cpuDict);
|
|
|
|
|
|
|
|
cpuName = cpuDict["model name"] ?? cpuDict["Processor"] ?? cpuDict["Hardware"] ?? "Unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
var memDict = new Dictionary<string, string>(StringComparer.Ordinal)
|
|
|
|
{
|
|
|
|
["MemTotal"] = null,
|
|
|
|
["MemAvailable"] = null
|
|
|
|
};
|
|
|
|
|
|
|
|
ParseKeyValues("/proc/meminfo", memDict);
|
|
|
|
|
2022-11-16 14:27:42 -08:00
|
|
|
// Entries are in KiB
|
|
|
|
ulong.TryParse(memDict["MemTotal"]?.Split(' ')[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out ulong totalKiB);
|
|
|
|
ulong.TryParse(memDict["MemAvailable"]?.Split(' ')[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out ulong availableKiB);
|
2021-02-28 20:22:00 -08:00
|
|
|
|
|
|
|
CpuName = $"{cpuName} ; {LogicalCoreCount} logical";
|
2022-11-16 14:27:42 -08:00
|
|
|
RamTotal = totalKiB * 1024;
|
|
|
|
RamAvailable = availableKiB * 1024;
|
2021-02-28 20:22:00 -08:00
|
|
|
}
|
2020-05-03 19:15:27 -07:00
|
|
|
|
2021-02-28 20:22:00 -08:00
|
|
|
private static void ParseKeyValues(string filePath, Dictionary<string, string> itemDict)
|
2020-05-03 19:15:27 -07:00
|
|
|
{
|
2021-02-28 20:22:00 -08:00
|
|
|
if (!File.Exists(filePath))
|
|
|
|
{
|
|
|
|
Logger.Error?.Print(LogClass.Application, $"File \"{filePath}\" not found");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = itemDict.Count;
|
|
|
|
|
|
|
|
using (StreamReader file = new StreamReader(filePath))
|
|
|
|
{
|
|
|
|
string line;
|
|
|
|
while ((line = file.ReadLine()) != null)
|
|
|
|
{
|
|
|
|
string[] kvPair = line.Split(':', 2, StringSplitOptions.TrimEntries);
|
|
|
|
|
|
|
|
if (kvPair.Length < 2) continue;
|
|
|
|
|
|
|
|
string key = kvPair[0];
|
|
|
|
|
|
|
|
if (itemDict.TryGetValue(key, out string value) && value == null)
|
|
|
|
{
|
|
|
|
itemDict[key] = kvPair[1];
|
|
|
|
|
|
|
|
if (--count <= 0) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 19:15:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|