Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added internet usage meter and hardware monitor logging #1963

Merged
merged 5 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Project-Aurora/Project-Aurora/LibreHardwareMonitorLib.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions Project-Aurora/Project-Aurora/Profiles/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ private MMDevice DefaultAudioInDevice {
public GPUInfo GPU => _gpuInfo ?? (_gpuInfo = new GPUInfo());
#endregion

#region NET Properties
private static NETInfo _netInfo;
public NETInfo NET => _netInfo ?? (_netInfo = new NETInfo());
#endregion

/// <summary>
/// Returns whether or not the device dession is in a locked state.
/// </summary>
Expand Down Expand Up @@ -336,4 +341,9 @@ public class GPUInfo : Node<GPUInfo>
public float MemoryFree => MemoryTotal - MemoryUsed;
public float MemoryTotal => Utils.HardwareMonitor.GPU.GPUMemoryTotal;
}

public class NETInfo : Node<NETInfo>
{
public float Usage => Utils.HardwareMonitor.NET.BandwidthUsed;
}
}
5 changes: 5 additions & 0 deletions Project-Aurora/Project-Aurora/Settings/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ public class Configuration : Settings
public int idle_amount;
public float idle_frequency;

//Hardware Monitor
public int HardwareMonitorUpdateRate;

public VariableRegistry VarRegistry;

//BitmapDebug Data
Expand Down Expand Up @@ -559,6 +562,8 @@ public Configuration()
idle_amount = 5;
idle_frequency = 2.5f;

HardwareMonitorUpdateRate = 200;

//Debug
bitmapDebugTopMost = false;
httpDebugTopMost = false;
Expand Down
91 changes: 64 additions & 27 deletions Project-Aurora/Project-Aurora/Utils/HardwareMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ public static class HardwareMonitor
private static RAMUpdater _ram;
public static RAMUpdater RAM => _ram ?? (_ram = new RAMUpdater(_hardware));

private static NETUpdater _net;
public static NETUpdater NET => _net ?? (_net = new NETUpdater(_hardware));

#pragma warning disable CA1810 // Initialize reference type static fields inline
static HardwareMonitor()
#pragma warning restore CA1810 // Initialize reference type static fields inline
{
_computer = new Computer()
{
IsCpuEnabled = true,
IsGpuEnabled = true,
IsMemoryEnabled = true
IsMemoryEnabled = true,
IsNetworkEnabled = true
};
try
{
Expand All @@ -44,7 +50,13 @@ static HardwareMonitor()

private static ISensor FindSensor(this IHardware hardware, string identifier)
{
return Array.Find(hardware.Sensors, s => s.Identifier.ToString().Contains(identifier));
var result = Array.Find(hardware.Sensors, s => s.Identifier.ToString().Contains(identifier));
if (result is null)
{
Global.logger.Error(
$"[HardwareMonitor] Failed to find sensor \"{identifier}\" in {hardware.Name} of type {hardware.HardwareType}.");
}
return result;
}

public abstract class HardwareUpdater
Expand All @@ -65,7 +77,7 @@ protected HardwareUpdater()
};
_useTimer.Start();

_updateTimer = new Timer(200);
_updateTimer = new Timer(Global.Configuration.HardwareMonitorUpdateRate);
_updateTimer.Elapsed += (a, b) =>
{
if (inUse)
Expand All @@ -79,7 +91,7 @@ protected float GetValue(ISensor sensor)
inUse = true;
_useTimer.Stop();
_useTimer.Start();
return sensor.Value ?? 0;
return sensor?.Value ?? 0;
}

public void SetUpdateTimer(int interval)
Expand All @@ -90,7 +102,7 @@ public void SetUpdateTimer(int interval)
}
}

public class GPUUpdater : HardwareUpdater
public sealed class GPUUpdater : HardwareUpdater
{
#region Sensors
private readonly ISensor _GPUCoreTemp;
Expand Down Expand Up @@ -131,27 +143,29 @@ public GPUUpdater(IEnumerable<IHardware> hardware)
{
hw = hardware.FirstOrDefault(hw => hw.HardwareType == HardwareType.GpuAmd ||
hw.HardwareType == HardwareType.GpuNvidia);
if (hw != null)
if (hw is null)
{
_GPUCoreLoad = hw.FindSensor("load/0");
_GPUMemoryCLoad = hw.FindSensor("load/1");
_GPUVideoEngineLoad = hw.FindSensor("load/2");
Global.logger.Error("[HardwareMonitor] Could not find hardware of type GPU");
return;
}
_GPUCoreLoad = hw.FindSensor("load/0");
_GPUMemoryCLoad = hw.FindSensor("load/1");
_GPUVideoEngineLoad = hw.FindSensor("load/2");

_GPUCoreClock = hw.FindSensor("clock/0");
_GPUMemoryClock = hw.FindSensor("clock/1");
_GPUShaderClock = hw.FindSensor("clock/2");
_GPUCoreClock = hw.FindSensor("clock/0");
_GPUMemoryClock = hw.FindSensor("clock/1");
_GPUShaderClock = hw.FindSensor("clock/2");

_GPUCoreTemp = hw.FindSensor("temperature/0");
_GPUFan = hw.FindSensor("fan/0");
_GPUPower = hw.FindSensor("power/0");
_GPUCoreTemp = hw.FindSensor("temperature/0");
_GPUFan = hw.FindSensor("fan/0");
_GPUPower = hw.FindSensor("power/0");

_GPUMemoryTotal = hw.FindSensor("smalldata/3");
_GPUMemoryUsed = hw.FindSensor("smalldata/2");
}
_GPUMemoryTotal = hw.FindSensor("smalldata/3");
_GPUMemoryUsed = hw.FindSensor("smalldata/2");
}
}

public class CPUUpdater : HardwareUpdater
public sealed class CPUUpdater : HardwareUpdater
{
#region Sensors
private readonly ISensor _CPUDieTemp;
Expand All @@ -167,16 +181,18 @@ public class CPUUpdater : HardwareUpdater
public CPUUpdater(IEnumerable<IHardware> hardware)
{
hw = hardware.FirstOrDefault(hw => hw.HardwareType == HardwareType.Cpu);
if (hw != null)
if (hw is null)
{
_CPUDieTemp = hw.FindSensor("temperature/0");
_CPUTotalLoad = hw.FindSensor("load/0");
_CPUPower = hw.FindSensor("power/0");
Global.logger.Error("[HardwareMonitor] Could not find hardware of type CPU");
return;
}
_CPUDieTemp = hw.FindSensor("temperature/0");
_CPUTotalLoad = hw.FindSensor("load/0");
_CPUPower = hw.FindSensor("power/0");
}
}

public class RAMUpdater : HardwareUpdater
public sealed class RAMUpdater : HardwareUpdater
{
#region Sensors
private readonly ISensor _RAMUsed;
Expand All @@ -189,11 +205,32 @@ public class RAMUpdater : HardwareUpdater
public RAMUpdater(IEnumerable<IHardware> hws)
{
hw = hws.FirstOrDefault(h => h.HardwareType == HardwareType.Memory);
if (hw != null)
if (hw is null)
{
Global.logger.Error("[HardwareMonitor] Could not find hardware of type RAM");
return;
}
_RAMUsed = hw.FindSensor("data/0");
_RAMFree = hw.FindSensor("data/1");
}
}

public sealed class NETUpdater : HardwareUpdater
{
#region Sensors
private readonly ISensor _BandwidthUsed;
public float BandwidthUsed => GetValue(_BandwidthUsed);
#endregion

public NETUpdater(IEnumerable<IHardware> hws)
{
hw = hws.FirstOrDefault(h => h.HardwareType == HardwareType.Network);
if (hw is null)
{
_RAMUsed = hw.FindSensor("data/0");
_RAMFree = hw.FindSensor("data/1");
Global.logger.Error("[HardwareMonitor] Could not find hardware of type Network");
return;
}
_BandwidthUsed = hw.FindSensor("load");
}
}
}
Expand Down