1.1 --- a/Hardware/CPU/CPULoad.cs Mon Apr 05 21:31:21 2010 +0000
1.2 +++ b/Hardware/CPU/CPULoad.cs Sat Apr 24 19:59:52 2010 +0000
1.3 @@ -68,8 +68,7 @@
1.4 [Out] SystemProcessorPerformanceInformation[] informations,
1.5 int structSize, out IntPtr returnLength);
1.6
1.7 - private uint coreCount;
1.8 - private uint logicalProcessorsPerCore;
1.9 + private CPUID[][] cpuid;
1.10
1.11 private long systemTime;
1.12 private long[] idleTimes;
1.13 @@ -80,7 +79,7 @@
1.14 private bool available = false;
1.15
1.16 private long[] GetIdleTimes() {
1.17 - long[] result = new long[coreCount * logicalProcessorsPerCore];
1.18 + long[] result = new long[cpuid.Length * cpuid[0].Length];
1.19 SystemProcessorPerformanceInformation[] informations = new
1.20 SystemProcessorPerformanceInformation[result.Length];
1.21
1.22 @@ -97,10 +96,9 @@
1.23 return result;
1.24 }
1.25
1.26 - public CPULoad(uint coreCount, uint logicalProcessorsPerCore) {
1.27 - this.coreCount = coreCount;
1.28 - this.logicalProcessorsPerCore = logicalProcessorsPerCore;
1.29 - this.coreLoads = new float[coreCount];
1.30 + public CPULoad(CPUID[][] cpuid) {
1.31 + this.cpuid = cpuid;
1.32 + this.coreLoads = new float[cpuid.Length];
1.33 this.systemTime = DateTime.Now.Ticks;
1.34 this.totalLoad = 0;
1.35 try {
1.36 @@ -135,21 +133,22 @@
1.37 return;
1.38
1.39 float total = 0;
1.40 - for (int i = 0; i < coreCount; i++) {
1.41 + int count = 0;
1.42 + for (int i = 0; i < cpuid.Length; i++) {
1.43 float value = 0;
1.44 - for (int j = 0; j < logicalProcessorsPerCore; j++) {
1.45 - long index = i * logicalProcessorsPerCore + j;
1.46 + for (int j = 0; j < cpuid[i].Length; j++) {
1.47 + long index = cpuid[i][j].Thread;
1.48 long delta = idleTimes[index] - this.idleTimes[index];
1.49 value += delta;
1.50 total += delta;
1.51 + count++;
1.52 }
1.53 - value = 1.0f - value / (logicalProcessorsPerCore *
1.54 + value = 1.0f - value / (cpuid[i].Length *
1.55 (systemTime - this.systemTime));
1.56 value = value < 0 ? 0 : value;
1.57 coreLoads[i] = value * 100;
1.58 }
1.59 - total = 1.0f - total / (coreCount * logicalProcessorsPerCore *
1.60 - (systemTime - this.systemTime));
1.61 + total = 1.0f - total / (count * (systemTime - this.systemTime));
1.62 total = total < 0 ? 0 : total;
1.63 this.totalLoad = total * 100;
1.64