Muokkaa

Jaa


Instrumentation in Visual Studio (C#, Visual Basic, C++, F#)

This article describes the instrumentation tools in Visual Studio, which are used for collecting exact call counts and call times.

There are two types of instrumentation:

  • Static, which modifies the program’s files before it runs (VSInstr)

  • Dynamic, which uses a dynamic process where it doesn’t change the files. It loads the files to memory and then modifies them to collect the instrumentation info. Using the dynamic instrumentation tool, you get more accurate information, but for a smaller part of the program. You can investigate small sections of code.

Dynamic instrumentation is helpful because:

  • Static instrumentation breaks strong name signing. With dynamic instrumentation, this issue is avoided because instrumentation happens at runtime.

  • With static instrumentation, files need to be deployed in a specific order and the tool may not know where the files are. You need to manually run VSInstr. With the new instrumentation tool, you don’t have to go find the files. On a complicated program, finding all the files can be a difficult, manual process.

Instrumentation versus sampling

When it comes to profiling, there's two mechanisms of collecting data. Collection using instrumentation or collection using sampling. For detailed information, see Understanding performance collection methods.

Dynamic instrumentation tool

Instrumentation - Starting in Visual Studio 2022 version 17.5, the Instrumentation tool provides dynamic instrumentation for .NET Core, .NET 5+, and .NET Framework. This tool provides the best performance for instrumentation scenarios. Access this tool using the Performance Profiler (Alt + F2). For more information, see the following article:

Starting in Visual Studio 2022 version 17.6, the Instrumentation tool also supports C/C++, but uses static instrumentation (VSInstr).

To use this tool from the command-line, see the following article:

Instrumentation - Starting in Visual Studio 2019 version 16.9, the Instrumentation tool provides dynamic instrumentation for .NET Core, .NET 5+, and .NET Framework (not C/C++). This tool uses a version of VSInstr.exe that supports dynamic instrumentation. Access this tool using the Performance Profiler (Alt + F2). For DLLs, you need to use the command-line tool (VSInstr) instead.

Static instrumentation tool

VSInstr - Starting in Visual Studio 2022 version 17.6, the Instrumentation tool uses VSInstr for C/C++ support. VSInstr is also used for command-line scenarios and works for .NET Framework and C/C++ apps. For more information, see the following article: