mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
-
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using GHelper;
|
||||
using GHelper;
|
||||
using GHelper.Gpu;
|
||||
using NvAPIWrapper.GPU;
|
||||
using System.Diagnostics;
|
||||
|
||||
public static class HardwareMonitor
|
||||
{
|
||||
@@ -45,7 +44,7 @@ public static class HardwareMonitor
|
||||
if (Program.config.getConfig("fan_rpm") == 1)
|
||||
return " Fan: " + (fan * 100).ToString() + "RPM";
|
||||
else
|
||||
return " Fan: " + Math.Min(Math.Round((float)fan/fanMax*100), 100).ToString() + "%"; // relatively to 6000 rpm
|
||||
return " Fan: " + Math.Min(Math.Round((float)fan / fanMax * 100), 100).ToString() + "%"; // relatively to 6000 rpm
|
||||
}
|
||||
|
||||
private static int GetGpuUse()
|
||||
@@ -80,27 +79,29 @@ public static class HardwareMonitor
|
||||
var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true);
|
||||
cpuTemp = ct.NextValue() - 273;
|
||||
ct.Dispose();
|
||||
} catch
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logger.WriteLine("Failed reading CPU temp");
|
||||
Debug.WriteLine("Failed reading CPU temp");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature();
|
||||
gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature();
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
gpuTemp = -1;
|
||||
Logger.WriteLine("Failed reading GPU temp");
|
||||
Logger.WriteLine(ex.ToString());
|
||||
Debug.WriteLine("Failed reading GPU temp");
|
||||
Debug.WriteLine(ex.ToString());
|
||||
}
|
||||
|
||||
if (gpuTemp is null || gpuTemp < 0)
|
||||
gpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_GPU);
|
||||
|
||||
gpuUsage.Add(GetGpuUse());
|
||||
if (gpuUsage.Count > 3) gpuUsage.RemoveAt(0);
|
||||
if (gpuUsage.Count > 3) gpuUsage.RemoveAt(0);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -111,23 +112,25 @@ public static class HardwareMonitor
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logger.WriteLine("Failed reading Battery discharge");
|
||||
Debug.WriteLine("Failed reading Battery discharge");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsUsedGPU(int threshold = 50)
|
||||
{
|
||||
if (GetGpuUse() > threshold)
|
||||
if (GetGpuUse() > threshold)
|
||||
return true;
|
||||
else
|
||||
else
|
||||
return (gpuUsage.Average() > threshold);
|
||||
}
|
||||
|
||||
public static void RecreateGpuTemperatureProviderWithDelay() {
|
||||
public static void RecreateGpuTemperatureProviderWithDelay()
|
||||
{
|
||||
|
||||
// Re-enabling the discrete GPU takes a bit of time,
|
||||
// so a simple workaround is to refresh again after that happens
|
||||
Task.Run(async () => {
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
RecreateGpuTemperatureProvider();
|
||||
});
|
||||
@@ -136,7 +139,8 @@ public static class HardwareMonitor
|
||||
|
||||
}
|
||||
|
||||
public static void RecreateGpuTemperatureProvider() {
|
||||
public static void RecreateGpuTemperatureProvider()
|
||||
{
|
||||
try
|
||||
{
|
||||
GpuTemperatureProvider?.Dispose();
|
||||
@@ -163,8 +167,8 @@ public static class HardwareMonitor
|
||||
GpuTemperatureProvider = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
{
|
||||
Debug.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user