Instrument your .NET applications in Visual Studio (C#, C++, Visual Basic, F#)

With the release of Visual Studio 2022 version 17.5, you can use the new dynamic Instrumentation tool. This tool shows the exact number of times your functions are called and is faster than the previous version of the Instrumentation tool. This tool supports .NET Core instrumentation without needing PDBs. Starting in Visual Studio 2022 version 17.6 Preview 2, the tool also supports C/C++.

The tool is similar to the CPU Usage tool except it's based on wall clock time instead of CPU utilization. For additional information on learning to use the Instrumentation tool effectively, see Improving Visual Studio performance with the new Instrumentation Tool.

Instrument your application

  1. Select Alt+F2 (or Debug > Performance Profiler) to open the performance profiler in Visual Studio.

  2. Select the Instrumentation check box.

    Screenshot showing Instrumentation tool selected.

    If you enable the Start with collection paused option before starting the profiler, data won't be collected until you select the Record button in the diagnostic session view.

    Note

    If the tool isn't available for selection, clear every other tool's check box because some tools need to run alone. To learn more about running tools together, see Using multiple profiler tools simultaneously.

    If the tool still isn't available, check that your project meets the preceding requirements. Make sure your project is in Release mode to capture the most accurate data.

  3. Select the Start button to run the tool.

  4. Select the items in your program to instrument.

    Screenshot showing Select items to instrument dialog.

  5. Select OK.

  6. After the tool starts running, go through the scenario you want to profile in your app. Then select Stop collection or close the app to see your data.

Analyze the Instrumentation report

Your profiling data appears in Visual Studio.

Screenshot showing .NET Instrumentation data.

The Instrumentation data view shows you a list of functions ordered by longest running, with the longest running function at the top under Top Functions. The Hot Path section shows you the call stack for the functions that are using the most time. These lists can help guide you to functions where performance bottlenecks are happening.

Click on a function that you're interested in, and you see a more detailed view.

The information available is similar to the CPU Usage tool, except that it's based on wall clock time and call counts instead of CPU utilization. This means blocked time such as time spent waiting for locks will show up in the instrumentation trace, unlike the CPU Usage tool. For detailed information on the views, see CPU Usage.