Using the Visual Studio Diagnostics Tools

The Diagnostics Tools of Visual Studio provide you with historical information about your application in a debugging session. Along with Visual Studio 2013, Microsoft first introduced the Performance and Diagnostics hub, which changed over time and was relaunched as Diagnostics Tools in Visual Studio 2015 with more limited options than the version currently available in Visual Studio 2019.

When you start a debugging session, the Diagnostics Tools window will automatically launch and appear side-by-side with your code window. If it is unavailable, you can launch it from the Visual Studio Debug | Windows | Show Diagnostics Tools menu or, press Ctrl + Alt + F2. The following screenshot shows this:

This window shows you detailed historical information about your application, called PerfTips, in the events graph and events table. It also allows you to correlate execution time with the memory and CPU utilization graph. You can take snapshots of the current memory utilization to enable/disable the CPU profiling in this screen:

In the preceding screenshot, check how the memory was utilized over time. The yellow arrowhead indicates the time when the Garbage Collector was called, either automatically by the system or forcefully from the code:

To view all of the events that were performed while you were debugging the context, switch to the Event tab. It gives you a new IntelliTrace experience in Visual Studio and saves your valuable debugging time. It captures additional events and useful information about the execution of your application. Hence, it allows you to identify the potential root causes of any issues. When an exception happens, it also maintains the history of the events where it occurred.

When you want to know more about a specific event, click on an item from the list and activate Historical debugging to set the debug window back to a time when the event occurred. You can then see the call stack, the values of local variables, and other important information that was available at the time when the event occurred:

To find out more about memory utilization, navigate to the Memory Usage tab. Here, you need to take snapshots of the current memory usages by clicking the Take Snapshot button, as shown in the preceding screenshot.

Using this tab, you can monitor the memory usage (increased/decreased) and identify memory issues while you are debugging your code. Clicking on the individual links in each item will give you more details about the snapshot and heap objects, as shown in the following screenshot:

The CPU Usage tab provides you details about CPU utilization and tells you how many CPU resources were used by your code. You can correlate this information with the CPU usage graph shown in the tool window and find out the spike where a higher utilization took place:

You should start CPU Profiling to grab this information about CPU utilization by the program currently in the debugging context.

If you spot a potential issue when debugging, you can check this tab to get the per-function breakdown to identify the problem. Double-clicking on any item will give you details about the call tree, as shown in the following screenshot:

This provides the following details about each function that is available in the call tree:

  • Total CPU %: This provides you with the CPU activity in the selected function and the functions it called. The information is provided as a percentage value.
  • Self CPU %: This provides the percentage of CPU activity in the selected function, but not in the functions where it has been called.
  • Module: This provides the name of the module where the call has been made.

By investigating these column values, you can easily identify the code block where CPU utilization was higher and, based on that, optimize your code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.216.174