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
//Create a category with more than one counter
System.Diagnostics.CounterCreationDataCollection counterCollection System.Diagnostics.CounterCreationDataCollection();
// Create the category and pass the collection to it.
The problem I had was the new performance counters did not show up correctly in PerfMon, but seemed OK from Visual Studio. In PerfMon I was seeing the single counter category OK but the multi counter category was only showing the first counter.
If I sent data to one of the multi category counters it seemed to go OK but in Perfmon I saw nothing. If I sent to the single category counter it showed up on both the single and multi graph in PerfMon.
The fix was simple, unload PerfMon completely between tests and all is OK. Just loading the Add Counter dialog IS NOT ENOUGH.
Also it is worth calling
when adding or deleting categories as this removes stale data that can also be a problem.