Changeset 124
- Timestamp:
- May 26, 2009, 3:31:47 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MacFaceFloat/MacFaceApp.cs
r119 r124 48 48 public static void Main(string[] args) 49 49 { 50 //NtKernel.SYSTEM_BASIC_INFORMATION info = NtKernel.QuerySystemBasicInformation(); 51 //NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list = 52 // NtKernel.QuerySystemProcessorPerformanceInfomation((int)info.ActiveProcessors); 53 //MachineStatus status = MachineStatus.LocalMachineStatus(); 54 //int c = status.ProcessorCount; 55 //NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list = status.ProcessorPerformances(); 56 50 57 Application.EnableVisualStyles(); 51 58 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); … … 54 61 } 55 62 56 /// <summary>57 /// Windows 2000 ÍptH[}Xj^ª_Èç»ê¼êAPIŪñÎé58 /// </summary>59 public void SetupStatisticsForWindows2000()60 {61 // cpuStats = new CPUStatistics(81);62 // memStats = new MemoryStatistics(81);63 //64 // try65 // {66 // // µÉJE^ðÀsµÄÝé67 // cpuStats.Update();68 // memStats.Update();69 // }70 // catch (System.ComponentModel.Win32Exception)71 // {72 // // _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö73 // cpuStats = new CPUStatisticsNtQuerySystemInformation(61);74 // memStats = new MemoryStatisticsGlobalMemoryStatusEx(61);75 // }76 // catch (System.InvalidOperationException)77 // {78 // // _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö79 // cpuStats = new CPUStatisticsNtQuerySystemInformation(61);80 // memStats = new MemoryStatisticsGlobalMemoryStatusEx(61);81 // }82 83 cpuStats = new CPUStatisticsNtQuerySystemInformation(61);84 memStats = new MemoryStatisticsNtQuerySystemInformation(61);85 }86 87 public void SetupStatisticsForWindowsXP()88 {89 // cpuStats = new CPUStatistics(81);90 // memStats = new MemoryStatistics(81);91 // try92 // {93 // // µÉJE^ðÀsµÄÝé94 // cpuStats.Update();95 // memStats.Update();96 // }97 // catch (System.ComponentModel.Win32Exception)98 // {99 // // _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö100 // cpuStats = new CPUStatisticsGetSystemTime(61);101 // memStats = new MemoryStatisticsNtQuerySystemInformation(61);102 // }103 // catch (System.InvalidOperationException)104 // {105 // // _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö106 // cpuStats = new CPUStatisticsGetSystemTime(61);107 // memStats = new MemoryStatisticsPSAPI(61);108 // }109 110 cpuStats = new CPUStatisticsGetSystemTime(61);111 memStats = new MemoryStatisticsNtQuerySystemInformation(61);112 }113 63 114 64 public MacFaceApp() … … 119 69 pageio_count = 0; 120 70 121 // OS ²ÆÉæ¾·éû@ðÏX·é 122 if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0) 123 { 124 SetupStatisticsForWindows2000(); 125 } 126 else 127 { 128 // XP / 2003 / Vista 129 SetupStatisticsForWindowsXP(); 130 } 71 cpuStats = new CPUStatisticsNtQuerySystemInformation(61); 72 memStats = new MemoryStatisticsNtQuerySystemInformation(61); 73 74 patternWindow = null; 75 statusWindow = null; 76 77 InitializeComponent(); 78 79 // x64 «Š32bit È OptimusMini.dll ðÇÝà¤Æ·éÆRG[ÆÈéÌŽàµÈ¢NXɵĨ 80 optimusMini = (IntPtr.Size == 4 ? (IOptimusMini)new OptimusMini() : new OptimusMiniMock()); 81 optimusMini.DisplayOn(); 131 82 132 83 //OptimusMini.OnKeyDownCallbackDelegate oKD = new OptimusMini.OnKeyDownCallbackDelegate(OnKeyDownCallbackHandler); 133 84 //OptimusMini.OnDeviceStateChangedCallbackDelegate oDSC = new OptimusMini.OnDeviceStateChangedCallbackDelegate(OnDeviceStateChangedCallbackHandler); 134 85 //OptimusMini.RegisterEventHandler(oKD, oDSC); 135 136 patternWindow = null;137 statusWindow = null;138 139 InitializeComponent();140 141 // x64 «Š32bit È OptimusMini.dll ðÇÝà¤Æ·éÆRG[ÆÈéÌŽàµÈ¢NXɵĨ142 optimusMini = (IntPtr.Size == 4 ? (IOptimusMini)new OptimusMini() : new OptimusMiniMock());143 optimusMini.DisplayOn();144 86 145 87 CountProcessorUsage(null, null); -
trunk/MacFaceLibrary/CPUStatisticsNtQuerySystemInformation.cs
r121 r124 1 // $Id$ 1 2 using System; 2 3 using System.Diagnostics; … … 11 12 { 12 13 13 UInt64 idleTimePrev = 0;14 UInt64 kernelTimePrev = 0;15 UInt64 userTimePrev = 0;14 Int64 idleTimePrev = 0; 15 Int64 kernelTimePrev = 0; 16 Int64 userTimePrev = 0; 16 17 17 18 public CPUStatisticsNtQuerySystemInformation(int historySize) : base(historySize) … … 22 23 protected override CPUUsage NextValue() 23 24 { 24 UInt64 idleTime;25 UInt64 kernelTime;26 UInt64 userTime;25 Int64 idleTime; 26 Int64 kernelTime; 27 Int64 userTime; 27 28 28 NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION sysProcessorPerfInfo = NtKernel.QuerySystemProcessorPerformanceInfomation( );29 NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION sysProcessorPerfInfo = NtKernel.QuerySystemProcessorPerformanceInfomation(1)[0]; 29 30 30 idleTime = (UInt64)sysProcessorPerfInfo.IdleTime;31 kernelTime = (UInt64)sysProcessorPerfInfo.KernelTime;32 userTime = (UInt64)sysProcessorPerfInfo.UserTime;31 idleTime = sysProcessorPerfInfo.IdleTime; 32 kernelTime = sysProcessorPerfInfo.KernelTime - idleTime; 33 userTime = sysProcessorPerfInfo.UserTime; 33 34 34 Int 32 idleTimeDiff = (Int32)(idleTime - idleTimePrev);35 Int32 userTimeDiff = (Int32)(userTime - userTimePrev);36 Int32 kernelTimeDiff = (Int32)(kernelTime - kernelTimePrev);37 Int32 systemTimeDiff = (Int32)(userTimeDiff + kernelTimeDiff);35 Int64 idleTimeDiff = idleTime - idleTimePrev; 36 Int64 userTimeDiff = userTime - userTimePrev; 37 Int64 kernelTimeDiff = kernelTime - kernelTimePrev; 38 Int64 totalTimeDiff = idleTimeDiff + userTimeDiff + kernelTimeDiff; 38 39 39 40 idleTimePrev = idleTime; … … 42 43 43 44 return new CPUUsage( 44 (Int32)( 100 - ((Double)idleTimeDiff / userTimePrev) * 100),45 (Int32)( 100 - ((Double)idleTimeDiff / kernelTimePrev) * 100),46 (Int32)(((Double)idleTimeDiff / (systemTimeDiff)) * 100)45 (Int32)(((Double)userTimeDiff / totalTimeDiff) * 100), 46 (Int32)(((Double)kernelTimeDiff / totalTimeDiff) * 100), 47 (Int32)(((Double)idleTimeDiff / totalTimeDiff) * 100) 47 48 ); 48 49 } -
trunk/MacFaceLibrary/MachineStatus.cs
-
Property
svn:keywords
set to
Id
r122 r124 1 using System; 1 // $Id$ 2 using System; 2 3 using System.Collections.Generic; 3 4 using System.Text; … … 5 6 namespace MacFace 6 7 { 7 class MachineStatus8 public class MachineStatus 8 9 { 9 10 protected static MachineStatus sharedMachineStatus; 10 11 11 protected Byte numberProcessors;12 protected Byte processorCount; 12 13 13 14 public static MachineStatus LocalMachineStatus() … … 23 24 { 24 25 NtKernel.SYSTEM_BASIC_INFORMATION info = NtKernel.QuerySystemBasicInformation(); 25 numberProcessors= info.NumberProcessors;26 processorCount = info.NumberProcessors; 26 27 } 27 28 28 public int NumberProcessors29 public int ProcessorCount 29 30 { 30 31 get 31 32 { 32 return numberProcessors;33 return processorCount; 33 34 } 34 35 } 35 36 37 public NtKernel.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] ProcessorPerformances() 38 { 39 return NtKernel.QuerySystemProcessorPerformanceInfomation(processorCount); 40 } 36 41 } 37 42 } -
Property
svn:keywords
set to
-
trunk/MacFaceLibrary/NtKernel.cs
-
Property
svn:keywords
set to
Id
r121 r124 1 using System; 1 // $Id$ 2 using System; 2 3 using System.Runtime.InteropServices; 3 4 4 class NtKernel {5 public class NtKernel { 5 6 6 unsafepublic static SYSTEM_BASIC_INFORMATION QuerySystemBasicInformation()7 public static SYSTEM_BASIC_INFORMATION QuerySystemBasicInformation() 7 8 { 8 SYSTEM_BASIC_INFORMATION info = new SYSTEM_BASIC_INFORMATION();9 UInt32 len = (UInt32)Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION));9 int len = Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION)); 10 IntPtr ptr = Marshal.AllocCoTaskMem(len); 10 11 UInt32 outLen; 11 12 12 13 NtQuerySystemInformation( 13 SYSTEM_INFORMATION_CLASS.SystemBasicInformation, &info,len, out outLen14 SYSTEM_INFORMATION_CLASS.SystemBasicInformation, ptr, (UInt32)len, out outLen 14 15 ); 15 return info; 16 17 return (SYSTEM_BASIC_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_BASIC_INFORMATION)); 16 18 } 17 19 18 unsafepublic static SYSTEM_PERFORMANCE_INFORMATION QuerySystemPerformanceInformation()20 public static SYSTEM_PERFORMANCE_INFORMATION QuerySystemPerformanceInformation() 19 21 { 20 SYSTEM_PERFORMANCE_INFORMATION info = new SYSTEM_PERFORMANCE_INFORMATION();21 UInt32 len = (UInt32)Marshal.SizeOf(typeof(SYSTEM_PERFORMANCE_INFORMATION));22 int len = Marshal.SizeOf(typeof(SYSTEM_PERFORMANCE_INFORMATION)); 23 IntPtr ptr = Marshal.AllocCoTaskMem(len); 22 24 UInt32 outLen; 23 25 24 26 NtQuerySystemInformation( 25 SYSTEM_INFORMATION_CLASS.SystemPerformanceInformation, &info,len, out outLen27 SYSTEM_INFORMATION_CLASS.SystemPerformanceInformation, ptr, (UInt32)len, out outLen 26 28 ); 27 return info; 29 30 return (SYSTEM_PERFORMANCE_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_PERFORMANCE_INFORMATION)); 28 31 } 29 32 30 unsafe public static SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION QuerySystemProcessorPerformanceInfomation()33 public static SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] QuerySystemProcessorPerformanceInfomation(int processorCount) 31 34 { 32 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION info = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION();33 UInt32 len = (UInt32)(Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)));35 int len = Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)) * processorCount; 36 IntPtr ptr = Marshal.AllocCoTaskMem(len); 34 37 UInt32 outLen; 38 35 39 NtQuerySystemInformation( 36 SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, &info,len, out outLen40 SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, ptr, (UInt32)len, out outLen 37 41 ); 38 return info; 42 43 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[processorCount]; 44 for (int i = 0; i < processorCount; i++) { 45 IntPtr p = new IntPtr(ptr.ToInt32() + Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)) * i); 46 list[i] = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)Marshal.PtrToStructure(p, typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)); 47 } 48 49 return list; 39 50 } 40 51 41 52 [DllImport("ntdll.dll")] 42 unsafeprotected extern static UInt32 NtQuerySystemInformation(53 protected extern static UInt32 NtQuerySystemInformation( 43 54 SYSTEM_INFORMATION_CLASS SystemInformationClass, 44 void*SystemInformation,55 IntPtr SystemInformation, 45 56 UInt32 SystemInformationLength, 46 57 out UInt32 ReturnLength … … 63 74 public struct SYSTEM_BASIC_INFORMATION 64 75 { 65 public UInt 64Unknown;66 public UInt 64MaximumIncrement;67 public UInt 64PhysicalPageSize;68 public UInt 64NumberOfPhysicalPages;69 public UInt 64LowestPhysicalPage;70 public UInt 64HighestPhysicalPage;71 public UInt 64AllocationGranularity;72 public UInt 64LowestUserAddress;73 public UInt 64HighestUserAddress;74 public UInt 64ActiveProcessors;76 public UInt32 Unknown; 77 public UInt32 MaximumIncrement; 78 public UInt32 PhysicalPageSize; 79 public UInt32 NumberOfPhysicalPages; 80 public UInt32 LowestPhysicalPage; 81 public UInt32 HighestPhysicalPage; 82 public UInt32 AllocationGranularity; 83 public UInt32 LowestUserAddress; 84 public UInt32 HighestUserAddress; 85 public UInt32 ActiveProcessors; 75 86 public Byte NumberProcessors; 76 87 } -
Property
svn:keywords
set to
Note: See TracChangeset
for help on using the changeset viewer.