Ejemplo n.º 1
0
        /// <summary> Finds all GPUs and creates a GPU instance for each </summary>
        public static void GetGPUInstances()
        {
            var devices = Directory.EnumerateDirectories("/sys/bus/pci/devices/");

            foreach (string directory in devices)
            {
                if (File.Exists($"{directory}/boot_vga"))
                {
                    ushort vid  = Convert.ToUInt16(FileReader.ReadLine($"{directory}/vendor"), 16);
                    ushort did  = Convert.ToUInt16(FileReader.ReadLine($"{directory}/device"), 16);
                    ushort svid = Convert.ToUInt16(FileReader.ReadLine($"{directory}/subsystem_vendor"), 16);
                    ushort sdid = Convert.ToUInt16(FileReader.ReadLine($"{directory}/subsystem_device"), 16);

                    GPUs.Add(new GPU(vid, did, svid, sdid));
                }
            }
        }
Ejemplo n.º 2
0
        public static void GetCPUInfo()
        {
            string modelexpr  = @"model\sname\s*:\s*([a-zA-Z0-9()\- ,+]*[^ @])";
            string vendorexpr = @"vendor_id\s*:\s*(.*)";
            string idexpr     = @"physical id\s*:\s*(\d+)";

            CPU.model  = FileReader.ReadFileAndFindGroup("/proc/cpuinfo", modelexpr, 1);
            CPU.vendor = FileReader.ReadFileAndFindGroup("/proc/cpuinfo", vendorexpr, 1);
            // workaround for VMs - doesn't seem to exist in KVM-based VMs
            try
            {
                CPU.speed = $"{Math.Round(decimal.Parse(FileReader.ReadLine("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"))/1000000, 2)} GHz";
            }
            catch
            {
                CPU.speed = null;
                Console.WriteLine("could not get cpu speed!");
            }
            var cpus = Directory.EnumerateDirectories("/sys/devices/system/cpu");

            foreach (string s in cpus)
            {
                if (Regex.IsMatch(s, @"cpu\d+"))
                {
                    CPU.threadCount++;
                }
            }

            List <String> idarr       = FileReader.ReadFileMatchMultiple("/proc/cpuinfo", idexpr, 1);
            Int32         CPUCountInt = Int32.Parse(idarr[idarr.Count - 1]) + 1;

            switch (CPUCountInt)
            {
            case 1:
                CPU.count = null;
                break;

            default:
                CPU.count = $"{CPUCountInt}x ";
                break;
            }
        }