HOW TO:產生效能統計資料

更新:2007 年 11 月

.NET Compact Framework 包含效能計數器,可建立關於應用程式效能的統計報告。計數器會測量物件配置、記憶體回收、集合,以及其他功能和處理序。您可以開啟和關閉登錄設定,以產生關於應用程式的報告。

如需效能計數器的詳細資訊,請參閱 .NET Compact Framework 中的效能計數器

若要產生效能統計資料

  1. 請將下列登錄子機碼 (Subkey) 值設為 1:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\PerfMonitor

    如需設定登錄值的範例,請參閱這個程序之後的程式碼片段。

  2. 執行要分析效能的應用程式。請勿同時執行其他的 .NET Compact Framework 應用程式。

  3. 分析產生在裝置根目錄的統計資料檔。檔案的名稱和目前執行的 .NET Compact Framework 應用程式相同,副檔名則為 .stat。

    您可以將資料匯入至文字編輯器,或在 Excel 的 [文字匯入精靈] 對話方塊中選擇 [固定寬度],將資料匯入至 Microsoft Excel。

  4. 將登錄子機碼值設定為零以關閉效能計數器。

範例

下列方法會根據布林值 (Boolean) perfOn 參數的值,設定登錄子機碼值以開啟或關閉效能計數器。

' Call this method with True to 
' turn on the peformance counters, 
' or with False to turn them off.
Private Sub SetPerfCounters(perfOn As Boolean)

    ' Specify values for setting the registry.
    Dim userRoot As String = "HKEY_LOCAL_MACHINE"
    Dim subKey As String = "SOFTWARE\\Microsoft\\.NETCompactFramework\\PerfMonitor"
    Dim keyName As String = userRoot & "\" & subKey

    Dim PCset As Integer

    If perfOn = True Then
        PCset = 1
    Else
        PCset = 0
    End If

    ' Set the registry value.       
    Try
        Registry.SetValue(keyName, "Counters", PCset)
        If perfOn = True Then
            MessageBox.Show("Performance Counters On")
        Else
            MessageBox.Show("Performance Counters Off")
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub
// 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);
    }
}

編譯程式碼

此範例需要下列命名空間的參考:

請參閱

概念

.NET Compact Framework 中的效能計數器