added periodic recreation of the LHM objects, to prevent memory leaks
This commit is contained in:
@@ -10,7 +10,7 @@ public class Telemetry : IDisposable
|
||||
public int UpdateRateMs => UpdateRateDefaultMs;
|
||||
|
||||
private readonly UdpSender udp = new UdpSender();
|
||||
private readonly Computer computer = new Computer();
|
||||
private Computer computer = new Computer();
|
||||
|
||||
private IHardware? cpuHw;
|
||||
private IHardware? gpuHw;
|
||||
@@ -29,25 +29,70 @@ public class Telemetry : IDisposable
|
||||
|
||||
private static readonly CultureInfo CI = CultureInfo.InvariantCulture;
|
||||
|
||||
// Restart LHM every 30 minutes
|
||||
private readonly TimeSpan restartInterval = TimeSpan.FromMinutes(30);
|
||||
private DateTime lastRestart = DateTime.UtcNow;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
ConfigureComputer();
|
||||
computer.Open();
|
||||
CacheHardwareAndSensors();
|
||||
}
|
||||
|
||||
private void ConfigureComputer()
|
||||
{
|
||||
computer.IsCpuEnabled = true;
|
||||
computer.IsGpuEnabled = true;
|
||||
computer.IsMemoryEnabled = true;
|
||||
// Disable everything else (true minimal mode)
|
||||
computer.IsMotherboardEnabled = false;
|
||||
computer.IsControllerEnabled = false;
|
||||
computer.IsNetworkEnabled = false;
|
||||
computer.IsStorageEnabled = false;
|
||||
computer.IsBatteryEnabled = false;
|
||||
|
||||
// True minimal mode
|
||||
computer.IsMotherboardEnabled = false;
|
||||
computer.IsControllerEnabled = false;
|
||||
computer.IsNetworkEnabled = false;
|
||||
computer.IsStorageEnabled = false;
|
||||
computer.IsBatteryEnabled = false;
|
||||
}
|
||||
|
||||
private void RestartComputerIfNeeded()
|
||||
{
|
||||
if (DateTime.UtcNow - lastRestart < restartInterval)
|
||||
return;
|
||||
|
||||
lastRestart = DateTime.UtcNow;
|
||||
|
||||
try
|
||||
{
|
||||
computer.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
computer = new Computer();
|
||||
ConfigureComputer();
|
||||
computer.Open();
|
||||
CacheHardwareAndSensors();
|
||||
}
|
||||
|
||||
private void CacheHardwareAndSensors()
|
||||
{
|
||||
cpuHw = null;
|
||||
gpuHw = null;
|
||||
memHw = null;
|
||||
|
||||
cpuLoadSensors = Array.Empty<ISensor>();
|
||||
cpuTempSensor = null;
|
||||
|
||||
gpu3DLoadSensor = null;
|
||||
gpuTempSensor = null;
|
||||
gpuVramUsedSensor = null;
|
||||
gpuVramTotalSensor = null;
|
||||
|
||||
memUsedSensor = null;
|
||||
memAvailSensor = null;
|
||||
|
||||
foreach (var hw in computer.Hardware)
|
||||
{
|
||||
hw.Update();
|
||||
@@ -141,6 +186,8 @@ public class Telemetry : IDisposable
|
||||
|
||||
public void UpdateAndSend()
|
||||
{
|
||||
RestartComputerIfNeeded();
|
||||
|
||||
cpuHw?.Update();
|
||||
gpuHw?.Update();
|
||||
memHw?.Update();
|
||||
|
||||
Reference in New Issue
Block a user