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.
& "c:\users\jeremylikness\my documents\powershell\symbolsetup.ps1" -public
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.
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.
XFit/Bin/Releasefor the main XAP in X-Fit. If you have dynamic modules, you can copy the DLL and PDB files to this directory.
"c:\program files (x86)\internet explorer\iexplore.exe" http://localhost/xfit/
VSPerfCmd /start:sample /output:xfitdata /attach:4436
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.On Jul 14 2010 6:52 AMBy jlikness Silverlight, powershellWith 3 Comments