Windows performance counters disappearing from PerfMon

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); // Magical voodoo line that may indicate my inexperience, but whose inclusion or // exclusion does not affect discernibly affect behavior. PerformanceCounter.CloseSharedResources(); } // Multithreading setup, each thread repeats block below infinitely: { System.Threading.Thread.Sleep((new Random()).Next(100)); try { var counter = new PerformanceCounter(category, counterName, false)); c.Increment(); } catch (Exception ex) { /* ... */ } } 

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.

+2
source share
2 answers

The problem probably lies in the computer and / or its configuration, and not in the code that you published. I faced the same situation and could not understand why the counters disappear when the performance monitor is opened. However, I can help you with this:

  • Perfmon will sometimes disable performance counters , marking it as disabled in the registry. A link can help you determine why the counters are disabled.

  • Monitoring counters can also be performed using the typeperf tool. In my experience, typeperf has not disabled the same perfmon counters, providing you with an alternative for monitoring your counters.

+2
source

Make sure you do not mix x86 and x64.

those. if your perf counters were created using the x64 process, make sure you also read them using the x64 process.

Also, try running as admin.

+1
source

All Articles