The earlier parts of this series talked about Visual Studio 2015 improvements and enhancements. This article on Visual Studio 2015 will cover another interesting feature of Visual Studio 2015; i.e., Diagnostic Tool Window. We’ll have a glance over the new Diagnostic Window and try to cover the topic with practical examples, thus exploring how this diagnostic tool window has helped in debugging and monitoring.
You can learn more in the previous parts:
- Day #1: Code Assistance in Visual Studio 2015
- Day #2: Code Analyzers in Visual Studio 2015
- Day #3: Renaming Assistance in Visual Studio 2015
- Day #4: Code Refactoring in Visual Studio 2015
- Day #5: Debugging Improvements in Visual Studio 2015 (Breakpoint Configuration and New Error List)
- Day #6: Debugging Improvements in Visual Studio 2015 (Tool Window Support for LINQ and Lambda)
- Day #7: PerfTip in Visual Studio 2015
- Day #8: New Diagnostic Tool Window in Visual Studio 2015
Diagnostic Tool Window
The new Diagnostic Tools Window in Visual Studio appears whenever you run the application with debugging.
This Window provides an ample amount of information, which is very helpful when debugging the application. It contains a timeline across the top, that provides a temporal display of the application’s debugging session.
The Diagnostic Tool Window can be launched via Debug-> Show Diagnostic Tools option, as shown in the image, below:
Under the timeline are three important views.
- The debugger events view displays break point, output and IntelliTrace events.
- The Memory view displays the processor or memory usage in bytes.
- The CPU utilization view displays the percent of the CPU usage.
At the bottom of the Diagnostic Tools Window are the tabs with additional details and options. The Yellow arrow at the bottom shows the code being debugged is currently at a breakpoint.
This article will cover the different views of Diagnostic Tool Window, one by one. We’ll use the existing code base as a sample to explore the features. Place the breakpoints at two locations, as shown below. The existing Program.cs file that we have been using throughout the prior articles states:
Now run the Application and wait for the execution to pause at a break point. Now, open the Diagnostic tools or press Ctrl+Alt+F2. You get the following view of Diagnostic Tool Window:
The example of debugging session was 0.19 seconds in length, from the time of the application's start until the current break point and we are looking at about 5.5 seconds of that time, here in the timeline. The black bars here allow you to select a portion of the timeline.
The selected time interval, shown in White, is the area of the timeline that you want to focus on. Drag either Black bar to adjust the selection area. The other sections of this Window adjust based on the location of the Black bars. Since our selected area includes part of a Red line in the break point track, the list also displays the end of that break point line.
The debugger events view in the Diagnostic Tools Window displays the events that occurred during the debugging session. This view is broken into the tracks. The break events track shows the events which stopped the execution of the Application, such as breakpoints that were hit, stepping through the code or breaking exceptions. The bars indicate the amount of time the application was running in between the break events. The bars in this track are color coded as Red indicates a break point or breaking exception. Yellow indicates a step through the code and Blue indicates a break on operation.
The Blue bar indicates the time from the last break point, until the time that debugging session was paused, using the Break All feature.
Hover over a bar to view the elapsed time.
The IntelliTrace track shows all other events collected by IntelliTrace, such as ADO.NET calls, file access and so on. It is also color coded, as Black is used for important events, Gray for less important events, and Purple for the custom events.
The Process memory section of the Diagnostic Tools Window helps you to monitor the memory usage of the app while you are debugging. A memory usage tool was introduced in Visual Studio 2013 as a part of the performance and diagnostics hub. In Visual Studio 2015, this tool was merged into the Diagnostic Tools Window and enhanced. With the current memory usage tool, you can take a memory snapshot at any point of time and compare it against another snapshot.
In this sample debugging session, you can see there is one snapshot.
Using the memory usage tool helps you to analyze the cause of memory spikes or leaks. You can also view the heap information through memory usage Window.
The CPU utilization section of the Diagnostic Tools Window helps you to monitor the CPU usage of your Application, by viewing a live CPU graph.
This graph shows you how many CPU resources are used by the code. Looking at the CPU usage with the debugger events helps you to correlate spikes in CPU with the execution of the code, making it easier to debug CPU-related issues.
You can switch on CPU profiling for more detailed CPU usage statistics.
You can use the Diagnostic Tools Window that comes to aid in your debugging process, and improves productivity and performance.
In this article, we covered a very useful and critical feature of Visual Studio 2015 called Diagnostic Tools Window. We saw how the Diagnostic Tool Window can help you to debug your code and monitor CPU & memory usage too.