Skip to content

Instantly share code, notes, and snippets.

@jmcd
Created December 2, 2011 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcd/1423402 to your computer and use it in GitHub Desktop.
Save jmcd/1423402 to your computer and use it in GitHub Desktop.
A console app to print the current memory usage of all worker processes of an IIS app-pool.
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Web.Administration;
namespace WtfApp
{
internal class Program
{
private static void Main(string[] args)
{
var applicationPoolName = args[0];
var message = new StringBuilder();
for (;;)
{
var processes = new ServerManager().ApplicationPools
.Where(ap => ap.Name == applicationPoolName)
.SelectMany(ap => ap.WorkerProcesses)
.Select(wp => wp.ProcessId)
.OrderBy(processId => processId)
.Select(Process.GetProcessById)
;
message.Length = 0;
message.Append(DateTime.Now).Append(" ");
foreach (var process in processes)
{
message.AppendFormat("Id. {0} @ {1}MB ", process.Id, process.PrivateMemorySize64/(1024*1024));
}
Console.WriteLine(message.ToString());
Thread.Sleep(1000);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment