Click here to Skip to main content
Click here to Skip to main content

Performance Wizard for Silverlight

, 22 Dec 2010
Rate this:
Please Sign up or sign in to vote.
Profile Silverlight applications performance directly through Visual Studio

Introduction

I had written this article on my blog and thought of posting it on CodeProject too.

Article

Microsoft has released the first service pack for Visual Studio 2010. Although the service pack is marked as beta it comes with a “go live” license. Along with it, two other service packs are released - Team Foundation Server 2010 SP1 Beta and .NET 4.0 SP1 Beta. For Silverlight developers, they have packed two updates in the Visual Studio 2010 SP1 Beta.

  1. Silverlight 4 tools for Visual Studio 2010: “The Silverlight 4 tools are now included along with Silverlight 3 support”, all it means is that you will not have to install Silverlight 4 tools separately.
  2. Performance Wizard for Silverlight: This will enable the users to profile the Silverlight application performance directly through Visual Studio, user can create profiling reports and save them.

You can get the download links from Brian blog, he has nicely detailed all important updates in the service packs http://blogs.msdn.com/b/bharry/archive/2010/12/07/vs-tfs-2010-sp1-beta-has-released.aspx.

Once you have downloaded the web installer, be patient as the install will take some time to download the packages and install. For me, the process took around an hour from start to finish. After successful installation, you will be asked to restart your computer. Now your Visual Studio is all set to start profiling your Silverlight application using the wizard.

The Performance Wizard is very simple. Let us go step by step through it, open an existing Silverlight project or create a new project. To launch the ‘Performance Wizard’, go to the main menu find Analyze –> Launch Performance Wizard…

1.png

Performance wizard page 1 of 3 should be displayed, CPU Sampling must be selected by default if not the check mark the radio button before CPU Sampling.

2.png

Performance wizard page 2 of 3 - on this page you will find a list of projects depending on the structure of your solution. Typically for a Silverlight project, you will find the Silverlight application and the web application in the list, select your Silverlight application and click the ‘Next’ button.

3.png

Performance wizard page 2 of 3 is just a summary that says all the information needed has been collected. Make sure that on this page you have the check mark on the check box labelled as Launch profiling after the wizard finishes. When you click finish, the application should open in your default browser.

4.png

If you are not running as administrator, you might get an error saying “Unable to open profiler driver, would you like to upgrade credentials ..“ . Just click ‘yes’ and provide admin credentials if needed.

5.png

Once the above steps are done, the Performance Explorer with be populated with a structure similar to the image below. The performance wizard has created two folders, Reports and Targets.

6.png

Ok, now let's do a simple performance test. Let us create a simple application and see how the performance report looks like. Create a Silverlight application. In your main page, add a button and on the click of the button, we should have a function that does some kind of CPU intensive activity. I have simply created a nested loop to keep the CPU busy for a while, but you can write any code that will be CPU intensive.

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
  for (int i = 0; i < 100000; i++) 
  { 
     for (int j = 0; j < 10000; j++) 
     { 
     } 
   }
}

Now follow the steps shown above to generate a profiling report using the wizard, run the project and click on the button a couple of times and then close the browser. Visual Studio will bring up the visual report based on the samples collected during the performance analysis. THe below figure shows the result of my test, one can clearly identify in the graph the spike in CPU during the first and second click. An interesting fact is that Studio will automatically show a call tree of the method that is expensive in terms of resources. For our case, the event handler Button_Click() does an expensive for loop and Studio was able identify the method and display the call hierarchy.

7.png

Points of Interest

History

  • 22nd December, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

vikas amin
Software Developer (Senior)
India India
My name is Vikas Amin ,my childhood dream was to be a rocket scientist so many times ended with burned hand meshing with firecracker rockets. Now I mesh with computer's using C#,VC++,C,C++,VB,ASP,Silverlight,WPF,WCF,Assebly language some vbscript and javascript.

Comments and Discussions

 
Generalnice one PinmemberPranay Rana23-Dec-10 21:53 
GeneralRe: nice one Pinmembervikas amin28-Dec-10 8:00 
GeneralMy Vote of 5 PinmemberRaviRanjankr23-Dec-10 3:34 
GeneralRe: My Vote of 5 Pinmembervikas amin28-Dec-10 8:00 
GeneralMy vote of 5 Pinmemberprasad0222-Dec-10 18:32 
GeneralRe: My vote of 5 Pinmembervikas amin23-Dec-10 3:17 
Thank you Prasad

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 22 Dec 2010
Article Copyright 2010 by vikas amin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid