Share via


How to: Generate Performance Statistics

The .NET Compact Framework contains performance counters for creating statistical reports about the performance of your application. The counters measure object allocation, garbage collection, collections, and other features and processes. You can generate a report about your application by turning a registry setting on and off.

For information about the performance counters, see Performance Counters in the .NET Compact Framework.

To generate performance statistics

  1. Set the following registry subkey value to 1:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\PerfMonitor

    See the code listing following this procedure for an example of setting the registry value.

  2. Run the application that you want to analyze for performance. Do not run any other .NET Compact Framework applications at the same time.

  3. Analyze the generated statistics file at the root of your device. The file has the same name as the currently running .NET Compact Framework application, with a .stat extension.

    You can import the data into a text editor or into Microsoft Excel by choosing Fixed width in the Excel Text Import Wizard dialog box.

  4. Set the registry subkey value to zero to turn off the performance counters.

Example

The following method turns the performance counters on or off by setting the registry subkey according to the value of the Boolean perfOn parameter.

' 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);
    }
}

Compiling the Code

This example requires references to the following namespaces:

See Also

Concepts

Performance Counters in the .NET Compact Framework