Share via


Using Performance Counters

Download sample

This sample demonstrates how to access Windows Communication Foundation (WCF) performance counters and how to create user-defined performance counters. This sample is based on the Getting Started Sample.

NoteNote:

The setup procedure and build instructions for this sample are located at the end of this topic.

In this sample, the client calls the four methods of the ICalculator service. The client continues to do this until it is interrupted by the user. The service remains unchanged.

Performance counters are enabled in the diagnostics section of the Web.config file for the service, as shown in the following sample configuration.

<configuration>
  <system.serviceModel>
    <diagnostics performanceCounters="All" /> 
  </system.serviceModel>
</configuration>

This task can also be done using the Configuration Editor Tool (SvcConfigEditor.exe).

When performance counters are enabled, the entire suite of WCF performance counters is enabled for the service. The .NET Framework automatically maintains performance data at three levels: ServiceModelService, ServiceModelEndpoint and ServiceModelOperation. Each of these levels has performance counters such as "Calls", "Calls per Second", and "Security Calls Not Authorized".

To set up, build, and run the sample

  1. Ensure that you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.

  2. To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.

  3. To run the sample in a single- or cross-machine configuration, follow the instructions in Running the Windows Communication Foundation Samples.

To view performance data

  1. Start the Performance Monitor Tool by clicking Start, Run…, enter perfmon and click OK, or from Control Panel, select Administrative Tools and double-click Performance.

    NoteNote:

    You cannot add counters until the sample code is running.

  2. Remove the performance counters that are listed by selecting them and pressing the Delete key.

  3. Add WCF counters by right-clicking the graph pane and selecting Add Counters. In the Add Counters dialog box, select ServiceModelOperation 3.0.0.0, ServiceModelEndpoint 3.0.0.0, or ServiceModelService 3.0.0.0 in the Performance object drop down list box. Select the counters you want to view from the list.

    NoteNote:

    There are no WCF performance counters for a service if there are no WCF services running on the machine.

To use the Configuration Editor to enable counters

  1. Open an instance of the SvcConfigEditor.exe.

  2. On the File menu, click Open and then click Config file….

  3. Navigate to the sample application's service folder and open the Web.config file.

  4. Click Diagnostics on the Configuration tree.

  5. Toggle Performance Counter in the Diagnostics window to show 'All'.

  6. Save the configuration file and exit the editor.

Footer image

Send comments about this topic to Microsoft.
© Microsoft Corporation. All rights reserved.