VS2010: Silverlight 4 profiling

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.


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).


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


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.


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.


Comments (30)

  1. MarkRi says:

    I have followed your directions with your Breakout source code and I cannot produce a profile that contains samples from the Breakout code. I see a similar call tree to your final graphic but it stops at Draw with no System.Windows.dll samples.

    Can you think of any reason why I would not get any samples below agcore.dll?

  2. miteshyh says:

    Looks symbols for silverlight 4 are not publically available, when will it become available? its much needed and we have waited more than a year now.

  3. MarkRi says:

    Thanks miteshyh.  I retried with a Release build and I now see the symbols.

    I’ll repeat your question, too.  When will we see debug symbols MS?

  4. mgoldin says:

    Hi MarkRi and Miteshyh, The SL4 team member reply to your question is "the debug symbols will only apply to debug builds (chk). Since we only release ret builds, and only publish ret symbols, I’m not sure what the question is about. The ret symbols give you all the information you would want to have…". Saying that, as I am not Silverlight developer myself, may I suggest that you ask this question on forums on silverlight.net? There are many SL developers trolling those forums, so you might get an answer there. Thanks!

  5. Chuck says:

    This doesn’t work for me, no matter what I’ve tried. Basically, the vsp file is created, but it doesn’t have any of the symbols for the user code. I even grabbed your breakout solution, put it in c:codeBreakout…, changed dir to that Release dir, rebuilt the project, etc. I can successfully attach, run the app, and close, but I don’t even see agcore.dll in my call tree. I’m running VS and the cmd window as admin, too. Any ideas on what’s missing?

  6. MarkRi says:

    @Chuck – which install of VS and Silverlight are you running?  Is it possible that you are running a version of Silverlight for which MS has not shared symbols for like an  RC or Beta, etc?

  7. mgoldin says:

    Hi Chuck!

    When you run "VSPerfClrEnv /sampleon", a number of environment variables are set. Two of them are of the most importance for SL4 profiling –



    Can you please double check that all of the below is valid in your case:

    1. You use latest available version of Silverlight 4 and VS2010 (as MarkRi noticed).

    2. You run your scenario from the directory where you SL4 binaries are located.

    3. You use IE8 and you start it from the prepared environment, not by clicking an IE icon.

    4. You attach to either all IE8 processes, or to the process that runs your SL code.

    5. You have CORECLR_ENABLE_PROFILING and CORECLR_PROFILER environment variables set in your target process

    6. You see VSPerfCorProf.dll is loaded into your target process.

  8. orena says:

    Hey Chuck,

    Did you disable IE multi tab TabProcGrowth registry setting? Without this you will be attaching to the IE container as opposed to the tab process and will not see agcore.dll.

    Do you have the SL4 dev tools installed – or are you using a stock install of VS2010 RTM to build the project and run it under the SL4 plugin? If so, can you install the SL4 dev tools from http://www.silverlight.net/getstarted/ and retry?

    Just a note that profiling of the standard install of the SL4 plugin is not supported (you need the dev install to wire up the extra registry settings / files). Regardless, you should always see agcore.dll in your profiles though (regardless of version) as it is native, there just won’t be any symbols underneath it.



  9. Chuck says:

    I have the release of SL4 in VS2010 on a Win7 x64 box. Using IE8 and using cmd lines as posted above.

    Thanks for the tips, I’ll try this stuff out and get back to y’all hopefully before the end of today 🙂

  10. Xsun says:

    Hi, I can get the SL4 profiler to work only if the IE loads HTML page, but if using aspx pages, I cannot see my own dll in the module list. Any idea?

  11. Chuck says:

    Ah, got it. I used ProcExp to help me ensure I had the VSPerfCorProf.dll loaded within the process I was trying to profile, and that was the missing piece. Apparently orena’s comment holds true, I was essentially profiling the wrong process. That also means the cmd that combines steps 2 and 3 didn’t work for me because I didn’t disable TabProcGrowth in the registry.

    Hope all this helps others.

  12. orena says:

    Chuck – great to hear that you got it solved! 🙂

    Xsun – there is no difference from Silverlight’s point of view if it is being loaded from aspx or html (it’s all html in the end). I imagine that you are launching IE in slightly different ways each time:

    1. Are you always launching IE from the Visual Studio command prompt?

    2. Have you disabled TabProcGrowth in the registry? (set to 0)


  13. mgoldin says:

    Chuck – glad it worked out for you! Yes, you can combine steps 2 and 3 into launch of IE only if it will not spawn a new IE process. If your scenario allows you to attach and doesn’t require launch, you can attach to any IE process later, or to all of them (if you are not sure which one of them is the right process).

    Xsun – as Orena says, can you please make sure that you profiler the process that runs your code? There is a list of check points I provided for Chuck – can you please go through them and see if everything is in order?


  14. Xsun says:


    1. Yes, always launching IE from VS prompt.

    2. Yes, TabProcGrowth = 0.

    I can see the VSPerfCorProf.dll loaded. I tried to use VS test Web service, which didn’t sample anything. And I installed in IIS, the profiler captured something. But the result is different if I change the directory in the VS prompt. I can see the System.Windows.dll, and unkown under agcore.

    What else can I try?

  15. orena says:

    It sounds like you are actually getting agcore in the modules list – all you are missing is the symbols. You need to enable the Microsoft Symbol Server under Tools -> Options -> Debugging -> Symbols. Also make sure that you have the directory to your pdbs in the same list, so that you get the correct managed symbols.


  16. Xsun says:

    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.

  17. Xsun says:

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

  18. mgoldin says:

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

  19. Eli Schleifer says:

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

  20. mgoldin says:

    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?

  21. CUrwiler says:

    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…

  22. mgoldin says:

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

  23. Ritchie says:

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

    Any advice would be appreciated.

  24. mgoldin says:

    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!

  25. jimnet says:

    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?

  26. Hiral says:


    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,


  27. Brent says:

    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.

  28. Brent says:

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

  29. Uday says:

    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?

  30. 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!