Tuesday, March 21, 2017

Visual Studio – Performance analysis tool

Diagnosing an application performance issues are crucial before blowing in production.

Usually to investigate performance problems, developer uses a simple stopwatch (System.Diagnostics.Stopwatch) measurement in debugging mode to analyse how long particular code block executed. But, adding stopwatch in every code block is a pain and time consuming action for developers.

To avoid adding stopwatch measurement in code block, Microsoft has introduced a Performance memory analysis tool since Visual Studio 2013.

Steps to use Performance analysis tool

1. Run the application in debugging mode
2. Set Breakpoint in required line of code
3. On Step over of each line, Visual Studio shows elapsed time at end of each line
4. Find more details from Debug Menu --Show Diagnostic Tools

Example

1. As per above screen, line number 56 took 71ms to run includes I/O time and CPU execution time ( which is highlighted with red pen)
2. To get accurate time, execute same code block multiple times using Set Next Statement ( Ctrl+Shift+F10 )
3. To get more details, click on elapsed time and see the following screen


Events window: It shows each line execution time after break point hit
Memory Usage window: It allows us to take snapshot and compare performance
CPU Usage window: It shows complete call-tree with Total CPU time


Happy Coding :)

No comments:

Post a Comment