WPF performance and .NET Framework Client Profile related blogs provided by Jossef Goldberg.
Event Tracing for Windows (ETW) provides application developers the ability to start and stop event tracing sessions, instrument an application to provide trace events, and consume trace events.
In addition to Windows itself, WPF also emits an array of interesting events that can be used to track the execution of an application at the framework level.
Mike Cook wrote a great document that explain the various ETW events emitted by WPF.
Check out the this documentation here.
You are encouraged to use these events to measure and analyze your WPF application performance.
The WpfPerf tool for example, use these events extensively. In addition, the WPF team is also using ETW in its automated tests to analyze WPF performance and catch regressions.
Attached is also a sample that demonstrates how you can consume one of these events (UceNotifyPresent event) to measure frame-rate (aka FPS , Frame-per-Second) in a WPF application.
The sample animates a rectangle and outputs the FPS to a command window . It is writing to a command window and not to the main app window so that it will not affect the real FPS. You should expect to see frame-rate tied to the refresh rate of your monitor. Special thanks to Mike Cook and TJ Hsiang who helped put this sample together.
The WPFPerf tool comprises of a suite of performance profiling tools that allow you to analyze the run-time behavior of your WPF application and point to potential performance bottlenecks.
We now added some new functionality as well as given the tool a major facelift. Below are highlights for some of the exciting improvements that are included in this update. More details and download link is available here. Most of the concepts on how to use the tool remain the same so you can still refer to the existing documentation for the tool here to learn more. The tool should work on all 3.x version of .Net.
Note: some folks reported issues when installing on none-US machines. Until this is investigated, please install only on US machine using the default local settings.
The Visual Profile tool now provides:
1) Search: provides the ability to search element in the application’s Element Tree.
2) Hotpath: Allows you to Right Click / Expand Hotpath on an Element Tree, the tree will expand to show the element in the sub-tree that consumes the most amount of CPU in that sub-tree.
3) Elements CPU Usage: As user expands the Element Tree (e.g. by using the Hotpath feature from above), elements that (Exclusively) consumes CPU time are highlighted in Red. The intensity of the Red highlighting corresponds to the percentage of CPU usage.
4) Tinting the Target Application : Using the Overlay Window button, you can view the Selected and Hotpath sub-tree elements in their target application. If the Overlay Window button is depressed, then:
Here is an example of how target application may look:
Note: Enabling this feature will slow the target application performance. In addition, tinting the target application uses Layered Windows. It is recommended that users follow this blog to make to obtain latest QFEs (or use XP Sp3 or Vista Sp1)
5) Live Preview: If the “Live Preview” is enabled, then in a live representation of the selected Element sub-tree is drawn on the bottom left. Otherwise a static image of the sub-tree is displayed. In both cases, the image will change if another Tree Element is selected.
Note: Enabling this feature will slow the target application performance.
6) Splitter control: Allows user to adjust the various display areas (E.g. the Element Tree & Element Information areas)
7) Graph Duration Slider: Allow user to change the amount of history data collected.
8) Expander controls: Allow user to remove un-wanted clutter from the screen
9) Element Tree View: Using the View menu you can control what information is displayed on the each node in the Element Tree and remove unwanted clutter.
The Perforator tool now provides:
1. Improved UX : More intuitive and richer UX.
2. History Data:
3. Detect SW rendered Bitmap Effects: Checkbox added to tint the target application elements that use SW rendered legacy Bitmap Effects. In below example, the top button is decorated with OuterGlowEffect Bitmap Effect. Since this effect is not HW accelerated the Button is tinted in Red. The bottom Button is decorated with DropShadow Bitmap Effect which is HW accelerated (DropShadow is now HW accelerated in .Net 3.5 Sp1), and therefore is not tinted with Red. Known limitations: A) You must force the target elements to redraw itself after you enabled the checkbox for you to see the red tint. E.g. hover over with the mouse, if it is standard button. B) You still need to launch Perforator before you launch your app.
C) New tool: String Allocation Profiler We added a new tool to WPFPerf called “String Allocation Profiler” The tool enables users to view all the strings and their sizes which were allocated by the application from the time the application started till the time it closed. To use this tool: 1. Click on “Action / Lunch Process…” to launch the target application. Notice that WpfPerf says “Profiling…” on the status bar 2. Click around your application and when done close it. Notice that WpfPerf says “Processing Profile Data…” on the status bar 3. When done, WpfPerf displays the application method tree and for each method it shows the Inclusive and Exclusive # of strings allocations and their sizes. 4. You can drill down the application Method Stack Tree to view all the strings your application allocated in a specific method sub-tree. 5. Search: If you know the string names you can also search for them and find the methods that allocated them. 6. Using the “Action/Save String Allocation Log” and “Action / Save String Allocation Log” menu, you can save and open a view allocation logs at a later point. Notes: a) The tool display strings allocated directly by the application (in code and XAML) as well as strings allocated by the CLR and WPF framework. b) The tool have affect on the performance of you application while it monitors string allocations.
D) ETW Event Tracing tool: Some bugs fixed, and new detailed documentation for the WPF ETW events is now available. See more here.
E) General improvements: 1) Numerous bug fixes 2) Now you can attach and profile XBAPs in addition to Standalone WPF apps 3) Improved “Add Tool” dialog. It now allows user to select more than one tool at a time. 4) UI improvements to the “Select Process” dialog. This allows user to select the target application to profile. 5) UI improvements to the “Launch Process” dialog. F) Know issues and Caveats:
Please enjoy the tool and tell us what you think and what needs improvement.