These pages cover ANTS Performance Profiler 7, which is not the latest version. Help for other versions is also available.
Attaching to a running .NET 4 process
Published 03 December 2012
ANTS Performance Profiler can attach to a .NET 4 process which is already running. This feature allows you to start profiling your applications when performance problems are noticed, without having to restart the application from scratch.
This page explains how to do this, using a simple C# program (called Net4Process.exe), which counts down for 300 seconds.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Net4Process
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Countdown test process");
- int i = 300;
- int[] array = new int[301];
- while (i >= 0)
- {
- Console.WriteLine(i + " seconds");
- array[i] = i;
- i--;
- System.Threading.Thread.Sleep(1000);
- }
- }
- }
- }
- Start Net4Process.exe from the command prompt.
- When the countdown starts, open ANTS Performance Profiler.
- In the ANTS Performance Profiler Settings dialog, under Application Settings, select Attach to a .NET 4 process.
A list of the processes currently running is displayed with the .NET framework version that they use. Processes that are not .NET 4 processes are unavailable. - Select Net4Process and click Start Profiling.
- When the application has finished (or if you press ANTS Performance Profiler's Stop Profiling button), the results are shown in the call tree in ANTS Performance Profiler.
As expected, almost 100% of the time is spent in Main().
If you need to save results for analysis later, attaching ANTS Performance Profiler to a running process means that you can save just the results you need, helping to reduce the size of the results file. This is particularly useful for line-level timings for all methods.