How to: Generate Performance Statistics

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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:


    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.

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 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;
        PCset = 0;

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

This example requires references to the following namespaces: