I have just adding some Performance Counters to instrument some code and had a few issues that are worth knowing about.
I created two categories of counters using the following code:
//Create a category with a single counter
PerformanceCounterCategory.Create(
“categoryName”, “categoryDescription”,
PerformanceCounterCategoryType.SingleInstance,
“counterName”, “counterDescription”);
//Create a category with more than one counter
System.Diagnostics.CounterCreationDataCollection counterCollection System.Diagnostics.CounterCreationDataCollection();
counterCollection.Add(new System.Diagnostics.CounterCreationData(
“Name1,
“Description1”,
PerformanceCounterType.NumberOfItems64));
counterCollection.Add(new System.Diagnostics.CounterCreationData(
“Name2,
“Description2”,
PerformanceCounterType.NumberOfItems64));
// Create the category and pass the collection to it.
System.Diagnostics.PerformanceCounterCategory.Create(
“multicategoryName”,
“multicategoryDescription”, PerformanceCounterCategoryType.SingleInstance,
counterCollection);
...