Channels ▼

Gastón Hillar

Dr. Dobb's Bloggers

Visual Studio 2010 SP1 Beta 1 Enables Concurrency Profiling Features for Silverlight Applications

January 05, 2011

A month ago, Microsoft released Visual Studio 2010 Service Pack 1 Beta 1, also known as SP1 Beta 1. This Service Pack beta release allows Silverlight application developers to use the concurrency profiling features. This new feature is very useful when you want to optimize Silverlight applications for multicore hardware.If you work with Visual Studio 2010 Premium or Ultimate versions, you can use the concurrency profiling features for your Windows applications. However, when you create a Silverlight application and you try to launch the Performance Wizard you get the following message: "No launchable projects available to profile in the current solution." If you select the Concurrency option and activate the Visualize the behavior of a multithreaded application checkbox, you will just have the option to specify an executable (.EXE file) to profile. With Visual Studio 2010 SP1 Beta 1, this restriction disappears because you can select a Silverlight project as the target for profiling.

In "Silverlight 4 Makes it Easy to Count Logical Cores," I explained how to launch as many threads as the number of available logical cores in a Silverlight 4 application. The following snapshot shows the Performance Wizard in Visual Studio 2010 Ultimate with SP1 Beta 1 installed. SilverlightThreads is the Silverlight 4 project explained in the previously mentioned post.

Figure 1. A Silverlight 4 project as the target for profiling concurrency.

By default, a Silverlight application uses multithreaded code under the hoods. This means that the application uses multiple threads and you must take this into account while profiling concurrency. You will see all these threads in the results of the concurrency analysis. In addition, you will see the additional threads that you launch in your application by creating manual threads or injecting them through the thread pool services. The first time that you run a concurrency profiling session for a Silverlight project, you might get a bit confused because you will see too many worker threads. However, all the detailed information provided by the profiler makes it easy to focus on your threads.

It is very important to finish your application as soon as possible to avoid collecting unnecessary information. Once the code you wanted to analyze has finished its execution, close the Web browser with the Silverlight application. This way, your profiling session will provide valuable information.

The next screenshot shows an average CPU utilization of 52% for the Silverlight project. However, it is very important to notice that there are many seconds in the timeline where the average CPU utilization was 0% because the Silverlight application was idle. This situation usually happens when you need some time to close the Web browser. The profiler goes on collecting data during this time and reduces the average CPU utilization value. In "Dive Deeper than the CPU Utilization Graph to Check Efficiency," I've provided detailed information about the meaning of the information provided by the CPU utilization graph.

Figure 2. The CPU utilization graph for a Silverlight 4 project.

The following snapshot shows the Threads view. There are too many worker threads. However, just four worker threads are running the multithreaded code launched by the SilverlightThreads application:

* Worker Thread(5544) * Worker Thread(5784) * Worker Thread(5352) * Worker Thread(336)

Figure 3. The Threads View utilization graph for a Silverlight 4 project.

The following snapshot shows the Cores view with the results of profiling the SilverlightThreads project in a computer with a quad-core CPU without Hyper-Threading. The CPU has four logical cores, also known as hardware threads.

Figure 4. The Cores View for a Silverlight 4 project.

If you combine the concurrency profiling features with the information provided by the new Parallel Stacks window, you will understand the code that runs in threads in a Silverlight project and you will be able to profile it. The following snapshot shows the Parallel Stacks window with the code that each thread is running:

Figure 5. The Parallel Stacks window with information about the code that each thread is running in debugging session for a Silverlight 4 project with Visual Studio 2010 Ultimate.

However, you have to be careful because Visual Studio 2010 SP1 Beta 1 is a Beta version and it isn't compatible with Visual Studio Async CTP.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.