Index: /trunk/MacFaceFloat/MacFaceApp.cs
===================================================================
--- /trunk/MacFaceFloat/MacFaceApp.cs (revision 76)
+++ /trunk/MacFaceFloat/MacFaceApp.cs (revision 77)
@@ -49,4 +49,56 @@
}
+ ///
+ /// Windows 2000 ÍptH[}Xj^ª_Èç»ê¼êAPIŪñÎé
+ ///
+ 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);
+ }
+ }
+
+ 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 MemoryStatisticsPSAPI(61);
+ }
+ catch (System.InvalidOperationException)
+ {
+ // _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö
+ cpuStats = new CPUStatisticsGetSystemTime(61);
+ memStats = new MemoryStatisticsPSAPI(61);
+ }
+ }
+
public MacFaceApp()
{
@@ -54,18 +106,15 @@
config.Load();
- cpuStats = new CPUStatistics(81);
- memStats = new MemoryStatistics(81);
pageio_count = 0;
- // XXX: Îû@ªA·¬ÈÌð½Æ©·é
- try
- {
- // µÉJE^ðÀsµÄÝé
- cpuStats.Update();
- }
- catch (System.ComponentModel.Win32Exception e)
- {
- // _¾Á½ÌÅptH[}XJE^ðgíÈ¢û@Ö
- cpuStats = new CPUStatisticsGetSystemTime(61);
- memStats = new MemoryStatisticsPSAPI(61);
+
+ // OS ²ÆÉæ¾·éû@ðÏX·é
+ if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0)
+ {
+ SetupStatisticsForWindows2000();
+ }
+ else
+ {
+ // XP / 2003 / Vista
+ SetupStatisticsForWindowsXP();
}
Index: /trunk/MacFaceLibrary/CPUStatisticsGetSystemTime.cs
===================================================================
--- /trunk/MacFaceLibrary/CPUStatisticsGetSystemTime.cs (revision 76)
+++ /trunk/MacFaceLibrary/CPUStatisticsGetSystemTime.cs (revision 77)
@@ -6,5 +6,5 @@
{
///
- /// CPUStatisticsGetSystemTime nngY
+ /// CPUStatisticsGetSystemTime
///
public class CPUStatisticsGetSystemTime : CPUStatistics
Index: /trunk/MacFaceLibrary/CPUStatisticsNtQuerySystemInformation.cs
===================================================================
--- /trunk/MacFaceLibrary/CPUStatisticsNtQuerySystemInformation.cs (revision 77)
+++ /trunk/MacFaceLibrary/CPUStatisticsNtQuerySystemInformation.cs (revision 77)
@@ -0,0 +1,88 @@
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+namespace MacFace
+{
+ ///
+ /// CPUStatisticsNtQuerySystemInformation
+ ///
+ public class CPUStatisticsNtQuerySystemInformation : CPUStatistics
+ {
+
+ UInt64 idleTimePrev = 0;
+ UInt64 kernelTimePrev = 0;
+ UInt64 userTimePrev = 0;
+
+ public CPUStatisticsNtQuerySystemInformation(int historySize) : base(historySize)
+ {
+ NextValue();
+ }
+
+ protected override CPUUsage NextValue()
+ {
+ UInt64 idleTime;
+ UInt64 kernelTime;
+ UInt64 userTime;
+
+ SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION sysProcessorPerfInfo;
+ UInt32 outLen;
+ UInt32 len = (UInt32)(Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)));
+ NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation,
+ out sysProcessorPerfInfo
+ , len
+ , out outLen);
+
+ idleTime = (UInt64)sysProcessorPerfInfo.IdleTime;
+ kernelTime = (UInt64)sysProcessorPerfInfo.KernelTime;
+ userTime = (UInt64)sysProcessorPerfInfo.UserTime;
+
+ Int32 idleTimeDiff = (Int32)(idleTime - idleTimePrev);
+ Int32 userTimeDiff = (Int32)(userTime - userTimePrev);
+ Int32 kernelTimeDiff = (Int32)(kernelTime - kernelTimePrev);
+ Int32 systemTimeDiff = (Int32)(userTimeDiff + kernelTimeDiff);
+
+ idleTimePrev = idleTime;
+ kernelTimePrev = kernelTime;
+ userTimePrev = userTime;
+
+ return new CPUUsage(
+ (Int32)(100 - ((Double)idleTimeDiff / userTimePrev) * 100),
+ (Int32)(100 - ((Double)idleTimeDiff / kernelTimePrev) * 100),
+ (Int32)(((Double)idleTimeDiff / (systemTimeDiff)) * 100)
+ );
+ }
+
+ enum SYSTEM_INFORMATION_CLASS
+ {
+ SystemBasicInformation = 0,
+ SystemPerformanceInformation = 2,
+ SystemTimeOfDayInformation = 3,
+ SystemProcessInformation = 5,
+ SystemProcessorPerformanceInformation = 8,
+ SystemInterruptInformation = 23,
+ SystemExceptionInformation = 33,
+ SystemRegistryQuotaInformation = 37,
+ SystemLookasideInformation = 45
+ }
+
+ struct SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
+ {
+ public Int64 IdleTime;
+ public Int64 KernelTime;
+ public Int64 UserTime;
+ public Int64 Reserved1_0;
+ public Int64 Reserved1_1;
+ public Int32 Reserved2;
+ }
+
+ [DllImport("ntdll.dll")]
+ private extern static UInt32 NtQuerySystemInformation(
+ SYSTEM_INFORMATION_CLASS SystemInformationClass,
+ out SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SystemInformation,
+ UInt32 SystemInformationLength,
+ out UInt32 ReturnLength
+ );
+
+ }
+}
Index: /trunk/MacFaceLibrary/MacFaceLibrary.csproj
===================================================================
--- /trunk/MacFaceLibrary/MacFaceLibrary.csproj (revision 76)
+++ /trunk/MacFaceLibrary/MacFaceLibrary.csproj (revision 77)
@@ -110,4 +110,9 @@
/>
+
+
+ /// MemoryStatisticsGlobalMemoryStatusEx ÌTvÌà¾Å·B
+ ///
+ public class MemoryStatisticsGlobalMemoryStatusEx : MemoryStatistics
+ {
+ public MemoryStatisticsGlobalMemoryStatusEx(int historySize) : base(historySize)
+ {
+ }
+
+ public override ulong CommitLimit
+ {
+ get
+ {
+ Unmanaged.MEMORYSTATUSEX memStat = new Unmanaged.MEMORYSTATUSEX();
+ memStat.dwLength = (UInt32)Marshal.SizeOf(typeof(Unmanaged.MEMORYSTATUSEX));
+ Unmanaged.GlobalMemoryStatusEx(ref memStat);
+
+ return (ulong)memStat.ullTotalPageFile;
+ }
+ }
+
+ protected override MemoryUsage NextValue()
+ {
+ Unmanaged.MEMORYSTATUSEX memStat = new Unmanaged.MEMORYSTATUSEX();
+ memStat.dwLength = (UInt32)Marshal.SizeOf(typeof(Unmanaged.MEMORYSTATUSEX));
+ Unmanaged.GlobalMemoryStatusEx(ref memStat);
+
+ int available = (int)(memStat.ullAvailPageFile);
+ int committed = (int)(memStat.ullTotalPageFile - memStat.ullAvailPageFile);
+
+ return new MemoryUsage(available, committed, 0, 0,
+ 0, 0, 0, 0, 0);
+ }
+
+ private class Unmanaged
+ {
+ [DllImport("Kernel32.dll")]
+ public extern static Boolean GlobalMemoryStatusEx(
+ [In][Out] ref MEMORYSTATUSEX lpBuffer
+ );
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct MEMORYSTATUSEX
+ {
+ public UInt32 dwLength;
+ public UInt32 dwMemoryLoad;
+ public UInt64 ullTotalPhys;
+ public UInt64 ullAvailPhys;
+ public UInt64 ullTotalPageFile;
+ public UInt64 ullAvailPageFile;
+ public UInt64 ullTotalVirtual;
+ public UInt64 ullAvailVirtual;
+ public UInt64 ullAvailExtendedVirtual;
+ }
+ }
+
+ }
+}