diff -r ff3e6edc7113 -r 0e01b63e1fdc Hardware/CPU/AMD0FCPU.cs --- a/Hardware/CPU/AMD0FCPU.cs Wed Feb 03 22:02:58 2010 +0000 +++ b/Hardware/CPU/AMD0FCPU.cs Thu Feb 04 21:19:27 2010 +0000 @@ -58,8 +58,7 @@ private List active = new List(); - private PerformanceCounter totalLoadCounter; - private PerformanceCounter[] coreLoadCounters; + private CPULoad cpuLoad; private const ushort PCI_AMD_VENDOR_ID = 0x1022; private const ushort PCI_AMD_0FH_MISCELLANEOUS_DEVICE_ID = 0x1103; @@ -80,37 +79,23 @@ // max two cores coreCount = coreCount > 2 ? 2 : coreCount; - 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]; + + coreTemperatures = new Sensor[coreCount]; coreLoads = new Sensor[coreCount]; - for (int i = 0; i < coreLoadCounters.Length; i++) { - 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; - } + for (int i = 0; i < coreCount; i++) { + coreTemperatures[i] = + new Sensor("Core #" + (i + 1), i, SensorType.Temperature, this); coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1, SensorType.Load, this); - } + } - coreTemperatures = new Sensor[coreCount]; - for (int i = 0; i < coreCount; i++) - coreTemperatures[i] = - new Sensor("Core #" + (i + 1), i, SensorType.Temperature, this); + cpuLoad = new CPULoad(coreCount, 1); + if (cpuLoad.IsAvailable) { + foreach (Sensor sensor in coreLoads) + ActivateSensor(sensor); + ActivateSensor(totalLoad); + } pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID, PCI_AMD_0FH_MISCELLANEOUS_DEVICE_ID, 0); @@ -163,16 +148,12 @@ } } - if (totalLoadCounter != null) { - totalLoad.Value = totalLoadCounter.NextValue(); - ActivateSensor(totalLoad); + if (cpuLoad.IsAvailable) { + cpuLoad.Update(); + for (int i = 0; i < coreLoads.Length; i++) + coreLoads[i].Value = cpuLoad.GetCoreLoad(i); + totalLoad.Value = cpuLoad.GetTotalLoad(); } - - 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) {