|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionA performance counter monitors the behavior of performance objects on a computer. These include physical components, such as processors, disks, and memory, and system objects, such as processes and threads. There are also a large number of performance counters created (and maintained) by the .NET common language run time environment, including % time spent in garbage collection, and total size of managed heaps etc. The behaviour of your system can be monitored by running the perfmon.exe utility which has the interface as shown above. You select the performance counters that you are interested in and they are graphed for you. Creating custom performance countersThe .NET framework includes two classes that you can use to interact with the performance monitor: Attribute for performance monitoringThe attached library contains two attribute derived classes, Associating a class with a performance counter categoryTo associate a class with a particular performance counter category, you decorate that class definition with a <PerformanceCounterCategory("Attribute Test", _
"Test of the performance counter utility library")> _
Public Class PerformanceCounterTestClass
'- - 8< - - - - - - - - - - - - - - - - - - -
Associating a property of a class with a performance counterTo associate a public property of your class with a particular performance counter, you decorate that property definition with a '- - 8< - - - - - - - - - - - - - - - - - - -
<PerformanceCounter("Value List Length", _
"The number of items in the value list", _
PerformanceCounterType.NumberOfItems32)> _
Public ReadOnly Property CurrentList() As Collection
'- - 8< - - - - - - - - - - - - - - - - - - -
There are overloaded constructors for the (Re)Creating the performance countersBefore you can assign values to the various performance counters, you need to create them. To do this, you pass an instance of your class (that has the attributes on it) to Private TestClass As New PerformanceCounterTestClass
'\\ Create and register the performance counter categories
PerformanceCounterUtilities.PerformanceCounterUtilities.
RebuildPerformanceCounterCategory(TestClass)
Updating all the performance counters from an instance of a classTo update all the performance counters associated with a class, call the PerformanceCounterUtilities.UpdatePerformanceCounter(TestClass)
Updating a single performance counter from a class and property nameTo update a single performance counter associated with a class property, call the PerformanceCounterUtilities.UpdatePerformanceCounter(TestClass, _
"Iterations")
Usage scenariosCustom performance counters are a great way of instrumenting your .NET applications in order to monitor the performance and diagnose any bottlenecks or problems with that application, and in the long term, they can save a great deal of stress and hair loss.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||