StudioTools: Code Profiling

StudioTools includes easy to use line level code profiling features that measure both performance and memory utilization simultaneously as part of the unit testing process. This information will help you better understand the implications of your design choices and identify performance problems at the unit level. The performance profiler tells you how long methods and individual lines of code take to execute while the memory profiler keeps track of how created objects and managed heap usage.

Profile your code from within Visual Studio itself

StudioTools performance and memory profiling features work inside of Visual Studio, meaning you don't have to launch a separate application or turn your attention away from the code. Profiling results are display in simple, sortable summary reports as well as through flags and markers in the editor itself, making it easy to spot problem areas. StudioTools lets you practice continuous performance testing while you code and test, unlike stand alone profiling tools that tend to get dragged out only after problems are detected.

Unit level profiling

It is not unusual for developers to use test timings as a sort of poor-man's profiler. Considering how expensive and difficult most profilers are to use, it's a practical decision &emdash; if not always the most accurate one. StudioTools splits the difference between this approach and expensive, stand alone code profiling applications. StudioTools includes an easy to use memory and performance profiler that gathers line level timings, total times, average times, hit counts, object creations, and memory allocation information just like an expensive profiler, but does so at the unit test level. It's profiling from the bottom up.

By including profiling information in your unit test results, you'll gain valuable feedback about the relative performance of your application's components. Because each line and method reports its share of runtime, you'll find surprising results about what does and doesn't take lots of time or memory. It's educational, and will help you build up a measured foundation of performance tuning knowledge, rather than relying on straight guessing and rules of thumb. And best of all, it's automatic as part of your testing process and not another task you must disengage from programming to perform.

Targeted performance analysis

StudioTools also useful for targeted performance profiling. To investigate particular performance questions, you simply create test cases that exercise potentially slow areas of code. This is a simple, elegant alternative to writing throw-away test programs that calls your code. This approach is also more convenient, because you can pack these performance tests into a separate DLL and save them, allowing you to track your performance over time. Test Explorer's category and project filters make it easy to omit any long running performance tests from your every day testing runs.

Since performance tuning almost always comes down to the little things, unit level performance testing is a more precise and easier method of profiling than setting up a large external profiler. If you can make your classes and components fast at the unit level, you are well on your way to having a high performance application.

Surprising speed you'll appreciate

The StudioTools profiler is a fast and easy way to gather performance statistics. Instrumentation happens automatically at runtime, so there's no need make any changes to your code, you don't even need to recompile. If you've used other profilers, you know they can increase the runtime as much as 700%, making them aggravatingly slow to use. StudioTools won't slow you down as much as you'd think, you'll be surprised at just how fast it is. A typical project will experience an increase in runtime of only about a 35-40% while profiling. When working with smaller projects or individual test cases this increase goes practically unnoticed.

Profiler results panel

Memory and performance profiling results are displayed in their own report panels that lets you browse, sort, and analyze the results of your code profiling across the entire solution. Sorting and filtering controls make it easy to focus in on suspect classes or methods. Click on any method or class to navigate to it in the editor.

memory profiler

View profiling feedback in the editor

Profiling results are also visible in the editor itself. Coverage markers indicate which lines were hit by the last run. Hover your mouse over a coverage marker to see profile information for that line, including how many times it was hit, its average run time, and the amount of memory consumed.

Your worst performing methods will be flagged in the editor to show you the relative impact of each line code to the total method runtime. Thermometer bars in the gutter beside the method's lines indicate the percentage of runtime spent on that line. This makes it easy to spot your choke points. You can control the percentage of runtime cut off for triggering performance markers by adjusting the slider in the Performance Profile panel. For example, if set at 10%, only those methods that represent 10% or more of your total runtime will be flagged with performance markers.

timing bars

Tracking memory usage and object allocations

In addition to timing information, the StudioTools profiler also tracks the amount of memory used by each line of code, as well as the number of objects allocated. You'll be surprised how expensive and memory intensive common operations area, and will gain valuable insight into improving the memory efficiency of your application. Memory utilization is presented in the Memory Profiler panel, as well as the Visual Studio editor.

Fully configurable color schemes

If you would prefer a different color scheme, you can choose your own colors from the StudioTools section of the Visual Studio options panel. This is especially helpful if you suffer from red/green color blindness!

Export results as XML

You can export your application's coverage information in XML format. This makes it easy to generate coverage reports, track coverage over time, and collect other metrics. From the Coverage Profiler's file menu, just select Export as XML.