aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Common/SystemInfo/LinuxSystemInfo.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/LinuxSystemInfo.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/LinuxSystemInfo.cs')
-rw-r--r--Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs75
1 files changed, 68 insertions, 7 deletions
diff --git a/Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs b/Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs
index f067083e..069cd5aa 100644
--- a/Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs
+++ b/Ryujinx.Common/SystemInfo/LinuxSystemInfo.cs
@@ -1,19 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
using System.IO;
-using System.Linq;
using System.Runtime.Versioning;
+using Ryujinx.Common.Logging;
namespace Ryujinx.Common.SystemInfo
{
[SupportedOSPlatform("linux")]
- internal class LinuxSystemInfo : SystemInfo
+ class LinuxSystemInfo : SystemInfo
{
- public override string CpuName { get; }
- public override ulong RamSize { get; }
+ 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);
+
+ // Entries are in KB
+ ulong.TryParse(memDict["MemTotal"]?.Split(' ')[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out ulong totalKB);
+ ulong.TryParse(memDict["MemAvailable"]?.Split(' ')[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out ulong availableKB);
+
+ CpuName = $"{cpuName} ; {LogicalCoreCount} logical";
+ RamTotal = totalKB * 1024;
+ RamAvailable = availableKB * 1024;
+ }
- public LinuxSystemInfo()
+ private static void ParseKeyValues(string filePath, Dictionary<string, string> itemDict)
{
- CpuName = File.ReadAllLines("/proc/cpuinfo").Where(line => line.StartsWith("model name")).ToList()[0].Split(":")[1].Trim();
- RamSize = ulong.Parse(File.ReadAllLines("/proc/meminfo")[0].Split(":")[1].Trim().Split(" ")[0]) * 1024;
+ 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;
+ }
+ }
+ }
}
}
} \ No newline at end of file