1.1 --- a/Hardware/CPU/IntelCPU.cs Wed Feb 03 20:35:10 2010 +0000
1.2 +++ b/Hardware/CPU/IntelCPU.cs Wed Feb 03 22:02:58 2010 +0000
1.3 @@ -133,19 +133,29 @@
1.4 default: tjMax = 100; break;
1.5 }
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[
1.23 coreCount * logicalProcessorsPerCore];
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 }
1.39
1.40 coreTemperatures = new Sensor[coreCount];
1.41 @@ -211,17 +221,27 @@
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 float value = 0;
1.54 - for (int j = 0; j < logicalProcessorsPerCore; j++)
1.55 - value += coreLoadCounters[
1.56 - logicalProcessorsPerCore * i + j].NextValue();
1.57 - value /= logicalProcessorsPerCore;
1.58 - coreLoads[i].Value = value;
1.59 - ActivateSensor(coreLoads[i]);
1.60 + int count = 0;
1.61 + for (int j = 0; j < logicalProcessorsPerCore; j++) {
1.62 + PerformanceCounter counter =
1.63 + coreLoadCounters[logicalProcessorsPerCore * i + j];
1.64 + if (counter != null) {
1.65 + value += counter.NextValue();
1.66 + count++;
1.67 + }
1.68 + }
1.69 + if (count > 0) {
1.70 + value /= count;
1.71 + coreLoads[i].Value = value;
1.72 + ActivateSensor(coreLoads[i]);
1.73 + }
1.74 }
1.75 }
1.76