Index: MacFaceFloat/MacFaceApp.cs
===================================================================
--- MacFaceFloat/MacFaceApp.cs (revision 69)
+++ MacFaceFloat/MacFaceApp.cs (working copy)
@@ -49,9 +49,21 @@
{
config = Configuration.GetInstance();
config.Load();
-
+
cpuStats = new CPUStatistics(61);
memStats = new MemoryStatistics(61);
+ // XXX: 対処方法がアレすぎなのを何とかする
+ try
+ {
+ // 試しにカウンタを実行してみる
+ cpuStats.Update();
+ }
+ catch (System.ComponentModel.Win32Exception e)
+ {
+ // ダメだったのでパフォーマンスカウンタを使わない方法へ
+ cpuStats = new CPUStatisticsGetSystemTime(61);
+ memStats = new MemoryStatisticsPSAPI(61);
+ }
updateTimer = new System.Windows.Forms.Timer();
updateTimer.Enabled = false;
Index: MacFaceFloat/PatternWindow.cs
===================================================================
--- MacFaceFloat/PatternWindow.cs (revision 69)
+++ MacFaceFloat/PatternWindow.cs (working copy)
@@ -79,6 +79,7 @@
{
Graphics g = this.Graphics;
g.Clear(Color.FromArgb(0, 0, 0, 0));
+ g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
curFaceDef.DrawPatternImage(g, curSuite, curPattern, curMarkers, patternSize);
base.Refresh();
}
Index: MacFaceLibrary/CPUStatistics.cs
===================================================================
--- MacFaceLibrary/CPUStatistics.cs (revision 69)
+++ MacFaceLibrary/CPUStatistics.cs (working copy)
@@ -70,7 +70,7 @@
if (count < length) count++;
}
- protected CPUUsage NextValue()
+ protected virtual CPUUsage NextValue()
{
int user = (int)userCounter.NextValue();
int system = (int)systemCounter.NextValue();
Index: MacFaceLibrary/CPUStatisticsGetSystemTime.cs
===================================================================
--- MacFaceLibrary/CPUStatisticsGetSystemTime.cs (revision 0)
+++ MacFaceLibrary/CPUStatisticsGetSystemTime.cs (revision 0)
@@ -0,0 +1,54 @@
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+namespace MacFace
+{
+ ///
+ /// CPUStatisticsGetSystemTime の概要の説明です。
+ ///
+ public class CPUStatisticsGetSystemTime : CPUStatistics
+ {
+
+ UInt64 idleTimePrev = 0;
+ UInt64 kernelTimePrev = 0;
+ UInt64 userTimePrev = 0;
+
+ public CPUStatisticsGetSystemTime(int historySize) : base(historySize)
+ {
+ NextValue();
+ }
+
+ protected override CPUUsage NextValue()
+ {
+ UInt64 idleTime;
+ UInt64 kernelTime;
+ UInt64 userTime;
+
+ GetSystemTimes(out idleTime, out kernelTime, out 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)
+ );
+ }
+
+ [DllImport("kernel32.dll")]
+ private extern static Boolean GetSystemTimes(
+ out UInt64 lpIdleTime,
+ out UInt64 lpKernelTime,
+ out UInt64 lpUserTime
+ );
+
+ }
+}
Property changes on: MacFaceLibrary\CPUStatisticsGetSystemTime.cs
___________________________________________________________________
Name: svn:keywords
+ Id
Index: MacFaceLibrary/MacFaceLibrary.csproj
===================================================================
--- MacFaceLibrary/MacFaceLibrary.csproj (revision 69)
+++ MacFaceLibrary/MacFaceLibrary.csproj (working copy)
@@ -104,6 +104,11 @@
BuildAction = "Compile"
/>
+
+
+ /// MemoryStatisticsPSAPI の概要の説明です。
+ ///
+ public class MemoryStatisticsPSAPI : MemoryStatistics
+ {
+ public MemoryStatisticsPSAPI(int historySize) : base(historySize)
+ {
+ }
+
+ public override ulong CommitLimit
+ {
+ get
+ {
+ Unmanaged.PERFORMANCE_INFORMATION pInfo;
+ pInfo.cb = (UInt32)Marshal.SizeOf(typeof(Unmanaged.PERFORMANCE_INFORMATION));
+ Unmanaged.GetPerformanceInfo(out pInfo, (UInt32)Marshal.SizeOf(typeof(Unmanaged.PERFORMANCE_INFORMATION)));
+
+ return (ulong)pInfo.CommitLimit * pInfo.PageSize;
+ }
+ }
+
+ protected override MemoryUsage NextValue()
+ {
+ Unmanaged.PERFORMANCE_INFORMATION pInfo;
+ pInfo.cb = (UInt32)Marshal.SizeOf(typeof(Unmanaged.PERFORMANCE_INFORMATION));
+ Unmanaged.GetPerformanceInfo(out pInfo, (UInt32)Marshal.SizeOf(typeof(Unmanaged.PERFORMANCE_INFORMATION)));
+
+ int available = (int)(pInfo.PhysicalAvailable * pInfo.PageSize);
+ int committed = (int)(pInfo.CommitTotal * pInfo.PageSize);
+
+ // TODO:
+ int pagein = (int)0;
+ int pageout = (int)0;
+
+ int systemCache = (int)(pInfo.SystemCache * pInfo.PageSize);
+ int kernelPaged = (int)(pInfo.KernelPaged * pInfo.PageSize);
+ int kernelNonPaged = (int)(pInfo.KernelNonpaged * pInfo.PageSize);
+
+ // XXX: とりあえず片方に振り分けてしまう
+ // int kernelTotal = usage.KernelNonPaged + usage.KernelPaged + usage.DriverTotal + usage.SystemCodeTotal;
+ int driverTotal = (int)0;
+ int systemCodeTotal = (int)((pInfo.KernelTotal - (pInfo.KernelNonpaged + pInfo.KernelPaged)) * pInfo.PageSize);
+
+ return new MemoryUsage(available, committed, pagein, pageout,
+ systemCache, kernelPaged, kernelNonPaged, driverTotal, systemCodeTotal);
+ }
+
+ private class Unmanaged
+ {
+ [DllImport("psapi.dll")]
+ public extern static Boolean GetPerformanceInfo(
+ [Out] out PERFORMANCE_INFORMATION pPerformanceInformation,
+ [In] UInt32 cb
+ );
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct PERFORMANCE_INFORMATION
+ {
+ public UInt32 cb;
+ // SIZE_T -> UInt32 (x86)
+ public UInt32 CommitTotal;
+ public UInt32 CommitLimit;
+ public UInt32 CommitPeak;
+ public UInt32 PhysicalTotal;
+ public UInt32 PhysicalAvailable;
+ public UInt32 SystemCache;
+ public UInt32 KernelTotal;
+ public UInt32 KernelPaged;
+ public UInt32 KernelNonpaged;
+ public UInt32 PageSize;
+ public UInt32 HandleCount;
+ public UInt32 ProcessCount;
+ public UInt32 ThreadCount;
+ }
+ }
+
+ }
+}
Property changes on: MacFaceLibrary\MemoryStatisticsPSAPI.cs
___________________________________________________________________
Name: svn:keywords
+ Id