Index: /trunk/MacFaceFloat/MacFaceApp.cs
===================================================================
--- /trunk/MacFaceFloat/MacFaceApp.cs	(revision 123)
+++ /trunk/MacFaceFloat/MacFaceApp.cs	(revision 124)
@@ -48,4 +48,11 @@
 		public static void Main(string[] args)
 		{
+            //NtKernel.SYSTEM_BASIC_INFORMATION info = NtKernel.QuerySystemBasicInformation();
+            //NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list =
+            //    NtKernel.QuerySystemProcessorPerformanceInfomation((int)info.ActiveProcessors);
+            //MachineStatus status = MachineStatus.LocalMachineStatus();
+            //int c = status.ProcessorCount;
+            //NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list = status.ProcessorPerformances();
+
             Application.EnableVisualStyles();
             AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
@@ -54,61 +61,4 @@
 		}
 
-		/// <summary>
-		/// Windows 2000 ÍptH[}Xj^ª_Èç»ê¼êAPIÅªñÎé
-		/// </summary>
-		public void SetupStatisticsForWindows2000()
-		{
-//			cpuStats = new CPUStatistics(81);
-//			memStats = new MemoryStatistics(81);
-//
-//			try 
-//			{
-//				// µÉJE^ðÀsµÄÝé
-//				cpuStats.Update();
-//				memStats.Update();
-//			} 
-//			catch (System.ComponentModel.Win32Exception) 
-//			{
-//				// _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö
-//				cpuStats = new CPUStatisticsNtQuerySystemInformation(61);
-//				memStats = new MemoryStatisticsGlobalMemoryStatusEx(61);
-//			}
-//			catch (System.InvalidOperationException) 
-//			{
-//				// _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö
-//				cpuStats = new CPUStatisticsNtQuerySystemInformation(61);
-//				memStats = new MemoryStatisticsGlobalMemoryStatusEx(61);
-//			}
-
-			cpuStats = new CPUStatisticsNtQuerySystemInformation(61);
-			memStats = new MemoryStatisticsNtQuerySystemInformation(61);
-		}
-
-		public void SetupStatisticsForWindowsXP()
-		{
-//			cpuStats = new CPUStatistics(81);
-//			memStats = new MemoryStatistics(81);
-//			try 
-//			{
-//				// µÉJE^ðÀsµÄÝé
-//				cpuStats.Update();
-//				memStats.Update();
-//			} 
-//			catch (System.ComponentModel.Win32Exception) 
-//			{
-//				// _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö
-//				cpuStats = new CPUStatisticsGetSystemTime(61);
-//				memStats = new MemoryStatisticsNtQuerySystemInformation(61);
-//			}
-//			catch (System.InvalidOperationException) 
-//			{
-//				// _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö
-//				cpuStats = new CPUStatisticsGetSystemTime(61);
-//				memStats = new MemoryStatisticsPSAPI(61);
-//			}
-
-			cpuStats = new CPUStatisticsGetSystemTime(61);
-			memStats = new MemoryStatisticsNtQuerySystemInformation(61);
-		}
 
 		public MacFaceApp()
@@ -119,27 +69,19 @@
 			pageio_count = 0;
 
-			// OS ²ÆÉæ¾·éû@ðÏX·é
-			if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0)
-			{
-				SetupStatisticsForWindows2000();
-			}
-			else
-			{
-				// XP / 2003 / Vista
-				SetupStatisticsForWindowsXP();
-			}
+            cpuStats = new CPUStatisticsNtQuerySystemInformation(61);
+            memStats = new MemoryStatisticsNtQuerySystemInformation(61);
+
+            patternWindow = null;
+            statusWindow = null;
+
+            InitializeComponent();
+
+            // x64 Â«Å 32bit È OptimusMini.dll ðÇÝà¤Æ·éÆRG[ÆÈéÌÅ½àµÈ¢NXÉµÄ¨­
+		    optimusMini = (IntPtr.Size == 4 ? (IOptimusMini)new OptimusMini() : new OptimusMiniMock());
+            optimusMini.DisplayOn();
 
             //OptimusMini.OnKeyDownCallbackDelegate oKD = new OptimusMini.OnKeyDownCallbackDelegate(OnKeyDownCallbackHandler);
             //OptimusMini.OnDeviceStateChangedCallbackDelegate oDSC = new OptimusMini.OnDeviceStateChangedCallbackDelegate(OnDeviceStateChangedCallbackHandler);
             //OptimusMini.RegisterEventHandler(oKD, oDSC);
-
-            patternWindow = null;
-            statusWindow = null;
-
-            InitializeComponent();
-
-            // x64 Â«Å 32bit È OptimusMini.dll ðÇÝà¤Æ·éÆRG[ÆÈéÌÅ½àµÈ¢NXÉµÄ¨­
-		    optimusMini = (IntPtr.Size == 4 ? (IOptimusMini)new OptimusMini() : new OptimusMiniMock());
-            optimusMini.DisplayOn();
 
             CountProcessorUsage(null, null);
Index: /trunk/MacFaceLibrary/CPUStatisticsNtQuerySystemInformation.cs
===================================================================
--- /trunk/MacFaceLibrary/CPUStatisticsNtQuerySystemInformation.cs	(revision 123)
+++ /trunk/MacFaceLibrary/CPUStatisticsNtQuerySystemInformation.cs	(revision 124)
@@ -1,2 +1,3 @@
+// $Id$
 using System;
 using System.Diagnostics;
@@ -11,7 +12,7 @@
 	{
 			
-		UInt64 idleTimePrev = 0;
-		UInt64 kernelTimePrev = 0;
-		UInt64 userTimePrev = 0;
+		Int64 idleTimePrev = 0;
+		Int64 kernelTimePrev = 0;
+		Int64 userTimePrev = 0;
 
 		public CPUStatisticsNtQuerySystemInformation(int historySize) : base(historySize)
@@ -22,18 +23,18 @@
 		protected override CPUUsage NextValue()
 		{
-			UInt64 idleTime;
-			UInt64 kernelTime;
-			UInt64 userTime;
+			Int64 idleTime;
+			Int64 kernelTime;
+			Int64 userTime;
 
-			NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION sysProcessorPerfInfo = NtKernel.QuerySystemProcessorPerformanceInfomation();
+			NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION sysProcessorPerfInfo = NtKernel.QuerySystemProcessorPerformanceInfomation(1)[0];
 			
-			idleTime = (UInt64)sysProcessorPerfInfo.IdleTime;
-			kernelTime = (UInt64)sysProcessorPerfInfo.KernelTime;
-			userTime = (UInt64)sysProcessorPerfInfo.UserTime;
+			idleTime = sysProcessorPerfInfo.IdleTime;
+			kernelTime = sysProcessorPerfInfo.KernelTime - idleTime;
+			userTime = sysProcessorPerfInfo.UserTime;
 				
-			Int32 idleTimeDiff = (Int32)(idleTime - idleTimePrev);
-			Int32 userTimeDiff = (Int32)(userTime - userTimePrev);
-			Int32 kernelTimeDiff = (Int32)(kernelTime - kernelTimePrev);
-			Int32 systemTimeDiff = (Int32)(userTimeDiff + kernelTimeDiff);
+			Int64 idleTimeDiff = idleTime - idleTimePrev;
+            Int64 userTimeDiff = userTime - userTimePrev;
+            Int64 kernelTimeDiff = kernelTime - kernelTimePrev;
+            Int64 totalTimeDiff = idleTimeDiff + userTimeDiff + kernelTimeDiff;
 
 			idleTimePrev = idleTime;
@@ -42,7 +43,7 @@
 
 			return new CPUUsage(
-				(Int32)(100 - ((Double)idleTimeDiff / userTimePrev) * 100),
-				(Int32)(100 - ((Double)idleTimeDiff / kernelTimePrev) * 100),
-				(Int32)(((Double)idleTimeDiff / (systemTimeDiff)) * 100)
+				(Int32)(((Double)userTimeDiff / totalTimeDiff) * 100),
+				(Int32)(((Double)kernelTimeDiff / totalTimeDiff) * 100),
+				(Int32)(((Double)idleTimeDiff / totalTimeDiff) * 100)
 			);
 		}
Index: /trunk/MacFaceLibrary/MachineStatus.cs
===================================================================
--- /trunk/MacFaceLibrary/MachineStatus.cs	(revision 123)
+++ /trunk/MacFaceLibrary/MachineStatus.cs	(revision 124)
@@ -1,3 +1,4 @@
-﻿using System;
+﻿// $Id$
+using System;
 using System.Collections.Generic;
 using System.Text;
@@ -5,9 +6,9 @@
 namespace MacFace
 {
-    class MachineStatus
+    public class MachineStatus
     {
         protected static MachineStatus sharedMachineStatus;
 
-        protected Byte numberProcessors;
+        protected Byte processorCount;
 
         public static MachineStatus LocalMachineStatus()
@@ -23,15 +24,19 @@
         {
             NtKernel.SYSTEM_BASIC_INFORMATION info = NtKernel.QuerySystemBasicInformation();
-            numberProcessors = info.NumberProcessors;
+            processorCount = info.NumberProcessors;
         }
 
-        public int NumberProcessors
+        public int ProcessorCount
         {
             get
             {
-                return numberProcessors;
+                return processorCount;
             }
         }
 
+        public NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] ProcessorPerformances()
+        {
+            return NtKernel.QuerySystemProcessorPerformanceInfomation(processorCount);
+        }
     }
 }
Index: /trunk/MacFaceLibrary/NtKernel.cs
===================================================================
--- /trunk/MacFaceLibrary/NtKernel.cs	(revision 123)
+++ /trunk/MacFaceLibrary/NtKernel.cs	(revision 124)
@@ -1,46 +1,57 @@
-﻿using System;
+﻿// $Id$
+using System;
 using System.Runtime.InteropServices;
 
-class NtKernel {
+public class NtKernel {
 
-    unsafe public static SYSTEM_BASIC_INFORMATION QuerySystemBasicInformation()
+    public static SYSTEM_BASIC_INFORMATION QuerySystemBasicInformation()
     {
-        SYSTEM_BASIC_INFORMATION info = new SYSTEM_BASIC_INFORMATION();
-        UInt32 len = (UInt32)Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION));
+        int len = Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION));
+        IntPtr ptr = Marshal.AllocCoTaskMem(len);
         UInt32 outLen;
 
         NtQuerySystemInformation(
-            SYSTEM_INFORMATION_CLASS.SystemBasicInformation, &info, len, out outLen
+            SYSTEM_INFORMATION_CLASS.SystemBasicInformation, ptr, (UInt32)len, out outLen
         );
-        return info;
+
+        return (SYSTEM_BASIC_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_BASIC_INFORMATION));
     }
 
-    unsafe public static SYSTEM_PERFORMANCE_INFORMATION QuerySystemPerformanceInformation()
+    public static SYSTEM_PERFORMANCE_INFORMATION QuerySystemPerformanceInformation()
     {
-        SYSTEM_PERFORMANCE_INFORMATION info = new SYSTEM_PERFORMANCE_INFORMATION();
-        UInt32 len = (UInt32)Marshal.SizeOf(typeof(SYSTEM_PERFORMANCE_INFORMATION));
+        int len = Marshal.SizeOf(typeof(SYSTEM_PERFORMANCE_INFORMATION));
+        IntPtr ptr = Marshal.AllocCoTaskMem(len);
         UInt32 outLen;
 
         NtQuerySystemInformation(
-            SYSTEM_INFORMATION_CLASS.SystemPerformanceInformation, &info, len, out outLen
+            SYSTEM_INFORMATION_CLASS.SystemPerformanceInformation, ptr, (UInt32)len, out outLen
         );
-        return info;
+
+        return (SYSTEM_PERFORMANCE_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_PERFORMANCE_INFORMATION));
     }
 
-    unsafe public static SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION QuerySystemProcessorPerformanceInfomation()
+    public static SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] QuerySystemProcessorPerformanceInfomation(int processorCount)
     {
-        SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION info = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION();
-        UInt32 len = (UInt32)(Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)));
+        int len = Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)) * processorCount;
+        IntPtr ptr = Marshal.AllocCoTaskMem(len);
         UInt32 outLen;
+
         NtQuerySystemInformation(
-            SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, &info, len, out outLen
+            SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, ptr, (UInt32)len, out outLen
         );
-        return info;
+
+        SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[processorCount];
+        for (int i = 0; i < processorCount; i++) {
+            IntPtr p = new IntPtr(ptr.ToInt32() + Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)) * i);
+            list[i] = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)Marshal.PtrToStructure(p, typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
+        }
+    
+        return list;
     }
 
     [DllImport("ntdll.dll")]
-    unsafe protected extern static UInt32 NtQuerySystemInformation(
+    protected extern static UInt32 NtQuerySystemInformation(
         SYSTEM_INFORMATION_CLASS SystemInformationClass,
-        void* SystemInformation,
+        IntPtr SystemInformation,
         UInt32 SystemInformationLength,
         out UInt32 ReturnLength
@@ -63,14 +74,14 @@
     public struct SYSTEM_BASIC_INFORMATION
     {
-        public UInt64 Unknown;
-        public UInt64 MaximumIncrement;
-        public UInt64 PhysicalPageSize;
-        public UInt64 NumberOfPhysicalPages;
-        public UInt64 LowestPhysicalPage;
-        public UInt64 HighestPhysicalPage;
-        public UInt64 AllocationGranularity;
-        public UInt64 LowestUserAddress;
-        public UInt64 HighestUserAddress;
-        public UInt64 ActiveProcessors;
+        public UInt32 Unknown;
+        public UInt32 MaximumIncrement;
+        public UInt32 PhysicalPageSize;
+        public UInt32 NumberOfPhysicalPages;
+        public UInt32 LowestPhysicalPage;
+        public UInt32 HighestPhysicalPage;
+        public UInt32 AllocationGranularity;
+        public UInt32 LowestUserAddress;
+        public UInt32 HighestUserAddress;
+        public UInt32 ActiveProcessors;
         public Byte NumberProcessors;
     }
