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

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.