mgoldin's blog

A blog about Profiler in Microsoft Visual Studio.

VS2010: Silverlight 4 profiling

VS2010: Silverlight 4 profiling

Rate This
  • Comments 30

Did you know that Visual Studio 2010 Profiler allows you to profile your Silverlight 4 applications? You didn’t? It does.

This feature, however, is only partially integrated with Visual Studio UI, and you need to use command line tools to collect the data. After that, you can open the resulting .VSP file in Visual Studio as you normally do after other types of profiling, and enjoy rich visualization experience while investigating your performance problems.

Yes, we know it is not as cool as clicking VS buttons. We are working on a better experience. Yet I thought it is worth to emphasize that there is a way to use command line tools for customers that seek performance improvement in their Silverlight applications.

Let assume you develop an application like Breakout Game.

image 

You compile it inside VS2010, run it, and want to profiler it. Performance Wizard tells you that this project can not be launched by the profiler. Alas. Time to go to the command line tools. Click you Start button, go to All Programs and find there Microsoft Visual Studio 2010. There, go to Visual Studio Tools and launch a Visual Studio Command Prompt (2010).

image

This command line window has predefined PATH that includes profiler command line tools:

image

Now go to the directory where your Silverlight binaries are compiled:

>cd c:\Breakout\Breakout\Bin\Release

We are ready to start our profiling session.

  1. VSPerfClrEnv /sampleon
  2. "c:\Program Files (x86)\Internet Explorer\iexplore.exe" C:\Breakout\Breakout\Bin\Release\TestPage.html
  3. VSPerfCmd /start:sample /output:MyFile /attach:<PID of iexplore.exe process>
  4. Run your scenario
  5. VSPerfCmd /detach
  6. VSPerfCmd /shutdown
  7. VSPerfClrEnv /off

Steps above require some explanation. In 1 – you prepare environment that is needed for Silverlight profiling, and in 2 you start your hosting process (iexplore.exe, in our example) within that environment. This is essential, as if you start IE by clicking an icon on your desktop, you will get no Silverlight profiling data at the end. Step 3 starts profiler in Sampling mode, and attaches it to the process of your choice. Keep in mind that you might have multiple IE processes running, so you need to choose one that runs your code. If you are not completely sure which one is it, or if your code runs in several IE processes – well, attach to all of them! You can do it either running “VSPerfCmd /attach:<PidN>” several times, or enumerating all PIDs in a single command: “VSPerfCmd /attach:PID1,PID2,PID3”. After profiler is attached, you run your scenario in step 4, and detach profiler from all target processes in step 5. Detaching is not enough, as you need to shutdown the profiler in order to finalize your result file (step 6). Step 7 cancels changes of the environment that are made in step 1.

It could be that you need to profile your application from the very beginning. In this case steps 2 and 3 can be combined into one, where you launch IE under profiler:

VSPerfCmd /start:sample /output:MyFile /launch:"c:\Program Files (x86)\Internet Explorer\iexplore.exe" /args:”C:\Breakout\Breakout\Bin\Release\TestPage.html“

The caveat here is that if IE process spawns a child process that will run your application, the profiler will be still attached to the “father” IE process, as it doesn’t re-attach itself automatically to spawned processes. You may, however, eliminate creation of child processes by IE8 through the registry, modifying TabProcGrowth value.

Please make sure that you run all the above steps from the directory where your binaries are located. Until we complete the integration of this feature with VS, your function names will not be properly resolved otherwise.

You can kill you IE process now. Open the MyFile.VSP in VS2010 as you would do normally for profiling results.

image

Formally, that would conclude an official support of Silverlight profiling in VS2010 – Sampling mode through command line tools.

However, if you want to try .NET memory or concurrency resource contention profiling of your Silverlight application – I won’t stop you. This is not currently supported and tested modes of work, but they might work for you and help you to see your performance problems from a different angle.

For .NET memory profiling, use “VSPerfClrEnv /samplegc” or “VSPerfClrEnv /samplegclife” in your step 1 to get either allocation profiling or allocation and lifetime profiling.

For concurrency resource contention – use “/start":concurrency,ResourceOnly” in the step 3 above.

Oren Nachman from Sliverlight team is another excellent source for Silverlight profiling information. In his great article he provides several additional tricks and options that you can find quite useful.

Enjoy! 

Comments
  • Got it. Tried the same steps as before, worked using both VS test web server and IIS. I might have entered the wrong directory. Thanks.

  • SL4 sampling works great. How to get instrumentation to work with SL4? Is it supported?

  • Hi Xsun! Glad it works for you. No, instrumentation is not supported currently.

  • I can succesfully attach to the IE process, but when I start to use my app IE crashes. What are my next steps?

  • Hi Eli, sorry it took so long to reply to you (MSDN blog comments were disabled for the site maintenance). Can you please try to use SLLauncher.exe instead of IE for your application. Does it have the same problem? Does your application, btw, works with drop shadows?

  • I had a similar experience as Eli, when I try to profile my app, it crashes out. The sample app worked just fine. Honestly I gave up trying to make my app work, but didn't know that running SLLauncher was an option for an In-browser app so I'll try that I guess...

  • Hi CUrwiler! Thanks for your comment and please let us know if usage of SLLauncher helps you.

  • I have the same problem - for anything but the simplest Silverlight apps, IE crashes within 15 seconds or so.

    Any advice would be appreciated.

  • Ritchie, CUrwiler, Eli - can you please try to use /timer option of VSPerfCmd to modify frequency of sampling? I wonder if change of sampling timing will allow to skip a problematic code area.

    This issue is also being discussed on profiler forum: social.msdn.microsoft.com/.../14be439a-ebf1-445b-8492-62010b945f33

    Please add there any information you have. Thanks a lot for your help!

  • I'm experiencing the same problem when the profiler attaches to the IE process. I have updated the frequency of sampling but it seems that increasing the interval is not the solution because the profiler does not capture enough data.

    Did you solve the problem? Are there any updates from the SL team on this issue?

  • Hi,

    I tried running the above commands and got the error that 'MyFile.vsp' cannot be created since Access is denied. I know this might be a very basic question but can I know where this file is getting created so that I can get permission on that folder or can I change the path where this file gets created.

    Thanks in advance,

    Hiral

  • The only way this worked for me was to set the TabProcGrowth to 1 instead of 0.  At 0 or absent, IE8 always crashed within a second or so.

  • Scratch that...I had to enable the debug symbols in VS and set the TabprocGrowth to 0.  Now it's working...sheesh.

  • Hi, I'm trying to use profiling in instrumentation mode. I don't see help anywhere for this. Could you briefly give the commands for this mode as well?

  • Hi, I have the same question as Uday: need to know how to profile instrumentation of a Silverlight project. I have search around and tried many ways, but no luck.

    Is instrumentation supported now? If yes, what are the steps?

    Thanks a lot!

Page 2 of 2 (30 items) 12
Leave a Comment
  • Please add 7 and 6 and type the answer here:
  • Post