From 97c74fc91ba4c00f135d16ed012c6d65a68680ae Mon Sep 17 00:00:00 2001 From: L3tum <9307432+L3tum@users.noreply.github.com> Date: Sat, 19 Oct 2019 14:17:59 +0200 Subject: [PATCH] Remove frequency monitoring because it's way too expensive --- .../MachineInformationGatherer.cs | 84 ------------------- README.md | 6 -- 2 files changed, 90 deletions(-) diff --git a/HardwareInformation/MachineInformationGatherer.cs b/HardwareInformation/MachineInformationGatherer.cs index 0dc20eb..630c699 100644 --- a/HardwareInformation/MachineInformationGatherer.cs +++ b/HardwareInformation/MachineInformationGatherer.cs @@ -307,89 +307,5 @@ private static void GetCoreSpeeds() information.Cpu.MaxClockSpeed = information.Cpu.Cores.Count > 0 ? information.Cpu.Cores.Max(c => c.MaxClockSpeed) : 0; } - - /// - /// Monitors the frequency of the specified core until the token is cancelled. Reports maximum frequency in - /// Core.MaxClockSpeed and minimum frequency in Core.NormalClockSpeed. - /// - /// - /// 0-indexed number of the core to monitor. Includes hyperthreaded cores (e.g. 0 and 1 are the - /// same physical core) - /// - /// Token to stop the monitoring. - /// - /// Delay in ms for taking the measurement (e.g. wait $measurementDelay, take measurement, - /// repeat). Values under 1000ms may produce wrong results. - /// - /// - public static Task MonitorCoreFrequencies(int coreNumber, - CancellationToken token, int measurementDelay = 1000) - { - if (coreNumber > 64 || coreNumber < 0) - { - throw new ArgumentException("Core Number must be below 65 and above 0!"); - } - - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && - !RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - throw new PlatformNotSupportedException("This method only works on Windows or Linux!"); - } - - return Task.Run(() => - { - var core = new MachineInformation.Core(); - var highestFrequency = 0u; - var lowestFrequency = 0u; - PerformanceCounter counter = null; - var normalFrequency = 0u; - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - counter = new PerformanceCounter("Processor Information", "% Processor Performance", - "0," + coreNumber); - counter.NextValue(); - - ManagementObject Mo = new ManagementObject($"Win32_Processor.DeviceID='CPU{coreNumber}'"); - - normalFrequency = (uint) Mo["MaxClockSpeed"]; - } - - while (!token.IsCancellationRequested) - { - Thread.Sleep(measurementDelay); - var measuredValue = 0u; - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - measuredValue = (uint) (counter.NextValue() / 100.0f * normalFrequency); - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - // KHz - var freq = ulong.Parse( - File.ReadAllText($"/sys/devices/system/cpu/cpu{coreNumber}/cpufreq/scaling_cur_freq")); - - measuredValue = (uint) (freq / 1000); - } - - if (measuredValue > highestFrequency) - { - highestFrequency = measuredValue; - } - - if (measuredValue < lowestFrequency) - { - lowestFrequency = measuredValue; - } - } - - core.Number = (uint) coreNumber; - core.MaxClockSpeed = highestFrequency; - core.NormalClockSpeed = lowestFrequency; - - return core; - }); - } } } \ No newline at end of file diff --git a/README.md b/README.md index f93d708..f67e586 100644 --- a/README.md +++ b/README.md @@ -90,12 +90,6 @@ HRF = Human Readable Format. Normal capacity/size is in bytes, while this is a s **\*\*\*\* Only available on AMD platforms.** -One additional feature is drive-by core frequency monitoring. This is available on Windows and Linux by calling the following function. See the doc blocks for more information. - -`` -MachineInformationGatherer.MonitorCoreFrequencies(int coreNumber, CancellationToken token, int measurementDelay = 1000) : Task -`` - ## Goal The immediate goal is somewhat feature-parity with CPU-Z/CPUID.