@@ -5,52 +5,68 @@ namespace OpenHardwareMonitor.Hardware.Memory;
55
66internal sealed class GenericWindowsMemory : Hardware
77{
8+ private readonly Sensor _totalPhysicalMemory ;
89 private readonly Sensor _physicalMemoryAvailable ;
910 private readonly Sensor _physicalMemoryLoad ;
1011 private readonly Sensor _physicalMemoryUsed ;
1112 private readonly Sensor _virtualMemoryAvailable ;
1213 private readonly Sensor _virtualMemoryLoad ;
1314 private readonly Sensor _virtualMemoryUsed ;
1415
16+ private readonly Sensor _commitLimit ;
17+ private readonly Sensor _currentCommit ;
18+ private readonly Sensor _kernelSize ;
19+ private readonly Sensor _processCount ;
20+ private readonly Sensor _threadCount ;
21+ private readonly Sensor _handleCount ;
22+
1523 public GenericWindowsMemory ( string name , ISettings settings ) : base ( name , new Identifier ( "ram" ) , settings )
1624 {
17- _physicalMemoryUsed = new Sensor ( "Memory Used" , 0 , SensorType . Data , this , settings ) ;
18- ActivateSensor ( _physicalMemoryUsed ) ;
19-
20- _physicalMemoryAvailable = new Sensor ( "Memory Available" , 1 , SensorType . Data , this , settings ) ;
21- ActivateSensor ( _physicalMemoryAvailable ) ;
22-
23- _physicalMemoryLoad = new Sensor ( "Memory" , 0 , SensorType . Load , this , settings ) ;
24- ActivateSensor ( _physicalMemoryLoad ) ;
25+ ActivateSensor ( _physicalMemoryLoad = new Sensor ( "Memory" , 0 , SensorType . Load , this , settings ) ) ;
26+ ActivateSensor ( _virtualMemoryLoad = new Sensor ( "Virtual Memory" , 1 , SensorType . Load , this , settings ) ) ;
2527
26- _virtualMemoryUsed = new Sensor ( "Virtual Memory Used" , 2 , SensorType . Data , this , settings ) ;
27- ActivateSensor ( _virtualMemoryUsed ) ;
28+ ActivateSensor ( _totalPhysicalMemory = new Sensor ( "Total Physical Memory" , 0 , SensorType . Data , this , settings ) ) ;
29+ ActivateSensor ( _physicalMemoryUsed = new Sensor ( "Memory Used" , 1 , SensorType . Data , this , settings ) ) ;
30+ ActivateSensor ( _physicalMemoryAvailable = new Sensor ( "Memory Available" , 2 , SensorType . Data , this , settings ) ) ;
31+ ActivateSensor ( _virtualMemoryUsed = new Sensor ( "Virtual Memory Used" , 3 , SensorType . Data , this , settings ) ) ;
32+ ActivateSensor ( _virtualMemoryAvailable = new Sensor ( "Virtual Memory Available" , 4 , SensorType . Data , this , settings ) ) ;
33+ ActivateSensor ( _commitLimit = new Sensor ( "Virtual memory commit limit" , 5 , SensorType . Data , this , settings ) ) ;
34+ ActivateSensor ( _currentCommit = new Sensor ( "Virtual memory in use" , 6 , SensorType . Data , this , settings ) ) ;
35+ ActivateSensor ( _kernelSize = new Sensor ( "Kernel memory usage" , 7 , SensorType . Data , this , settings ) ) ;
2836
29- _virtualMemoryAvailable = new Sensor ( "Virtual Memory Available" , 3 , SensorType . Data , this , settings ) ;
30- ActivateSensor ( _virtualMemoryAvailable ) ;
31-
32- _virtualMemoryLoad = new Sensor ( "Virtual Memory" , 1 , SensorType . Load , this , settings ) ;
33- ActivateSensor ( _virtualMemoryLoad ) ;
37+ ActivateSensor ( _processCount = new Sensor ( "Processes" , 0 , SensorType . IntFactor , this , settings ) ) ;
38+ ActivateSensor ( _threadCount = new Sensor ( "Threads" , 1 , SensorType . IntFactor , this , settings ) ) ;
39+ ActivateSensor ( _handleCount = new Sensor ( "Handles" , 2 , SensorType . IntFactor , this , settings ) ) ;
3440 }
3541
36- public override HardwareType HardwareType
37- {
38- get { return HardwareType . Memory ; }
39- }
42+ public override HardwareType HardwareType => HardwareType . Memory ;
4043
4144 public override void Update ( )
4245 {
4346 Kernel32 . MEMORYSTATUSEX status = new ( ) { dwLength = ( uint ) Marshal . SizeOf < Kernel32 . MEMORYSTATUSEX > ( ) } ;
47+ if ( Kernel32 . GlobalMemoryStatusEx ( ref status ) )
48+ {
49+ _totalPhysicalMemory . Value = ( float ) status . ullTotalPhys / ( 1024 * 1024 * 1024 ) ;
50+ _physicalMemoryUsed . Value = ( float ) ( status . ullTotalPhys - status . ullAvailPhys ) / ( 1024 * 1024 * 1024 ) ;
51+ _physicalMemoryAvailable . Value = ( float ) status . ullAvailPhys / ( 1024 * 1024 * 1024 ) ;
52+ _physicalMemoryLoad . Value = 100.0f - 100.0f * status . ullAvailPhys / status . ullTotalPhys ;
4453
45- if ( ! Kernel32 . GlobalMemoryStatusEx ( ref status ) )
46- return ;
54+ _virtualMemoryUsed . Value =
55+ ( float ) ( status . ullTotalPageFile - status . ullAvailPageFile ) / ( 1024 * 1024 * 1024 ) ;
56+ _virtualMemoryAvailable . Value = ( float ) status . ullAvailPageFile / ( 1024 * 1024 * 1024 ) ;
57+ _virtualMemoryLoad . Value = 100.0f - 100.0f * status . ullAvailPageFile / status . ullTotalPageFile ;
58+ }
4759
48- _physicalMemoryUsed . Value = ( float ) ( status . ullTotalPhys - status . ullAvailPhys ) / ( 1024 * 1024 * 1024 ) ;
49- _physicalMemoryAvailable . Value = ( float ) status . ullAvailPhys / ( 1024 * 1024 * 1024 ) ;
50- _physicalMemoryLoad . Value = 100.0f - ( ( 100.0f * status . ullAvailPhys ) / status . ullTotalPhys ) ;
60+ Kernel32 . PERFORMANCE_INFORMATION performanceInfo = new ( ) { cb = ( uint ) Marshal . SizeOf < Kernel32 . PERFORMANCE_INFORMATION > ( ) } ;
61+ if ( Kernel32 . GetPerformanceInfo ( ref performanceInfo , performanceInfo . cb ) )
62+ {
63+ _commitLimit . Value = ( float ) performanceInfo . CommitLimit * performanceInfo . PageSize / ( 1024 * 1024 * 1024 ) ;
64+ _currentCommit . Value = ( float ) performanceInfo . CommitTotal * performanceInfo . PageSize / ( 1024 * 1024 * 1024 ) ;
65+ _kernelSize . Value = ( float ) performanceInfo . KernelNonpaged * performanceInfo . PageSize / ( 1024 * 1024 * 1024 ) ;
5166
52- _virtualMemoryUsed . Value = ( float ) ( status . ullTotalPageFile - status . ullAvailPageFile ) / ( 1024 * 1024 * 1024 ) ;
53- _virtualMemoryAvailable . Value = ( float ) status . ullAvailPageFile / ( 1024 * 1024 * 1024 ) ;
54- _virtualMemoryLoad . Value = 100.0f - ( ( 100.0f * status . ullAvailPageFile ) / status . ullTotalPageFile ) ;
67+ _processCount . Value = performanceInfo . ProcessCount ;
68+ _threadCount . Value = performanceInfo . ThreadCount ;
69+ _handleCount . Value = performanceInfo . HandleCount ;
70+ }
5571 }
5672}
0 commit comments