# HG changeset patch # User moel.mich # Date 1265234578 0 # Node ID ff3e6edc71139b0f7ec7fe9f241b85ed60d10849 # Parent 09ab31bee6bd48fb0ff14ed6d33751493dc78750 Release version 0.1.12. Added error handling for PerformanceCounters (CPU load sensor). diff -r 09ab31bee6bd -r ff3e6edc7113 Hardware/CPU/AMD0FCPU.cs --- a/Hardware/CPU/AMD0FCPU.cs Wed Feb 03 20:35:10 2010 +0000 +++ b/Hardware/CPU/AMD0FCPU.cs Wed Feb 03 22:02:58 2010 +0000 @@ -80,19 +80,29 @@ // 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 @@ } } - totalLoad.Value = totalLoadCounter.NextValue(); - ActivateSensor(totalLoad); + if (totalLoadCounter != null) { + totalLoad.Value = totalLoadCounter.NextValue(); + ActivateSensor(totalLoad); + } - for (int i = 0; i < coreLoads.Length; i++) { - coreLoads[i].Value = coreLoadCounters[i].NextValue(); - ActivateSensor(coreLoads[i]); - } + 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) { diff -r 09ab31bee6bd -r ff3e6edc7113 Hardware/CPU/AMD10CPU.cs --- a/Hardware/CPU/AMD10CPU.cs Wed Feb 03 20:35:10 2010 +0000 +++ b/Hardware/CPU/AMD10CPU.cs Wed Feb 03 22:02:58 2010 +0000 @@ -72,19 +72,29 @@ 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 @@ DeactivateSensor(coreTemperature); } - totalLoad.Value = totalLoadCounter.NextValue(); - ActivateSensor(totalLoad); + if (totalLoadCounter != null) { + totalLoad.Value = totalLoadCounter.NextValue(); + ActivateSensor(totalLoad); + } - for (int i = 0; i < coreLoads.Length; i++) { - coreLoads[i].Value = coreLoadCounters[i].NextValue(); - ActivateSensor(coreLoads[i]); - } + 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) { diff -r 09ab31bee6bd -r ff3e6edc7113 Hardware/CPU/IntelCPU.cs --- a/Hardware/CPU/IntelCPU.cs Wed Feb 03 20:35:10 2010 +0000 +++ b/Hardware/CPU/IntelCPU.cs Wed Feb 03 22:02:58 2010 +0000 @@ -133,19 +133,29 @@ 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 @@ } } - 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]); + } } } diff -r 09ab31bee6bd -r ff3e6edc7113 Properties/AssemblyInfo.cs --- a/Properties/AssemblyInfo.cs Wed Feb 03 20:35:10 2010 +0000 +++ b/Properties/AssemblyInfo.cs Wed Feb 03 22:02:58 2010 +0000 @@ -69,5 +69,5 @@ // 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")]