Skip to content

Commit ce6cbfe

Browse files
committed
fixup! memory sensors
1 parent 026fa38 commit ce6cbfe

6 files changed

Lines changed: 47 additions & 13 deletions

File tree

OpenHardwareMonitorLib/Hardware/Cpu/GenericCpu.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public GenericCpu(int processorIndex, CpuId[][] cpuId, ISettings settings) : bas
5050
// Check if processor supports an invariant TSC.
5151
_isInvariantTimeStampCounter = cpuId[0][0].ExtData.GetLength(0) > 7 && (cpuId[0][0].ExtData[7, 3] & 0x100) != 0;
5252

53-
_totalLoad = _coreCount > 1 ? new Sensor("CPU Total", 0, SensorType.Load, this, settings) : null;
54-
_maxLoad = _coreCount > 1 ? new Sensor("CPU Core Max", 1, SensorType.Load, this, settings) : null;
53+
_totalLoad = _coreCount > 1 ? new Sensor("Total", 0, SensorType.Load, this, settings) : null;
54+
_maxLoad = _coreCount > 1 ? new Sensor("Core Max", 1, SensorType.Load, this, settings) : null;
5555

5656
_cpuLoad = new CpuLoad(cpuId);
5757
if (_cpuLoad.IsAvailable)
@@ -119,9 +119,9 @@ public GenericCpu(int processorIndex, CpuId[][] cpuId, ISettings settings) : bas
119119
protected string CoreString(int i)
120120
{
121121
if (_coreCount == 1)
122-
return "CPU Core";
122+
return "Core";
123123

124-
return "CPU Core #" + (i + 1);
124+
return "Core #" + (i + 1);
125125
}
126126

127127
private static Identifier CreateIdentifier(Vendor vendor, int processorIndex)

OpenHardwareMonitorLib/Hardware/Memory/MemoryGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static MemoryGroup()
3535

3636
public MemoryGroup(ISettings settings)
3737
{
38-
_hardware.Add(new VirtualMemory(settings));
3938
_hardware.Add(new TotalMemory(settings));
39+
_hardware.Add(new VirtualMemory(settings));
4040

4141
//No RAM detected
4242
if (!DetectThermalSensors(out List<SPDAccessor> accessors))

OpenHardwareMonitorLib/Hardware/Memory/MemoryLinux.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ public static void Update(TotalMemory memory)
1919
float usedMemoryGb = totalMemoryGb - freeMemoryGb - cachedMemoryGb;
2020

2121
memory.PhysicalMemoryUsed.Value = usedMemoryGb;
22-
memory.PhysicalMemoryAvailable.Value = totalMemoryGb;
22+
memory.PhysicalMemoryTotal.Value = totalMemoryGb;
23+
memory.PhysicalMemoryAvailable.Value = freeMemoryGb;
2324
memory.PhysicalMemoryLoad.Value = 100.0f * (usedMemoryGb / totalMemoryGb);
2425
}
2526
}
2627
catch
2728
{
2829
memory.PhysicalMemoryUsed.Value = null;
30+
memory.PhysicalMemoryTotal.Value = null;
2931
memory.PhysicalMemoryAvailable.Value = null;
3032
memory.PhysicalMemoryLoad.Value = null;
3133
}
@@ -43,13 +45,15 @@ public static void Update(VirtualMemory memory)
4345
float usedSwapMemoryGb = totalSwapMemoryGb - freeSwapMemoryGb;
4446

4547
memory.VirtualMemoryUsed.Value = usedSwapMemoryGb;
46-
memory.VirtualMemoryAvailable.Value = totalSwapMemoryGb;
48+
memory.VirtualMemoryTotal.Value = totalSwapMemoryGb;
49+
memory.VirtualMemoryAvailable.Value = freeSwapMemoryGb;
4750
memory.VirtualMemoryLoad.Value = 100.0f * (usedSwapMemoryGb / totalSwapMemoryGb);
4851
}
4952
}
5053
catch
5154
{
5255
memory.VirtualMemoryUsed.Value = null;
56+
memory.VirtualMemoryTotal.Value = null;
5357
memory.VirtualMemoryAvailable.Value = null;
5458
memory.VirtualMemoryLoad.Value = null;
5559
}

OpenHardwareMonitorLib/Hardware/Memory/MemoryWindows.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static void Update(TotalMemory memory)
1212
if (!Kernel32.GlobalMemoryStatusEx(ref status))
1313
return;
1414

15+
memory.PhysicalMemoryTotal.Value = (float)status.ullTotalPhys / (1024 * 1024 * 1024);
1516
memory.PhysicalMemoryUsed.Value = (float)(status.ullTotalPhys - status.ullAvailPhys) / (1024 * 1024 * 1024);
1617
memory.PhysicalMemoryAvailable.Value = (float)status.ullAvailPhys / (1024 * 1024 * 1024);
1718
memory.PhysicalMemoryLoad.Value = 100.0f - ((100.0f * status.ullAvailPhys) / status.ullTotalPhys);
@@ -27,5 +28,17 @@ public static void Update(VirtualMemory memory)
2728
memory.VirtualMemoryUsed.Value = (float)(status.ullTotalPageFile - status.ullAvailPageFile) / (1024 * 1024 * 1024);
2829
memory.VirtualMemoryAvailable.Value = (float)status.ullAvailPageFile / (1024 * 1024 * 1024);
2930
memory.VirtualMemoryLoad.Value = 100.0f - ((100.0f * status.ullAvailPageFile) / status.ullTotalPageFile);
31+
32+
Kernel32.PERFORMANCE_INFORMATION performanceInfo = new() { cb = (uint)Marshal.SizeOf<Kernel32.PERFORMANCE_INFORMATION>() };
33+
if (Kernel32.GetPerformanceInfo(ref performanceInfo, performanceInfo.cb))
34+
{
35+
memory.VirtualMemoryTotal.Value = (float)performanceInfo.CommitLimit * performanceInfo.PageSize / (1024 * 1024 * 1024);
36+
//_virtualMemoryUsed.Value = (float)performanceInfo.CommitTotal * performanceInfo.PageSize / (1024 * 1024 * 1024);
37+
memory.KernelSize.Value = (float)performanceInfo.KernelNonpaged * performanceInfo.PageSize / (1024 * 1024 * 1024);
38+
memory.ProcessCount.Value = performanceInfo.ProcessCount;
39+
memory.ThreadCount.Value = performanceInfo.ThreadCount;
40+
memory.HandleCount.Value = performanceInfo.HandleCount;
41+
}
42+
3043
}
3144
}

OpenHardwareMonitorLib/Hardware/Memory/TotalMemory.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
internal sealed class TotalMemory : Hardware
44
{
55
public TotalMemory(ISettings settings)
6-
: base("Total Memory", new Identifier("ram"), settings)
6+
: base("Physical Memory", new Identifier("pram"), settings)
77
{
8-
PhysicalMemoryUsed = new Sensor("Memory Used", 0, SensorType.Data, this, settings);
8+
PhysicalMemoryUsed = new Sensor("Used", 0, SensorType.Data, this, settings);
99
ActivateSensor(PhysicalMemoryUsed);
1010

11-
PhysicalMemoryAvailable = new Sensor("Memory Available", 1, SensorType.Data, this, settings);
11+
PhysicalMemoryAvailable = new Sensor("Available", 1, SensorType.Data, this, settings);
1212
ActivateSensor(PhysicalMemoryAvailable);
1313

14+
ActivateSensor(PhysicalMemoryTotal = new Sensor("Total", 2, SensorType.Data, this, settings));
15+
1416
PhysicalMemoryLoad = new Sensor("Memory", 0, SensorType.Load, this, settings);
1517
ActivateSensor(PhysicalMemoryLoad);
1618
}
1719

1820
public override HardwareType HardwareType => HardwareType.Memory;
1921

22+
internal Sensor PhysicalMemoryTotal { get; }
23+
2024
internal Sensor PhysicalMemoryAvailable { get; }
2125

2226
internal Sensor PhysicalMemoryLoad { get; }

OpenHardwareMonitorLib/Hardware/Memory/VirtualMemory.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@
33
internal sealed class VirtualMemory : Hardware
44
{
55
public VirtualMemory(ISettings settings)
6-
: base("Virtual Memory", new Identifier("ram"), settings)
6+
: base("Virtual Memory", new Identifier("vram"), settings)
77
{
8-
VirtualMemoryUsed = new Sensor("Memory Used", 2, SensorType.Data, this, settings);
8+
VirtualMemoryUsed = new Sensor("Used", 2, SensorType.Data, this, settings);
99
ActivateSensor(VirtualMemoryUsed);
1010

11-
VirtualMemoryAvailable = new Sensor("Memory Available", 3, SensorType.Data, this, settings);
11+
VirtualMemoryAvailable = new Sensor("Available", 3, SensorType.Data, this, settings);
1212
ActivateSensor(VirtualMemoryAvailable);
1313

1414
VirtualMemoryLoad = new Sensor("Memory", 1, SensorType.Load, this, settings);
1515
ActivateSensor(VirtualMemoryLoad);
16+
17+
18+
ActivateSensor(VirtualMemoryTotal = new Sensor("Total", 4, SensorType.Data, this, settings));
19+
ActivateSensor(KernelSize = new Sensor("Kernel usage", 5, SensorType.Data, this, settings));
20+
ActivateSensor(ProcessCount = new Sensor("Processes", 0, SensorType.IntFactor, this, settings));
21+
ActivateSensor(ThreadCount = new Sensor("Threads", 1, SensorType.IntFactor, this, settings));
22+
ActivateSensor(HandleCount = new Sensor("Handles", 2, SensorType.IntFactor, this, settings));
1623
}
1724

1825
public override HardwareType HardwareType => HardwareType.Memory;
@@ -23,6 +30,12 @@ public VirtualMemory(ISettings settings)
2330

2431
internal Sensor VirtualMemoryUsed { get; }
2532

33+
internal readonly Sensor VirtualMemoryTotal;
34+
internal readonly Sensor KernelSize;
35+
internal readonly Sensor ProcessCount;
36+
internal readonly Sensor ThreadCount;
37+
internal readonly Sensor HandleCount;
38+
2639
public override void Update()
2740
{
2841
if (OperatingSystemHelper.IsUnix)

0 commit comments

Comments
 (0)