Performance Profiling Silverlight 4 Step-by-Step

It turns out you can profile Silverlight 4 applications. Really! But the steps are scattered about the web in bits and pieces, so I wrote this to pull them all together. I’m going to use my reference X-Fit application for this, but you can obviously insert your own. Here we go!

Set up PowerShell

Yeah, we’re going to make things a little easier and set up PowerShell. If you’re not familiar with PowerShell, don’t worry. Here is a decent description of PowerShell, but if you really want to get deep into it, read Wintellectual John Robbin’s blog which is full of goodness. Really the main thing you want to do is to enable script support in PowerShell, and get familiar with running scripts.

Set up your Symbol Server

We’re going to need a valid symbol server to make things work. If you’re not familiar with this, it’s basically a place that Windows debug can go to figure out symbols (labels, names, etc) for code as you are debugging, profiling, etc. John Robbins has a fantastic script that you can use to set this up.

  1. Get John Robbins’ script here (just copy it and save it to a file called “symbolsetup.ps1” and if I have to tell you without the quotes, you’re not ready to profile)
  2. Execute the script in PowerShell. You must specify the full path and add a flag. I do it like this: & "c:usersjeremyliknessmy documentspowershellsymbolsetup.ps1" -public
  3. This should set it all up for you. Beware! The first time you debug, you will have quite a delay as all of the symbols are downloaded – this only happens once.

Prepare your Application

To profile, you must compile the application in release mode. Yes, you read that correctly. The symbol server will provide all of the symbols and details necessary, but you must compile in release mode for this to work.

In our example, we’ll pull down the Reference X-Fit Application. Download it, unzip it, and build it in release mode.

While you can debug most applications from a test page, this application uses dynamic modules so it is best to publish it to a site. You can use your local development environment, but it’s easier if you just make an application in IIS. I’ll leave that to you, but when we profile, the parameter we’ll pass to launch it will be some type of URL.

Let’s Profile!

First, credits go to the Windows Profiler Team for their detailed post for this. It contains what I’m going to share here, but I was missing some of the setup.

Go to your start menu, navigate to Visual Studio 2010, Tools, and select the command prompt as an Administrator.

  1. Navigate to the release directory for the main XAP file. In this case, it is under XFit/Bin/Release for the main XAP in X-Fit. If you have dynamic modules, you can copy the DLL and PDB files to this directory.
  2. Open Task Manager and sort by image name. Note the PIDs of the existing iexplore.exe processes.
  3. Set up the profiling environment:
    vsperfclrenv /sampleon
  4. Launch a new process, passing the page you want to debug:
    "c:program files (x86)internet exploreriexplore.exe" http://localhost/xfit/
  5. Note the new IE process (Hint: you can also go into Visual Studio and choose “attach to process” to see the title/type of process to narrow down the correct one that is hosting the Silverlight application — don’t actually attach, just use this to get the process identifier)
  6. Start profiling the process (in this case, my PID was 4436):
    VSPerfCmd /start:sample /output:xfitdata /attach:4436
  7. Now go into the application and perform some actions. I created an account, then looked at my BMI, then updated my account and put in some errors and hovered over some information icons just to get a good sample
  8. End the session:
    VSPerfCmd /detach
    VSPerfCmd /shutdown
    VSPerfClrEnv /off

Examine the Data

Once I shut everything down, a new file was created called xfitdata.vsp. Now the fun part: analyzing the data. In Visual Studio 2010, you can go to File -> Open File and navigate to the VSP file to open it. You’ll see a message that it is analyzing the file. This may take several minutes, so be patient. If you have your output window open, you should see messages as the symbols are analyzed:

Probably the easiest way to filter the data is to go to the module view:

Then you can expand and see where the application is spending it’s time:

If you double-click on the higher level item, a window will open with the details including (if available) the source code.

There you have it … step-by-step profiling Silverlight 4.

Jeremy Likness

View Comments

  • You could also use a profiler that supports the SL 4 profiling infrastructure; most commercial profiler do that and my free one does as well. If nothing else, it is way easier to setup.
    Note: this is kind of a plug and please delete if you feel it is inappropriate.

  • OK, now you'll probably be seeing your downloads jump - the Twittersphere is quite excited about the tool! Thanks for sharing it.

Recent Posts

8-Step AWS to Microsoft Azure Migration Strategy

Microsoft Azure and Amazon Web Services (AWS) are two of the most popular cloud platforms.…

2 days ago

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

1 week ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

3 weeks ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

1 month ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

1 month ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago