Udostępnij za pośrednictwem


Collect .NET Framework memory allocation and lifetime data

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Visual Studio Profiling Tools support the collection of .NET Framework memory allocation and object lifetime data, which helps you detect memory-related performance issues in your application.

  • Data about .NET memory allocation includes the size and number of .NET Framework memory objects that were allocated.

  • Object lifetime data includes the size and number of .NET Framework memory objects that were reclaimed in the three garbage collection generations.

Note

Enhanced security features in Windows 8 and Windows Server 2012 required significant changes in the way the Visual Studio profiler collects data on these platforms. UWP apps also require new collection techniques. See Performance Tools on Windows 8 and Windows Server 2012 applications.

You can collect data by using either the sampling or the instrumentation profiling method.

  • When you use the sampling method, the profiler tracks all .NET memory allocations and objects that are generated by the process that was started or attached to.

  • When you use the instrumentation method, the profiler tracks only those .NET memory allocations and objects that are generated by the instrumented modules.

Important

When you are collecting .NET memory data (allocations, object lifetimes, or both) by using the sampling method, all user-specified sampling events are ignored, and the appropriate memory allocation events are used to collect data.

If you enable the profiling of.NET memory allocation, you also enable the Allocation View. If you enable the profiling of .NET lifetime data, you also enable the Objects Lifetime View. For more information, see Allocations View and Object Lifetime View.

For information about how to collect .NET memory data by using the Profiling Tools command-line tools, see Using .NET Memory Methods to Collect Memory Allocation and Object Lifetime Data in Using Profiling Methods From the Command Line.

To collect .NET memory data

  1. In Performance Explorer, right-click the performance session, and then click Properties.

  2. On the Performance Session Property Pages dialog box, click the General tab, and select the Collect .NET object allocation information check box.

  3. To collect .NET object lifetime data, select the Also collect .NET object lifetime information check box.

Common tasks

You can specify additional options in the Performance SessionProperty Pages dialog box of the performance session. To open this dialog box:

  • In Performance Explorer, right-click the performance session name, and then click Properties.

The tasks in the following table describe options that you can specify in the Performance SessionProperty Pages dialog box when you collect .NET memory data.

Task Related Content
On the General page, specify naming details for the generated profiling data (.vsp) file. - Collect .NET memory allocation and lifetime data
- How to: Set performance data file name options
On the Launch page, choose the application to start if you have multiple .exe projects in your code solution. - Collect tier interaction data
On the Tier Interaction page, add ADO.NET call data to the profiling run. - Collect tier interaction data
On the Windows Events page, specify one or more Event Tracing for Windows (ETW) events to collect with the sampling data. - How to: Collect Event Tracing for Windows (ETW) data
On the Windows Counters page, specify one or more operating system performance counters to add to the profiling data as marks. - How to: Collect Windows counter data
On the Advanced page, specify the version of the .NET Framework runtime to profile if your application modules use multiple versions. By default, the first version loaded is profiled. - How to: Specify the .NET Framework runtime

Instrumentation tasks

The tasks in the following table are options in the Property Pages dialog box that are specific to profiling with the instrumentation method.

Task Related Content
On the Binaries page, specify a location for the instrumented copies of the modules. By default, the original binaries are moved to a backup folder. - How to: Relocate Instrumented Binaries
On the Instrumentation page, exclude small functions from profiling to reduce the profiling overhead, profile JavaScript code in ASP.NET Web pages, and specify commands to run at a command prompt before and after the instrumentation process. - How to: Exclude or include short functions from instrumentation
- How to: Profile JavaScript Code in Web Pages
- How to: Specify Pre- and Post-Instrument Commands
On the CPU Counters page, specify one or more processor performance counters to add to the profiling data. - How to: Collect CPU Counter Data
On the Advanced page, specify any additional VSInstr.exe options that you want, such as options to include or exclude specific functions. For more information about VSInstr options, see VSInstr - How to: Specify additional instrumentation options
- How to: Limit instrumentation to specific functions

See also

Configure performance sessions How to: Choose collection methods Performance session properties