I am completely disabled (TM) by this: On a 64-bit Win7SP1 PerfMon , PerfMon seems to completely deny knowing the installed custom performance counters. I work with an existing code base that sets counters perfectly on production machines, but when I run it on my machine, when I run it using the counters I added, or if I run a completely contrived assembly (the meat of which is pasted below), I get seriously weird behavior.
It is probably the easiest way to describe the following code snippet:
var category = "SuperTest"; var counterName = "Test Counter 1"; var shouldInstall = true; if (PerformanceCounterCategory.Exists(category)) { shouldInstall = false; Console.WriteLine("{0} Category Exists. Overwrite? [n]", category); var input = Console.ReadLine(); if (bool.TryParse(input, out shouldInstall)) { PerformanceCounterCategory.Delete(category); } } if (shouldInstall) { var col = new CounterCreationDataCollection(); col.Add(new CounterCreationData() { CounterName = counterName, CounterType = PerformanceCounterType.NumberOfItems64 }); PerformanceCounterCategory.Create(category, "Test category.", PerformanceCounterCategoryType.SingleInstance, col);
At the first start, the category does not exist, and it continues to create the category and counter. I will kill the process, then open PerfMon . At the moment, I can add counter, see the category and counter, add it perfectly, and see how it sits at 0.000 . Fine. At this point, if I close PerfMon and open it again? I see that all the system performance counters are just fine, but all of my custom ones - as already mentioned, those that work in the products, those that I created based on these and far-fetched ones, simply disappeared.
Interestingly, if I run the code above, it will constantly inform me that the group exists. Diving deeper, a counter even exists. It seems strange to me. Leaving it still in an extinct state and making a cue from here , I can run: lodctr /R and they will return.
So it looks like I messed up my own performance counter store. My question has two parts:
- Is this what I am doing (performance counter storage corruption)?
- Since it is reproducible, is there anything that stands out in the code or in my process that I do to create this behavior?
In my opinion, this is somewhat different from other issues of "performance counters" because they exist, and I watch them disappear.