What's New in .NET Memory Profiler 5.7?

The major new features of .NET Memory Profiler 5.7 are:

Improved support for .NET Core 3.x and .NET 5.0

This includes a new debug symbols reader with support for portable PDBs, delegate target method identification, and WPF profiling support.

New implementation of debug profiling

The new implementation makes use of the debugger API available in Visual Studio 2015 and later, and no longer relies on undocumented behavior that could potentially cause problems (support for Visual Studio 2012 and 2013 has been dropped in version 5.7).

Debug profiling
Click on image to magnify.

  • Supports both 32- and 64-bit processes
    Previous implementation ran within the Visual Studio process and was limited to debug only 32-bit processes.
  • Handles more debug targets
  • Allows both debugger attach and profiler attach
    Previous implementation required that the the process was started with both debugging and profiling enabled. Now the debugger can be attached to a profiled process, or the profiler can be attached to a debugged process.

New implementation of unit test profiling

The new implementation is based on the new unit test data collector (NmpDataCollector) and supports the latest releases of Visual Studio 2019 and Visual Studio 2019 Preview, as well as Visual Studio 2017 (this feature is not implemented in Visual Studio 2015).

With the new debug profiling implementation, it is now also possible to debug unit tests that run under the profiler.

NOTE! Even though the unit test profiling is based on NmpDataCollector, it is not required to install the NmpDataCollector package to run unit tests under the profiler within Visual Studio.

The screencast below shows how unit tests can be run under .NET Memory Profiler.

Run tests using the Visual Studio Test Explorer
Click on image to play demo.

Unit test data collector for VSTest

NmpDataCollector is a VSTest data collector that can be added to a unit test project. It is available as a NuGet package and makes it very easy to run unit tests under the profiler within the build process, e.g. a CI/CD pipeline.

The data collector is enabled by adding "NMP Data Collector" to the .runsettings file:

<?xml version="1.0"?>
<RunSettings>
    <DataCollectionRunSettings>
        <DataCollectors>
            <DataCollector friendlyName="NMP Data Collector" />
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

Profiler sessions can be included as attachments to the test session or individual test cases by enabling the configuration options: SendSessionForTestCase and SendSessionForTestSession (available options are Always, WhenFailed, and Never).

The configuration below will always attach the profiler session to the test session, and additionally attach profiler sessions to each failed test.

<?xml version="1.0" ?>
<RunSettings>
    <DataCollectionRunSettings>
        <DataCollectors>
            <DataCollector friendlyName="NMP Data Collector">
                <Configuration>
                    <SendSessionForTestSession>Always</SendSessionForTestSession>
                    <SendSessionForTestCase>WhenFailed</SendSessionForTestCase>
                </Configuration>
            </DataCollector>
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

Use the MemProfiler.BeginTest API to associate profiler snapshots with a unit test:

[TestMethod]
public void TestMethod()
{
    Assert.IsTrue(MemProfiler.AreAssertionsEnabled);

    using( MemProfiler.BeginTest(nameof(TestMethod));
    {
        // Do test...
    }
}

More information about the NmpDataCollector will be provided soon.

Hybrid inspection snapshots

Normally the profiler will try to allow the runtime to garbage collect as many instances as possible before collecting a snapshot. This significantly reduces the risk of falsely identifying instances as memory leaks. However, when investigating and optimizing memory utilization, e.g. using the heap utilization tracker, it is better to get information about the actual memory usage at the time of the snapshot.

The new inspection snapshot will collect the memory usage information as it is, including unreachable instances and no prior garbage collection. This is the same type of snapshot that is collected when doing inspection profiling, but with all the additional information that is available for a standard snapshot, e.g. allocation call stacks.

Heap utilization after inspection snapshot
Click on image to magnify.

Identification of delegate target Method

When profiling a process running under .NET Core 3.0 or later, the profile will identify the target Method of a delegate. This will make it easier to identify the reason why a delegate was created or why it has not been removed. This is especially important when allocation call stack information is not available, e.g. when attaching or investigating a memory dump file.

Identification of delegate target method
Click on image to magnify.

WPF cleanup support in .NET Core 3.x and .NET 5.0

As part of the memory cleanup the profiler tries to perform before collecting a snapshot, it triggers the cleanup of stale data bindings in WPF. This was implemented in .NET Memory Profiler 5.5, but caused problem when profiling a WPF application running under .NET Core 3.0 or later. Now WPF cleanup is fully supported under .NET Core 3.x and .NET 5.0.

MemProfilerInstaller5_7_11.exe
(72,224 KB, v5.7.11, November 3, 2020)

© Copyright 2001-2020. SciTech Software AB
All rights reserved.

CONTACT INFO

SciTech Software AB
Ynglingavägen 1-3
SE-177 57 Järfälla
Sweden

E-mail: mail@scitech.se
Telephone: +46-706868081