How much CPU is my web app consuming?
Introduction
When running a load test, adding IIS specific performance counters is a good idea (this post details the most important IIS and ASP.NET counters). However, sometimes, all you want is a quick look at the usage (CPU %) for just your web app, you can check it on your localhost. Cassini, Visual Studio’s built-in web server, runs under the process name – WebDev.WebServer40.exe. If you are running IIS 7 or above, the appropriate process name is w3wp.exe (so you would use w3wp as the instance name in the code below)
static void Main(string[] args)
{
// do not need the .exe in the instance name
// For Cassini, instance name = WebDev.WebServer40
// For IIS 7x , instance name = w3wp
PerformanceCounter myAppCpu =
new PerformanceCounter(
"Process", "% Processor Time", "WebDev.WebServer40", true);
Console.WriteLine("Press any key to stop...\n");
while (!Console.KeyAvailable)
{
double pct = myAppCpu.NextValue();
Console.WriteLine("WEB APP CPU % = " + pct);
Thread.Sleep(250);
}
}
This provides a quick console view of the processor usage – as you run your test.
Source Code Download
IIS CPU Usagedownload
Leave a Reply