mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-29 05:18:14 +00:00
Release version 0.1.12. Added error handling for PerformanceCounters (CPU load sensor).
This commit is contained in:
parent
5249183290
commit
de0c73471d
@ -80,19 +80,29 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
// max two cores
|
||||
coreCount = coreCount > 2 ? 2 : coreCount;
|
||||
|
||||
totalLoadCounter = new PerformanceCounter();
|
||||
totalLoadCounter.CategoryName = "Processor";
|
||||
totalLoadCounter.CounterName = "% Processor Time";
|
||||
totalLoadCounter.InstanceName = "_Total";
|
||||
try {
|
||||
totalLoadCounter = new PerformanceCounter();
|
||||
totalLoadCounter.CategoryName = "Processor";
|
||||
totalLoadCounter.CounterName = "% Processor Time";
|
||||
totalLoadCounter.InstanceName = "_Total";
|
||||
totalLoadCounter.NextValue();
|
||||
} catch (Exception) {
|
||||
totalLoadCounter = null;
|
||||
}
|
||||
totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);
|
||||
|
||||
coreLoadCounters = new PerformanceCounter[coreCount];
|
||||
coreLoads = new Sensor[coreCount];
|
||||
for (int i = 0; i < coreLoadCounters.Length; i++) {
|
||||
coreLoadCounters[i] = new PerformanceCounter();
|
||||
coreLoadCounters[i].CategoryName = "Processor";
|
||||
coreLoadCounters[i].CounterName = "% Processor Time";
|
||||
coreLoadCounters[i].InstanceName = i.ToString();
|
||||
try {
|
||||
coreLoadCounters[i] = new PerformanceCounter();
|
||||
coreLoadCounters[i].CategoryName = "Processor";
|
||||
coreLoadCounters[i].CounterName = "% Processor Time";
|
||||
coreLoadCounters[i].InstanceName = i.ToString();
|
||||
coreLoadCounters[i].NextValue();
|
||||
} catch (Exception) {
|
||||
coreLoadCounters[i] = null;
|
||||
}
|
||||
coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1,
|
||||
SensorType.Load, this);
|
||||
}
|
||||
@ -153,13 +163,16 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
}
|
||||
}
|
||||
|
||||
totalLoad.Value = totalLoadCounter.NextValue();
|
||||
ActivateSensor(totalLoad);
|
||||
|
||||
for (int i = 0; i < coreLoads.Length; i++) {
|
||||
coreLoads[i].Value = coreLoadCounters[i].NextValue();
|
||||
ActivateSensor(coreLoads[i]);
|
||||
if (totalLoadCounter != null) {
|
||||
totalLoad.Value = totalLoadCounter.NextValue();
|
||||
ActivateSensor(totalLoad);
|
||||
}
|
||||
|
||||
for (int i = 0; i < coreLoads.Length; i++)
|
||||
if (coreLoadCounters[i] != null) {
|
||||
coreLoads[i].Value = coreLoadCounters[i].NextValue();
|
||||
ActivateSensor(coreLoads[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void ActivateSensor(Sensor sensor) {
|
||||
|
@ -72,19 +72,29 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
if (cpuidExtData.GetLength(0) > 8)
|
||||
coreCount = (cpuidExtData[8, 2] & 0xFF) + 1;
|
||||
|
||||
totalLoadCounter = new PerformanceCounter();
|
||||
totalLoadCounter.CategoryName = "Processor";
|
||||
totalLoadCounter.CounterName = "% Processor Time";
|
||||
totalLoadCounter.InstanceName = "_Total";
|
||||
try {
|
||||
totalLoadCounter = new PerformanceCounter();
|
||||
totalLoadCounter.CategoryName = "Processor";
|
||||
totalLoadCounter.CounterName = "% Processor Time";
|
||||
totalLoadCounter.InstanceName = "_Total";
|
||||
totalLoadCounter.NextValue();
|
||||
} catch (Exception) {
|
||||
totalLoadCounter = null;
|
||||
}
|
||||
totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);
|
||||
|
||||
coreLoadCounters = new PerformanceCounter[coreCount];
|
||||
coreLoads = new Sensor[coreCount];
|
||||
for (int i = 0; i < coreLoadCounters.Length; i++) {
|
||||
coreLoadCounters[i] = new PerformanceCounter();
|
||||
coreLoadCounters[i].CategoryName = "Processor";
|
||||
coreLoadCounters[i].CounterName = "% Processor Time";
|
||||
coreLoadCounters[i].InstanceName = i.ToString();
|
||||
try {
|
||||
coreLoadCounters[i] = new PerformanceCounter();
|
||||
coreLoadCounters[i].CategoryName = "Processor";
|
||||
coreLoadCounters[i].CounterName = "% Processor Time";
|
||||
coreLoadCounters[i].InstanceName = i.ToString();
|
||||
coreLoadCounters[i].NextValue();
|
||||
} catch (Exception) {
|
||||
coreLoadCounters[i] = null;
|
||||
}
|
||||
coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1,
|
||||
SensorType.Load, this);
|
||||
}
|
||||
@ -132,13 +142,16 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
DeactivateSensor(coreTemperature);
|
||||
}
|
||||
|
||||
totalLoad.Value = totalLoadCounter.NextValue();
|
||||
ActivateSensor(totalLoad);
|
||||
|
||||
for (int i = 0; i < coreLoads.Length; i++) {
|
||||
coreLoads[i].Value = coreLoadCounters[i].NextValue();
|
||||
ActivateSensor(coreLoads[i]);
|
||||
if (totalLoadCounter != null) {
|
||||
totalLoad.Value = totalLoadCounter.NextValue();
|
||||
ActivateSensor(totalLoad);
|
||||
}
|
||||
|
||||
for (int i = 0; i < coreLoads.Length; i++)
|
||||
if (coreLoadCounters[i] != null) {
|
||||
coreLoads[i].Value = coreLoadCounters[i].NextValue();
|
||||
ActivateSensor(coreLoads[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void ActivateSensor(Sensor sensor) {
|
||||
|
@ -133,19 +133,29 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
default: tjMax = 100; break;
|
||||
}
|
||||
|
||||
totalLoadCounter = new PerformanceCounter();
|
||||
totalLoadCounter.CategoryName = "Processor";
|
||||
totalLoadCounter.CounterName = "% Processor Time";
|
||||
totalLoadCounter.InstanceName = "_Total";
|
||||
try {
|
||||
totalLoadCounter = new PerformanceCounter();
|
||||
totalLoadCounter.CategoryName = "Processor";
|
||||
totalLoadCounter.CounterName = "% Processor Time";
|
||||
totalLoadCounter.InstanceName = "_Total";
|
||||
totalLoadCounter.NextValue();
|
||||
} catch (Exception) {
|
||||
totalLoadCounter = null;
|
||||
}
|
||||
totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);
|
||||
|
||||
coreLoadCounters = new PerformanceCounter[
|
||||
coreCount * logicalProcessorsPerCore];
|
||||
for (int i = 0; i < coreLoadCounters.Length; i++) {
|
||||
coreLoadCounters[i] = new PerformanceCounter();
|
||||
coreLoadCounters[i].CategoryName = "Processor";
|
||||
coreLoadCounters[i].CounterName = "% Processor Time";
|
||||
coreLoadCounters[i].InstanceName = i.ToString();
|
||||
try {
|
||||
coreLoadCounters[i] = new PerformanceCounter();
|
||||
coreLoadCounters[i].CategoryName = "Processor";
|
||||
coreLoadCounters[i].CounterName = "% Processor Time";
|
||||
coreLoadCounters[i].InstanceName = i.ToString();
|
||||
coreLoadCounters[i].NextValue();
|
||||
} catch (Exception) {
|
||||
coreLoadCounters[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
coreTemperatures = new Sensor[coreCount];
|
||||
@ -211,17 +221,27 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
}
|
||||
}
|
||||
|
||||
totalLoad.Value = totalLoadCounter.NextValue();
|
||||
ActivateSensor(totalLoad);
|
||||
if (totalLoadCounter != null) {
|
||||
totalLoad.Value = totalLoadCounter.NextValue();
|
||||
ActivateSensor(totalLoad);
|
||||
}
|
||||
|
||||
for (int i = 0; i < coreLoads.Length; i++) {
|
||||
float value = 0;
|
||||
for (int j = 0; j < logicalProcessorsPerCore; j++)
|
||||
value += coreLoadCounters[
|
||||
logicalProcessorsPerCore * i + j].NextValue();
|
||||
value /= logicalProcessorsPerCore;
|
||||
coreLoads[i].Value = value;
|
||||
ActivateSensor(coreLoads[i]);
|
||||
int count = 0;
|
||||
for (int j = 0; j < logicalProcessorsPerCore; j++) {
|
||||
PerformanceCounter counter =
|
||||
coreLoadCounters[logicalProcessorsPerCore * i + j];
|
||||
if (counter != null) {
|
||||
value += counter.NextValue();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
value /= count;
|
||||
coreLoads[i].Value = value;
|
||||
ActivateSensor(coreLoads[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,5 +69,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.1.11.0")]
|
||||
[assembly: AssemblyFileVersion("0.1.11.0")]
|
||||
[assembly: AssemblyVersion("0.1.12.0")]
|
||||
[assembly: AssemblyFileVersion("0.1.12.0")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user