32

Where are .NET 4.0 MemoryCache performance counters?

I am looking for their name and I can't find any.

Thank you,

1 Answer 1

76

That's a loaded question with a very long answer. I doubt it is going to be helpful, let's talk about the real problem you are trying to solve. Those performance counters have to be registered first before you can see them.

Start an elevated console prompt (right-click the shortcut and use Run as Administrator) and type these commands:

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
lodctr netmemorycache.ini

That adds the required registry entries so the MemoryCache can create these counters at runtime. Start your program so an instance of MemoryCache is created. Run Perfmon.exe, right-click the graph, Add Counters and pick from the added ".NET Memory Cache 4.0" category. Also select the instance of your program.

Sign up to request clarification or add additional context in comments.

8 Comments

THANK YOU VERY MUCH!!! This is exactly what I was looking for. It leaves me with another and more important question: Where is this documented? I searched everywhere for "netmemorycache.ini" and couldn't find a meaningful trace. I feel that I miss something big here, since entire MSDN does does not have any documentation related to this. In addition, is there any performance penalty with adding these counters? If there is, can I un-load them once I am done with performance analysis?
I don't know, I just figured it out myself. Took me a while. Don't worry about it, performance counters are very cheap. Looks like this question is answered, please close it.
I just marked it as answer. Thanks again. It would be a great help if you could share and tell how did you figure it out? I mean where was the clue?
Not just one. I studied the MemoryCache code. Then saw that the private field was null in a test program. Then discovered the exception that was raised when MemoryCache tries to initialize them. Then found out what the readOnly argument means for the PerformanceCounter constructor. Then found out that they need to be created up front. Then studied how other counters like that are used in the .NET framework. Then found google hits on how those get configured. Gave me the LODCTR hint, finding the .ini file to go with that was then easy from the filename.
yer a wizzard @HansPassant i have no idea on the planet how you knew the answer was this to the question that was asked
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.