Instrument and debug a Windows service, a serviced component, a .NET Remoting object, and an XML Web service.
Performance counters are Windows' way of collecting performance data from running processes. Microsoft Windows itself provides several hundred performance counterseach of which monitors a particular system parameter. In addition, the various .NET server products, such as SQL Server and Exchange Server, and applications, such as the .NET Framework, also publish their own custom performance counters. You might be familiar with performance counters from the Windows System Monitor utility, shown in Figure 9.37.
Windows organizes performance counters in categories. Each category defines a specific set of performance counters. For example, there are categories such as Memory, Processor, and PhysicalDisk. The Memory category has various counters, such as Available Bytes, Cache Bytes, and Committed Bytes.
Some categories are further divided into instances. For example, the Process category is divided into several instanceseach representing a running process on the computer. A new instance is added to the category whenever a new process is started and removed when a process is killed . Each instance can have performance counters (such as I/O Read Bytes/sec) that specify the activity of that particular process. Usually, all the instances in a category have the same list of performance counters. Of course, each of the performance counters has unique performance data associated with it.
You can view existing performance counters in a navigable format in Visual Studio .NET Server Explorer, as shown in Figure 9.38.
Note from Figure 9.38, .NET CLR Data, .NET CLR Memory, and so on nodes represent performance counter categories. The # Total committed Bytes, # Total reserved Bytes, and so on nodes are the performance counters in the .NET CLR Memory category. _Global_, aspnet_wp, devenv, and so on are the instances of the # Total committed Bytes performance counter.
The PerformanceCounter class allows you to read performance examples for processes that are running on a machine. By using this class, an application can even publish its own performance counter to inform the world about its performance level.
Table 9.8 lists some important members of the PerformanceCounter class.
Member | Type | Description |
---|---|---|
CategoryName | Property | Specifies the performance counter category name . |
Close | Method | Closes the performance counter and frees all the resources. |
CounterHelp | Property | Describes the performance counter. |
CounterName | Property | Specifies the name of the performance counter. |
CounterType | Property | Specifies the type of the performance counter. |
Decrement | Method | Decrements the value of the performance counter by one. |
Increment | Method | Increments the value of the performance counter by one. |
IncrementBy | Method | Increments or decrements the value of the performance counter by a specified amount. |
InstanceName | Property | Specifies the instance name. |
MachineName | Property | Specifies the computer name. |
NextSample | Method | Gets a sample for the performance counter and returns the raw, or uncalculated, value for it. |
NextValue | Method | Gets an example for the performance counter and returns the calculated value for it. |
RawValue | Property | Gets an example for the performance counter and returns its raw, or uncalculated, value. |
ReadOnly | Property | Indicates whether the performance counter is in read-only mode. |
RemoveInstance | Method | Deletes an instance from the PerformanceCounter object. |
The .NET Framework allows applications to create their own custom performance counters and publish their performance data. This performance data can then be monitored via the Performance Monitoring tool ( perfmon.exe ).
NOTE
Performance Counters on Remote Machines You can read existing performance counters on remote computers, but you can create custom performance counters only on the local machine.
Visual Studio .NET makes it easy for you to create new performance categories and counters: It provides the Performance Counter Builder Wizard, which is available via Server Explorer. In Step by Step 9.12, you create a Windows application that publishes its performance and allows you to manually increase or decrease its reported performance values.
STEP BY STEP9.12 Publishing Performance Data
|
REVIEW BREAK
|
Top |