Skip to content

Commit

Permalink
Calculate VRAM load from GPU memory used / total
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcadeRenegade committed Dec 23, 2021
1 parent dfd5542 commit 6ced8f7
Showing 1 changed file with 71 additions and 5 deletions.
76 changes: 71 additions & 5 deletions SidebarDiagnostics/Monitoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ public void InitRAM(IHardware board, MetricConfig[] metrics, bool roundAll)

public void InitGPU(MetricConfig[] metrics, bool roundAll, bool useGHz, bool useFahrenheit, double tempAlert)
{
List<OHMMetric> _sensorList = new List<OHMMetric>();
List<iMetric> _sensorList = new List<iMetric>();

if (metrics.IsEnabled(MetricKey.GPUCoreClock))
{
Expand Down Expand Up @@ -809,12 +809,22 @@ public void InitGPU(MetricConfig[] metrics, bool roundAll, bool useGHz, bool use

if (metrics.IsEnabled(MetricKey.GPUVRAMLoad))
{
ISensor _vramLoad = _hardware.Sensors.Where(s => s.SensorType == SensorType.Load && s.Name.Contains("Memory")).FirstOrDefault() ??
_hardware.Sensors.Where(s => s.SensorType == SensorType.Load && s.Index == 3).FirstOrDefault();
ISensor _memoryUsed = _hardware.Sensors.Where(s => (s.SensorType == SensorType.Data || s.SensorType == SensorType.SmallData) && s.Name == "GPU Memory Used").FirstOrDefault();
ISensor _memoryTotal = _hardware.Sensors.Where(s => (s.SensorType == SensorType.Data || s.SensorType == SensorType.SmallData) && s.Name == "GPU Memory Total").FirstOrDefault();

if (_vramLoad != null)
if (_memoryUsed != null && _memoryTotal != null)
{
_sensorList.Add(new GPUVRAMMLoadMetric(_memoryUsed, _memoryTotal, MetricKey.GPUVRAMLoad, DataType.Percent, null, roundAll));
}
else
{
_sensorList.Add(new OHMMetric(_vramLoad, MetricKey.GPUVRAMLoad, DataType.Percent, null, roundAll));
ISensor _vramLoad = _hardware.Sensors.Where(s => s.SensorType == SensorType.Load && s.Name.Contains("Memory")).FirstOrDefault() ??
_hardware.Sensors.Where(s => s.SensorType == SensorType.Load && s.Index == 1).FirstOrDefault();

if (_vramLoad != null)
{
_sensorList.Add(new OHMMetric(_vramLoad, MetricKey.GPUVRAMLoad, DataType.Percent, null, roundAll));
}
}
}

Expand Down Expand Up @@ -1706,6 +1716,62 @@ public override void Update()
private bool _disposed { get; set; } = false;
}

public class GPUVRAMMLoadMetric : BaseMetric
{
public GPUVRAMMLoadMetric(ISensor memoryUsedSensor, ISensor memoryTotalSensor, MetricKey key, DataType dataType, string label = null, bool round = false, double alertValue = 0, iConverter converter = null) : base(key, dataType, label, round, alertValue, converter)
{
_memoryUsedSensor = memoryUsedSensor;
_memoryTotalSensor = memoryTotalSensor;
}

public new void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (!_disposed)
{
if (disposing)
{
_memoryUsedSensor = null;
_memoryTotalSensor = null;
}

_disposed = true;
}
}

~GPUVRAMMLoadMetric()
{
Dispose(false);
}

public override void Update()
{
if (_memoryUsedSensor.Value.HasValue && _memoryTotalSensor.Value.HasValue)
{
float load = _memoryUsedSensor.Value.Value / _memoryTotalSensor.Value.Value * 100f;

Update(load);
}
else
{
Text = "No Value";
}
}

private ISensor _memoryUsedSensor { get; set; }

private ISensor _memoryTotalSensor { get; set; }

private bool _disposed { get; set; } = false;
}

public class IPMetric : BaseMetric
{
public IPMetric(string ipAddress, MetricKey key, DataType dataType, string label = null, bool round = false, double alertValue = 0, iConverter converter = null) : base(key, dataType, label, round, alertValue, converter)
Expand Down

0 comments on commit 6ced8f7

Please sign in to comment.