Performance Counters

The Windows operating system itself supplies a large number of performance counters that monitor such areas as virtual memory usage, IO and file system operations, network operations, and the amount of CPU time the processor spends on each process. Most of these counters are able to break down the information on resource usage that they supply according to which running process owns the resources. In addition, an API is available that makes it possible for other applications to register and implement additional performance counters in order to monitor items specific to that application. The CLR has taken advantage of this feature to register a large number of performance counters that supply information about the internal operation of the CLR. For example, these counters monitor the work done by the JIT compiler, the operation of the garbage collector, and the amount of memory allocated on the managed heap, .NET Remoting operations, and so on. Although these counters are implemented by the CLR rather than the operating system, the distinction isn't relevant as far as reading these counters is concerned. You use the .NET counters just as you would use any other counters.

Both the Task Manager and the PerfMon performance monitoring tool display data which has been read from performance counters. In addition, there are a number of framework classes in the System.Diagnostics namespace that allow you to access performance counters very easily. The most important of these classes are PerformanceCounter and PerformanceCounterCategory. These objects serve partly as managed wrappers for the native API calls that can be used to read data left by performance counters and partly as a means for you to implement your own performance counters. Indeed, one of the nicest things however about PerformanceCounter and related classes is how easy they make it for you to register your own performance counters. For obvious reasons, a performance counter should be able to gather its data without consuming any significant resources or CPU time itself - and implementing that ideal takes a lot of work. Remember I said earlier that performance counters will normally tend to be implemented using memory mapped files. That all means quite a bit of work to implement a performance counter in unmanaged code, but the .NET Framework classes will do all that work for you under the hood, so that implementing your own performance counter in managed code is incredibly simple. In this chapter we'll work through examples that show both how to read existing counters and how to implement your own.



Advanced  .NET Programming
Advanced .NET Programming
ISBN: 1861006292
EAN: 2147483647
Year: 2002
Pages: 124

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net