Release version 0.1.12. Added error handling for PerformanceCounters (CPU load sensor).
1.1 --- a/Hardware/CPU/AMD0FCPU.cs Wed Feb 03 20:35:10 2010 +0000
1.2 +++ b/Hardware/CPU/AMD0FCPU.cs Wed Feb 03 22:02:58 2010 +0000
1.3 @@ -80,19 +80,29 @@
1.4 // max two cores
1.5 coreCount = coreCount > 2 ? 2 : coreCount;
1.6
1.7 - totalLoadCounter = new PerformanceCounter();
1.8 - totalLoadCounter.CategoryName = "Processor";
1.9 - totalLoadCounter.CounterName = "% Processor Time";
1.10 - totalLoadCounter.InstanceName = "_Total";
1.11 + try {
1.12 + totalLoadCounter = new PerformanceCounter();
1.13 + totalLoadCounter.CategoryName = "Processor";
1.14 + totalLoadCounter.CounterName = "% Processor Time";
1.15 + totalLoadCounter.InstanceName = "_Total";
1.16 + totalLoadCounter.NextValue();
1.17 + } catch (Exception) {
1.18 + totalLoadCounter = null;
1.19 + }
1.20 totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);
1.21
1.22 coreLoadCounters = new PerformanceCounter[coreCount];
1.23 coreLoads = new Sensor[coreCount];
1.24 for (int i = 0; i < coreLoadCounters.Length; i++) {
1.25 - coreLoadCounters[i] = new PerformanceCounter();
1.26 - coreLoadCounters[i].CategoryName = "Processor";
1.27 - coreLoadCounters[i].CounterName = "% Processor Time";
1.28 - coreLoadCounters[i].InstanceName = i.ToString();
1.29 + try {
1.30 + coreLoadCounters[i] = new PerformanceCounter();
1.31 + coreLoadCounters[i].CategoryName = "Processor";
1.32 + coreLoadCounters[i].CounterName = "% Processor Time";
1.33 + coreLoadCounters[i].InstanceName = i.ToString();
1.34 + coreLoadCounters[i].NextValue();
1.35 + } catch (Exception) {
1.36 + coreLoadCounters[i] = null;
1.37 + }
1.38 coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1,
1.39 SensorType.Load, this);
1.40 }
1.41 @@ -153,13 +163,16 @@
1.42 }
1.43 }
1.44
1.45 - totalLoad.Value = totalLoadCounter.NextValue();
1.46 - ActivateSensor(totalLoad);
1.47 + if (totalLoadCounter != null) {
1.48 + totalLoad.Value = totalLoadCounter.NextValue();
1.49 + ActivateSensor(totalLoad);
1.50 + }
1.51
1.52 - for (int i = 0; i < coreLoads.Length; i++) {
1.53 - coreLoads[i].Value = coreLoadCounters[i].NextValue();
1.54 - ActivateSensor(coreLoads[i]);
1.55 - }
1.56 + for (int i = 0; i < coreLoads.Length; i++)
1.57 + if (coreLoadCounters[i] != null) {
1.58 + coreLoads[i].Value = coreLoadCounters[i].NextValue();
1.59 + ActivateSensor(coreLoads[i]);
1.60 + }
1.61 }
1.62
1.63 private void ActivateSensor(Sensor sensor) {
2.1 --- a/Hardware/CPU/AMD10CPU.cs Wed Feb 03 20:35:10 2010 +0000
2.2 +++ b/Hardware/CPU/AMD10CPU.cs Wed Feb 03 22:02:58 2010 +0000
2.3 @@ -72,19 +72,29 @@
2.4 if (cpuidExtData.GetLength(0) > 8)
2.5 coreCount = (cpuidExtData[8, 2] & 0xFF) + 1;
2.6
2.7 - totalLoadCounter = new PerformanceCounter();
2.8 - totalLoadCounter.CategoryName = "Processor";
2.9 - totalLoadCounter.CounterName = "% Processor Time";
2.10 - totalLoadCounter.InstanceName = "_Total";
2.11 + try {
2.12 + totalLoadCounter = new PerformanceCounter();
2.13 + totalLoadCounter.CategoryName = "Processor";
2.14 + totalLoadCounter.CounterName = "% Processor Time";
2.15 + totalLoadCounter.InstanceName = "_Total";
2.16 + totalLoadCounter.NextValue();
2.17 + } catch (Exception) {
2.18 + totalLoadCounter = null;
2.19 + }
2.20 totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);
2.21
2.22 coreLoadCounters = new PerformanceCounter[coreCount];
2.23 coreLoads = new Sensor[coreCount];
2.24 for (int i = 0; i < coreLoadCounters.Length; i++) {
2.25 - coreLoadCounters[i] = new PerformanceCounter();
2.26 - coreLoadCounters[i].CategoryName = "Processor";
2.27 - coreLoadCounters[i].CounterName = "% Processor Time";
2.28 - coreLoadCounters[i].InstanceName = i.ToString();
2.29 + try {
2.30 + coreLoadCounters[i] = new PerformanceCounter();
2.31 + coreLoadCounters[i].CategoryName = "Processor";
2.32 + coreLoadCounters[i].CounterName = "% Processor Time";
2.33 + coreLoadCounters[i].InstanceName = i.ToString();
2.34 + coreLoadCounters[i].NextValue();
2.35 + } catch (Exception) {
2.36 + coreLoadCounters[i] = null;
2.37 + }
2.38 coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1,
2.39 SensorType.Load, this);
2.40 }
2.41 @@ -132,13 +142,16 @@
2.42 DeactivateSensor(coreTemperature);
2.43 }
2.44
2.45 - totalLoad.Value = totalLoadCounter.NextValue();
2.46 - ActivateSensor(totalLoad);
2.47 + if (totalLoadCounter != null) {
2.48 + totalLoad.Value = totalLoadCounter.NextValue();
2.49 + ActivateSensor(totalLoad);
2.50 + }
2.51
2.52 - for (int i = 0; i < coreLoads.Length; i++) {
2.53 - coreLoads[i].Value = coreLoadCounters[i].NextValue();
2.54 - ActivateSensor(coreLoads[i]);
2.55 - }
2.56 + for (int i = 0; i < coreLoads.Length; i++)
2.57 + if (coreLoadCounters[i] != null) {
2.58 + coreLoads[i].Value = coreLoadCounters[i].NextValue();
2.59 + ActivateSensor(coreLoads[i]);
2.60 + }
2.61 }
2.62
2.63 private void ActivateSensor(Sensor sensor) {
3.1 --- a/Hardware/CPU/IntelCPU.cs Wed Feb 03 20:35:10 2010 +0000
3.2 +++ b/Hardware/CPU/IntelCPU.cs Wed Feb 03 22:02:58 2010 +0000
3.3 @@ -133,19 +133,29 @@
3.4 default: tjMax = 100; break;
3.5 }
3.6
3.7 - totalLoadCounter = new PerformanceCounter();
3.8 - totalLoadCounter.CategoryName = "Processor";
3.9 - totalLoadCounter.CounterName = "% Processor Time";
3.10 - totalLoadCounter.InstanceName = "_Total";
3.11 + try {
3.12 + totalLoadCounter = new PerformanceCounter();
3.13 + totalLoadCounter.CategoryName = "Processor";
3.14 + totalLoadCounter.CounterName = "% Processor Time";
3.15 + totalLoadCounter.InstanceName = "_Total";
3.16 + totalLoadCounter.NextValue();
3.17 + } catch (Exception) {
3.18 + totalLoadCounter = null;
3.19 + }
3.20 totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);
3.21
3.22 coreLoadCounters = new PerformanceCounter[
3.23 coreCount * logicalProcessorsPerCore];
3.24 for (int i = 0; i < coreLoadCounters.Length; i++) {
3.25 - coreLoadCounters[i] = new PerformanceCounter();
3.26 - coreLoadCounters[i].CategoryName = "Processor";
3.27 - coreLoadCounters[i].CounterName = "% Processor Time";
3.28 - coreLoadCounters[i].InstanceName = i.ToString();
3.29 + try {
3.30 + coreLoadCounters[i] = new PerformanceCounter();
3.31 + coreLoadCounters[i].CategoryName = "Processor";
3.32 + coreLoadCounters[i].CounterName = "% Processor Time";
3.33 + coreLoadCounters[i].InstanceName = i.ToString();
3.34 + coreLoadCounters[i].NextValue();
3.35 + } catch (Exception) {
3.36 + coreLoadCounters[i] = null;
3.37 + }
3.38 }
3.39
3.40 coreTemperatures = new Sensor[coreCount];
3.41 @@ -211,17 +221,27 @@
3.42 }
3.43 }
3.44
3.45 - totalLoad.Value = totalLoadCounter.NextValue();
3.46 - ActivateSensor(totalLoad);
3.47 + if (totalLoadCounter != null) {
3.48 + totalLoad.Value = totalLoadCounter.NextValue();
3.49 + ActivateSensor(totalLoad);
3.50 + }
3.51
3.52 for (int i = 0; i < coreLoads.Length; i++) {
3.53 float value = 0;
3.54 - for (int j = 0; j < logicalProcessorsPerCore; j++)
3.55 - value += coreLoadCounters[
3.56 - logicalProcessorsPerCore * i + j].NextValue();
3.57 - value /= logicalProcessorsPerCore;
3.58 - coreLoads[i].Value = value;
3.59 - ActivateSensor(coreLoads[i]);
3.60 + int count = 0;
3.61 + for (int j = 0; j < logicalProcessorsPerCore; j++) {
3.62 + PerformanceCounter counter =
3.63 + coreLoadCounters[logicalProcessorsPerCore * i + j];
3.64 + if (counter != null) {
3.65 + value += counter.NextValue();
3.66 + count++;
3.67 + }
3.68 + }
3.69 + if (count > 0) {
3.70 + value /= count;
3.71 + coreLoads[i].Value = value;
3.72 + ActivateSensor(coreLoads[i]);
3.73 + }
3.74 }
3.75 }
3.76
4.1 --- a/Properties/AssemblyInfo.cs Wed Feb 03 20:35:10 2010 +0000
4.2 +++ b/Properties/AssemblyInfo.cs Wed Feb 03 22:02:58 2010 +0000
4.3 @@ -69,5 +69,5 @@
4.4 // You can specify all the values or you can default the Build and Revision Numbers
4.5 // by using the '*' as shown below:
4.6 // [assembly: AssemblyVersion("1.0.*")]
4.7 -[assembly: AssemblyVersion("0.1.11.0")]
4.8 -[assembly: AssemblyFileVersion("0.1.11.0")]
4.9 +[assembly: AssemblyVersion("0.1.12.0")]
4.10 +[assembly: AssemblyFileVersion("0.1.12.0")]