For those of you who are a) building graphics-intensive applications or b) trying to debug your performance, I would like to introduce xperf and xperfview. These are two profiling tools which can be used to analyze the performance of any Microsoft technology, including Silverlight.
These tools have existed internally for quite some time, and I'm excited to see that they have been released. I use xperf as my first step for profiling any app -- it's a simple CPU sampler and gives you a peek to why on earth something is taking up so many CPU cycles. XPerf plugs into the Event Tracing for Windows library, and listens to all the internally embedded events that all Windows products trigger. With the publicly available Silverlight symbols, you can see how these events line back to what Silverlight is doing under the hood, while your app is running.
Note: with xperf, managed code (your app code) will show up as samples on the methods that your app code calls. XPerf does not have the capabilities to show CPU cycles in managed code.
With XPerf, one can find answers to questions like:
Please note that the tools only work on Vista and Windows Server 2k3. For profiling on a mac, see my previous post on how to use Shark from the Apple CHUD tools.
The first-time instructions are as follows:
1. Install XPerf (formerly xperfinfo) and xperfview (formerly xperf) as available here: http://msdn.microsoft.com/en-us/library/cc305187.aspx
[10/9-9am I updated the above link: download link http://www.microsoft.com/whdc/system/sysperf/perftools.mspx]
Close everything that is not user-specific (close VS, but keep your virus checker, etc).
2. Startup your sample
I personally start up my sample without profiling because the startup sampling is very different from that of the runtime.
3. Open an Administrator-level command prompt. Set your symbol path in the cmd shell:set _NT_SYMBOL_PATH= srv*C:\symbols*http://msdl.microsoft.com/downloads/symbols
This will set your symbol path to point to the Microsoft symbol server. The symbol server hosts debugging symbols for most all Microsoft products.
[update: cd into C:\Program Files\Microsoft Windows Performance Toolkit]
4. xperf -on base
Run the app for maybe 10 seconds for this initial run. We want to understand what method is taking up the most cycles. At the end of this, you will see a graph of CPU usage over time – so you can use various methods to see where time is going: repeatedly execute a user action (expand/collapse, scroll, etc), let the media play for a while, etc. If you are trying to compare several different options, you can execute different actions at widely-spaced intervals, and compare the graphs for each.
5. xperf –d myprofile.etl
Step #4 will both stop the profile and start the writing of the event trace log (etl) file. This can take a while, depending on the complexity of your application, how many other apps were running, and how long the profile extended.
6. xperfview myprofile.etl
We see now see multiple graphs. We are most interested in that of the CPU cycles, which will look something like this:
In my sample, I have a dual-core machine so you see two lines, one for each CPU. This graph is of a media file playing, which should have an almost steady hit for the CPU. I can drag and select any section of the graph and take a closer look:
7. TraceàLoad Symbols
8. Select the area of the CPU graph that you want to see
9. Accept the EULA for using symbols, expand IExplore.exe (or firefox.exe)
At this point, you’ll see how the time breaks down between the different processes and modules running within windows. Agcore.dll, npctrl.dll, and coreclr.dll are all Silverlight.
10. If the symbols server has correctly been set, you’ll see that you can expand and see the breakdown of time in each method call within agcore.dll:
The way to read this graph is that IE is taking up 40% of the CPU on average, during the selected sample. Within that, 32% of the time is spent in Silverlight core (graphics/decoding/property engine, etc are all represented in agcore.dll), and then of that time, 29% (9.24/32.33) of the drawing time is spent in one method call.
Note: with xperf, managed code (your app code) will show up as samples on the methods that your app code calls. XPerf does not have the capabilities to look at app code.
Now what? Well, with just the above think about how you can answer the questions at the top:
Note: The tools only work on Vista and Windows Server 2k3
For later usage, your usage pattern is quicker:
The platform code and the CPU samples will change version to version, so please keep that in mind when profiling between upgrades.
See anything interesting? Drop me a note!
Seema Ramchandani works on performance as a Program Manager on the Silverlight team. She gave a fast-paced
Seema Ramchandani Overview < 1 year from Silverlight 2 release Scenarios: Customer adoption blockers
I run xperf but it is not enough for stress testing. Is there any tool (free if it is possible) for silverlight testing which allow record scripts and set thinking time, number of user and other parameters for stress testing?
FYI using Perfmonitor should be able to provide call-stacks.
ETW is available only in Windows
<a href="www.eastcomfort.net/index.ro.html">Cazare Ieftina Bucuresti</a>
@endquote I had the same issue of "xperf: error: NT Kernel Logger: Cannot create a file when that file already exists. (0xb7)." but had a different resolution notied in my blog post: www.blogmynog.com/.../xperf-error-nt-kernel-logger-cannot-create-a-file-when-that-file-already-exists