Attach to a Process
(Professional and Enterprise only)
Instead of having the profiler launch the process to profile, it is also possible to attach the profiler to an already running .NET Process.
There are two ways of attaching to a process: Attach using profiling API and Inspection only attach. Attach using profiling API allows object instances to be tracked between snapshots, which allows the profiler identify new and removed instances, which makes it easier to identify memory leaks. However, when using the profiler API, the profiler will be loaded into the process and this will affect the performance and memory usage of the profiler process. Inspection only attach on the other hand, only inspects the profiled process by investigating the memory in the process. This has the advantage that the profiled process is not affected by the profiler, but the profiler cannot track instances and how they are moved by the garbage collector.
For more information about profiling API attach, see Attach to Process using Profiling API.
The following steps should be performed to attach the profiler to a running process:
Select the
Attach to Process command from the File menu or Attach Profiler to Process from the Profiler menu if running under Visual Studio.
The “Attach to” wizard appears.
Select the process you want to attach to from the list of .NET processes and whether the process should be attached using the profiling API or using inspection only attach.
If you want to profile using the default settings, click Start to start the application.
If you want to modify settings, you can use the Next button to modify some common settings.
When you have decided on the settings, click Start to attach to the process.
Attach to Process using Profiling API
In order for .NET Memory Profiler and the NmpCore tool to attach to a process using the profiling API, the process must be running under .NET Framework 4.0. Additionally, unless .NET Framework 4.5 is installed, the concurrent garbage collector must not be enabled. This is normally not a problem when attaching to server processes (like ASP.NET running under IIS), since they are using the server garbage collector, which is not using concurrent GC. For a standalone program, the concurrent garbage collector can be disabled by modifying the application config file. To disable concurrent GC and run the program under .NET runtime 4.0, modify the config file so that it includes the following settings:
<?xml version="1.0"?>
<configuration>
<runtime>
<gcConcurrent enabled="false" />
</runtime>
<startup>
<supportedRuntime version="v4.0.30319" />
</startup>
</configuration>