Application Security Testing: An Integral Part of DevOps
Multi-core processors are here to say, and to stay competitive developers need to learn new tricks to utilize these swift chips. With the introduction of Microsoft Visual Studio 2010 and .NET Framework 4.0, Microsoft has given developers betters tools and class libraries to create multi-threaded applications. In this article, you are going to learn how you can profile your .NET applications with Microsoft Visual Studio 2010.
Even now with technologies like Task Parallel Library ( TPL ) and Parallel LINQ (PLINQ), writing scalable and high-performance multi-threaded applications still requires work. Luckily, Microsoft Visual Studio 2010 aims to make this process at least a little easier, especially when performance profiling is considered. The newest Microsoft Visual Studio contains a completely new feature called Concurrency Visualizer. This feature gives you a highly visual view to the performance of your .NET framework code.
The new profiling features are available in the high-end versions of Microsoft Visual Studio 2010. Both Premium and Ultimate versions contain the Concurrency Visualizer feature, but it is missing from the Professional version. Furthermore, the Concurrency Visualizer feature is only available on newer Windows operating systems. This means that you can only profile concurrency issues on Windows Vista and Windows 7; Windows XP users cannot use the feature. The technical reason for this is that the new profiling functions in Microsoft Visual Studio rely on the Event Tracing for Windows (ETW) functionality which is not available on Windows XP.
In this article, you are going to see a walk-through of using the Concurrency Visualizer in Visual Studio 2010 Premium and Ultimate. Note that although the new Concurrency Visualizer is only a small part of the overall profiling features in these versions, this article will only focus on the concurrency features not available in previously. Remember that you will need Windows 7 (preferably) to try these features as you are progressing.
Starting a Performance Session
To get started with the Concurrency Visualizer in Visual Studio 2010, you first need to create what is called a performance session. To do so, start Visual Studio, and open a project you wish to profile. Although there other ways to start a performance session, an easy way is to use the wizard. To launch this wizard, go to Visual Studio's Analyze menu, and choose the Launch Performance Wizard command (or press Alt+N, Z). This will bring up the Performance Wizard dialog box (Figure 1).
If you have used Visual Studio's profiling features before, for instance with Microsoft Visual Studio 2008, then you will immediately recognize this dialog box. In Microsoft Visual Studio 2010, this dialog box contains a new option at the bottom called Concurrency. When you select this option, you will have two additional choices: to collect contention data and visualize threads. Once you have made your pick, click Next. (Initially, you might wish to select both options to see what kind of results you get.)
In the second step of the wizard, you are given the option to select the application you want to profile. Since you already have a project open, then the default option will usually be correct. However, you also can profile any application running or on disk, or select the correct project if your Microsoft Visual Studio solution contains more than one project.
In the third and final step of the wizard, you can select whether you want to start profiling immediately. This is usually what you want to do, so by simply clicking Finish, your selected project will start. Once the application has started, start working with it as you normally would. Note that while your application is running, Microsoft Visual Studio will tell you that a profiling session is in progress.