Reputation: 5303
When viewing the .Net performance counters using the Performance tool I can see the web process performance counters listed (w3wp, w3wp#1):
However when I run the following code as Administrator:
var instanceNames = new PerformanceCounterCategory(".NET CLR Memory")
.GetInstanceNames()
.OrderBy(x => x);
foreach (var name in instanceNames)
{
Console.WriteLine(name);
}
This is the output I see:
Notice the w3wp counters are not listed. Does anyone know why this is the case and how I can fix it?
Upvotes: 1
Views: 1187
Reputation: 5303
The solution was you have to run the application in the same bitness as your website. As my website was 64 bit I needed to run the console application in 64 bit mode. To do this right click on the console application project, click properties in the Build tab untick the box that says "Prefer 32-bit".
Also when you collect the process id for the w3wp process by using the Process ID counter inside the .NET CLR Memory category it is zero to begin with. To get the process id you have to initialize the web site and make sure at least one garbage collection happens. As this was in my test code I could simply call GC.Collect
in the Application_Start
handler.
Upvotes: 3