2009年2月24日 星期二

.NET Compact Framework 程式效能檢查方法

很簡單 只要設定
[HKEY_LOCAL_MACHINE\Software\Microsoft\.NETCompactFramework\PerfMonitor]
"Counters"=dword:1

就好了

之後Run .NET Program 然後會在根目錄下產生 "AppName".stat 這個檔案
就可以分析了

設定的code

C#


// Call this method with True to 
// turn on the peformance counters,
// or with False to turn them off.
private void SetPerfCounters(bool perfOn)
{
// Specify values for setting the registry.
string userRoot = "HKEY_LOCAL_MACHINE";
string subkey = "SOFTWARE\\Microsoft\\.NETCompactFramework\\PerfMonitor";
string keyName = userRoot + "\\" + subkey;

int PCset;
if(perfOn == true)
PCset = 1;
else
PCset = 0;

// Set the the registry value.
try
{
Registry.SetValue(keyName, "Counters", PCset);
if(perfOn == true)
MessageBox.Show("Performance Counters On");
else
MessageBox.Show("Performance Counters Off");
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}

WINCE Power Management

我做的專案 會在6分鐘之後 沒有聲音
經調查之後發現是Power Management 關掉聲音

詳細看了一下registry setting 及 Document 後
發現重點如下


[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\Timeouts]
; @CESYSGEN IF PM_PM_DEFAULT_PDD
"ACUserIdle"=dword:3c ; in seconds
"ACSystemIdle"=dword:12c ; in seconds
"ACSuspend"=dword:0 ; in seconds
"BattUserIdle"=dword:3c ; in seconds
"BattSystemIdle"=dword:b4 ; in seconds
"BattSuspend"=dword:12c ; in seconds


如上, 系統經過 ACUserIdle 秒數之後沒動作 會進入 UserIdle模式
如又經過 ACSystemIdle 秒數沒動作 會進入 SystemIdle

在機器上 就是經過 6分鐘 ( 0x3c + 0x12c 秒)之後關掉聲音


還有 WINCE 的Power Managment 有三種方式
只能選擇其一 以避免衝突

GWES, Power Manager, User Control

GWES 是 WinCE 4.1前所用的方式
所以要用 Power Manager 管理的話 必需把 GWES相關設定關掉
如下 ( Registry Default)

; Set GWES registry keys so that it's not fighting with the PM about
; when to suspend the system. Setting DisableGwesPowerOff to a non-
; zero value tells GWES to ignore the settings of the BattPowerOff,
; ExtPowerOff, and WakeupPowerOff values.
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power]
"DisableGwesPowerOff"=dword:1

所以解法就是
在 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\Timeouts] 下
"ACUserIdle"=dword:0


// Reset Timer
You can reset the system state transition timers by creating a named auto-reset event called _T("PowerManager/ReloadActivityTimeouts") and calling SetEvent on the handle of that event. This informs the Power Manager to read transition timer settings again from the Timeouts registry key.