WPF Performance Suite
The Windows SDK includes a suite of performance profiling tools for Windows Presentation Foundation (WPF) applications called the WPF Performance Suite. The WPF Performance Suite enables you to analyze the run-time behavior of your WPF applications and determine performance optimizations that you can apply. The WPF Performance Suite includes performance profiling tools called Perforator and Visual Profiler. This topic describes how to install and use the Perforator and Visual Profiler tools in the WPF Performance Suite.
This topic contains the following sections:
Installing the WPF Performance Suite
Starting the WPF Performance Suite
Perforator
Visual Profiler
Installing the WPF Performance Suite
The following steps describe how to install the WPF Performance Suite.
If you have an earlier version of the Windows Performance Toolkit installed, uninstall it.
Install the Windows SDK.
In the installation options, make sure that you select the Windows Performance Toolkit option under Common Utilities. For download information, see the Windows SDK Download Page.
After the Windows SDK is installed, on the Start menu, select All Programs, Microsoft Windows SDK v7.1, and then Tools.
Under Tools, click Install Windows Performance Tool Kit.
The setup wizard appears.
Follow the instructions that appear to install the Windows Performance Toolkit.
By default, the following features will be installed.
Performance Analyzer
Windows Performance Toolkit Help
GPUView
WPF Performance Suite
Starting the WPF Performance Suite
You should start the WPF Performance Suite before you run the application that you want to profile. To use the WPF Performance Suite, your user account must have administrative privileges.
The following steps describe how to start the WPF Performance Suite.
On the Start menu, select All Programs and then Microsoft Windows Performance Toolkit.
Click WPF Performance Suite.
If a User Account Control dialog box appears, click Yes.
The WPF Performance Suite starts.
The first time that you start the WPF Performance Suite, the Add Tools dialog box appears. The Add Tools dialog box lets you add performance profiling tools. To add a tool, you select an assembly that contains a tool and then click Scan Assembly. You can open the Add Tool dialog box at any time by clicking Add Tool from the File menu. The following illustration shows the Add Tools dialog box.
Add Tools dialog box
By default, the WPF Performance Suite includes the following performance profiling tools.
Tool |
Description |
---|---|
Perforator |
Analyzes rendering behavior. |
Visual Profiler |
Profiles the use of WPF services such as layout and event handling by elements in the visual tree. |
Make sure that the Perforator and Visual Profiler check boxes are selected and then click OK.
Perforator
Perforator is a performance profiling tool for analyzing the rendering behavior of your WPF application. The Perforator user interface displays a set of graphs that enable you to analyze very specific rendering behavior in parts of your application, such as the dirty rectangle addition rate and the frame rate. WPF uses a rendering technique called dirty rectangle, which means that only the portions of the screen that have changed are rendered on a new rendering pass. In addition, Perforator has several options that you can use to look for specific rendering problems. Perforator also reports the software rendering targets and a slider to control the duration of the graphs. The following illustration shows the Perforator user interface.
Perforator user interface
Using Perforator
To use Perforator, start the WPF application that you want to analyze. Once the application has started, click the Perforator tab, click the Actions menu, and then click Select Process. In the Select Process dialog box, select the application process that you want to analyze and then click Select. The process name and process ID should now appear at the top of the Perforator tab. Select rendering options that you want to analyze. The Perforator data values, such as frame rate, immediately reflect the rendering behavior of the application. The following illustration shows an example.
Perforator with application and rendering options selected
Perforator Graphs
It is important that the frame rate, dirty rectangle addition rate and the number of intermediate render targets remain low for your WPF application to render efficiently. Perforator has many useful graphs to monitor these levels.
The following table describes the metrics reported by each graph.
History Graph |
Description |
Notes |
---|---|---|
Frame Rate |
Reports the rate at which the application is rendering to the screen. |
For applications without animation, this value should be near 0. During animations in a well-performing application, Frame Rate should be close to the monitor’s refresh rate (typically 60 or 75). |
Dirty Rect Addition rate |
Indicates how many rectangular regions that WPF has to update for each frame. |
Dirty rectangle refers to a rendering technique where only the portions of the screen that have changed are rerendered. A high value indicates that a lot of regions are changing. This isn't necessarily good or bad but a value to consider with the overall performance of your application. |
SW IRTs Per Frame |
Shows the number of software intermediate render targets (IRTs) required to render one frame of the application. |
IRTs are expensive software surfaces that WPF must allocate and copy data to and from. Software IRTs are more expensive than hardware IRTs. IRTs are usually caused by using DrawingBrush, VisualBrush, Opacity property on a Visual, or Tile modes on a TileBrush. If this number is high (for example, greater than 5), it indicates that the WPF runtime is performing a large amount of work to render your application. On a computer that supports hardware acceleration, this number should be 0. Otherwise, this number indicates that some of your scene is rendered by using the slower software pipeline. |
HW IRTs Per Frame |
Shows the number of hardware intermediate render targets (IRTs) required to render one frame of the application. |
IRTs are expensive hardware surfaces that WPF must allocate and copy data to and from. Intermediate render targets are usually caused by using DrawingBrush, VisualBrush, or Opacity property on a Visual, or Tile modes on a TileBrush. If this number is high (for example, greater than 5), it indicates that the WPF runtime is performing a large amount of work to render your application. In this case, you will have to analyze all areas of your code that use the previously mentioned elements. Hardware IRTs are less expensive than software IRTs. |
Video Memory Usage |
Tracks large allocations of video memory to WPF for texture and render targets. This metric does not track memory allocations to the video driver or memory allocations for compiling and loading pixel and vertex shaders. |
Exceeding the available amount of texture memory will usually cause WPF render logic to fall back to software, and that multiple displays (multi-monitor) have a multiplicative effect on the amount of video memory that is required for an application. |
Perforator Rendering Options and Optimizing Rendering
Perforator enables you to set many rendering options that affect the real-time rendering behavior of the application. Setting these options enable you to see rendering events that could be problematic in your application. These options are found at the lower portion of the user interface.
The following illustration shows the Perforator rendering options.
Perforator rendering options
In general, to improve the performance of your WPF applications, you should minimize software rendering and lower the number of intermediate render targets. The following sections discuss how Perforator can help you do this.
Avoiding Software Rendering
Because the WPF hardware rendering pipeline is significantly faster that its software rendering pipeline, the less application user interface that renders in software, the faster rendering in that application will be. Typically, the time that it takes to render an area in software is proportional to the number of pixels rendered. Therefore, be wary of large areas rendered by using the software pipeline. Small areas are of less concern.
The following table lists the Perforator options that can help detect software rendering issues.
Option |
Description |
Notes |
---|---|---|
Draw software rendering with purple tint |
Draws all areas rendered by using the software rendering pipeline with a purple tint. This includes software render targets, software 3D content, and per-primitive software fallback. |
The WPF hardware rendering pipeline is significantly faster that its software rendering pipeline. Too much software rendering typically indicates a problem. Examples that would cause this behavior include tiling a Brush too much or exceeding the video card’s texture size. |
Draw software rendered bitmap effects with red tint |
Draws legacy software rendered bitmap effects with red tint. |
Software rendered BitmapEffect classes are slow and should be avoided. You should use the hardware rendered Effect classes that were introduced in the .NET Framework 3.5 SP1. |
The following illustration displays the PhotoDemo sample application with the Draw software rendering with purple tint rendering option enabled.
PhotoDemo with purple tint
Monitoring Dirty Regions
Because WPF updates only portions of a window as required, it can be helpful to visualize updates at any time. In some cases, although no animations are occurring in the application, regions will continue to update. The following options help visualize the update behaviors. Unnecessary updates are particularly important in remote desktop, virtual machines, and similar scenarios when WPF must send new bitmaps over the network. In addition, unnecessary updates can affect laptop battery life.
Option |
Description |
Notes |
---|---|---|
Show dirty-region update overlay |
Causes each update WPF makes to the screen to be indicated by re-coloring. This enables you to see when and where areas are redrawn in an application. |
Because WPF only updates portions of the window as required, it can be helpful to visualize what proportion of the window is being updated at any time. Use this option when frame rate and dirty rectangle addition rate are not zero, but no visuals are changing in your application. |
Disable dirty region support |
Causes WPF to redraw the entire window any time a change is made. |
This option is useful for forcing your entire window to update. Normally, only the portion of the window that has changed is redrawn. Enabling this option causes your application to render much more slowly. |
Clear back-buffer before rendering |
Clears application windows before each drawing operation. |
This option is an alternative to Show dirty-region update overlay. It effectively shows the most recent dirty region whereas the dirty region update overlay is more useful for seeing changes in the dirty region over time. |
Detecting Other Sources of Performance Degradation
Perforator enables you to disable certain performance-intensive operations to determine whether they are causing bottlenecks in your application. By monitoring the applications frame rate and selecting these options individually, you can determine whether operations, such as 3D rendering or image rescaling, are causing rendering issues. If you select one of these options and your frame rate drops significantly, you have likely identified the bottleneck in your application.
Option |
Description |
Notes |
---|---|---|
Disable Opacity Effects |
Disables certain potentially performance-intensive uses of opacity. |
To avoid this performance issue in general, consider setting opacity on a low-level object, such as Brush, instead of a high-level object, such as Button. |
Disable per-primitive software fallback |
Disables software fallback for individual rendering primitives. Software intermediate render targets and other software rendering cannot be disabled. |
This option is not required in most cases. Keep it unchecked. |
Disable high-quality image rescaling |
Disables the rescaling of large images to smaller sizes. |
Enables you to see the effect of image rescaling in your application. If checking this option significantly lowers your frame rate, consider decoding your images to a size near the size that they will be displayed. |
Disable 3D rendering |
Disables all 3D rendering operations |
Enables you to see the effect of 3D rendering operations in your application. |
Visual Profiler
Visual Profiler is a performance profiling tool of WPF services, such as layout, rendering, and animation, for elements in the visual tree. By analyzing the profiling output of this tool, you can determine which visual elements in your application may be causing performance bottlenecks.
Visual Profiler presents performance issues in the context of the basic building blocks that are used to construct visual scenes in your application. These building blocks include high-level objects, such as Button and TextBlock controls, as well as low-level objects, such as Line and Ellipse elements. Instead of describing performance issues in terms of call graphs of functions names, Visual Profiler describes these issues by using the representation of visual objects. This is similar to the way the Windows SDK tool, UI Spy, represents information. For more information, see UISpy.exe (UI Spy).
Using Visual Profiler
To use Visual Profiler, start the WPF application that you want to analyze. Once the application has started, click the Visual Profiler tab, click the Actions menu, and then click Select Process. In the Select Process dialog box, select the application process that you want to analyze and then click Select. The process name and process ID should now appear at the top of the Visual Profiler tab.
To analyze the breadth of WPF performance issues, you must understand the role and scope of underlying WPF services. These services include layout, rendering, and animation. Visual Profiler provides a graphical representation of how WPF services are allocated among application objects. For example, when Visual Profiler displays the visual tree of application objects, it overlays different shades of red on the objects in order to represent the relative amount of resources the object is using. An object that is displayed with a darker red overlay represents an object that uses a higher proportion of resources than an object with a lighter red overlay. More importantly, Visual Profiler provides a breakdown of the amount of specific WPF resources an object consumes.
The following illustration shows the Visual Profiler user interface.
Visual Profiler user interface
There are eight areas to the Visual Profiler user interface.
Element tree search box
Visual element tree
Element details and preview
Element exclusive CPU usage details
Application CPU usage details
Captured data zoom control
History graph display settings
Options for application preview and performance overlay
The following sections describe each area.
Element tree search box
The search box in the Element Tree section provides the ability to search elements in the application’s element tree. When a search is performed, all matching elements are highlighted in yellow. You can search for elements by their type or name.
Visual element tree
The tree control in the Element Tree section, displays the type and name of visual elements in the application along with subtree size and layout details.
The following is an example of an element label in the tree.
Border 'border1' (26) 0.02% (I)/ 0.00 % (E) - .24 ms (I) / 0.00 ms (E)
Element Label Part |
Description |
---|---|
Border |
Type of the element. |
'border1' |
Name of the element. |
(26) |
Subtree size. |
0.02% (I) |
Percent of total size for inclusive tree, which is the element and all its descendants. |
0.00 (E) |
Percent of total elements for the element only. |
.24 ms (I) |
Time in milliseconds to layout the element and its descendants. |
0.00 ms (E) |
Time in milliseconds to layout the element only. |
Use the View menu to control whether to display Inclusive/Exclusive %/time information.
Right-click an element to expand or collapse the subtree. You can also expand its hotpath. The hotpath shows the element in the subtree that consumes the most CPU in that subtree.
Element details and preview
The Element Information section displays the currently selected element type and name, if the element is named. It also provides a preview of the element in the Preview section. If the top-most element is selected, the preview displays a preview of the application.
Element exclusive CPU usage details
The Element Exclusive CPU Usage section displays a history graph and details of the exclusive CPU time that was consumed by the selected element over time. For example, an element may spent x% CPU time on layout arranging, y% on layout measuring, and z% on rendering.
Application CPU usage details
The Application CPU Usage section displays a history graph and details of application events. Visual Profiler listens and captures various application events. The application events are listed with absolute values and the history graph shows the CPU time that is spent in each application event over time with different colors. This enables you to easily see the time the application spends in layout versus rendering.
The following table describes the application events represented in the graph.
Note
Those events that correspond to methods calls in WPF are represented by the method name followed by the class name in parentheses. For example, Tick (TimeManager) represents the TimeManager.Tick method.
Application events |
Description |
---|---|
Unlabeled Time |
Time spent in WPF that is not categorized in another application event all time spent by the application outside of WPF |
RenderMessageHandler (MediaContext) |
Occurs when the render pass is initiated. This event causes the time manager to tick among other things. |
Rendering Thread |
Occurs when executing rendering instructions on the rendering thread. This is useful for detecting render-bound applications. |
Layout |
Occurs during the measure, arrange, and render pass. |
UpdateRealizations |
Occurs when updating internal bitmap representations of text and bitmap effects. |
Tick (TimeManager) |
Occurs when the animation is ticking. This event can trigger the animation render handler. When you animate objects in WPF, a time manager manages the Clock objects created for your timelines. The time manager is the root of a tree of Clock objects and controls the flow of time in that tree. A time manager is automatically created for each WPF application and is invisible to the application developer. The time manager "ticks" many times per second. The actual number of ticks that occur each second varies depending on available system resources. |
AnimatedRenderMessageHandler (MediaContext) |
Occurs for animation processing and updates. When animations are enabled, this handler processes and updates the animation, which causes properties to change and rendering to occur. |
Render (MediaContext) |
Occurs during the render pass. This method eventually calls the OnRender method of each element, and is useful for understanding the total cost of OnRender for all elements. This event corresponds to the MediaContext.Render method in a Visual Studio Profiler (VSP) file. |
Captured data zoom control
The Graph Options section includes a capture data zoom control. By dragging the zoom window handles, you can resize and change the time axis of the Element Exclusive CPU Usage and Application CPU Usage history graphs.
History graph display settings
The Graph Options section includes radio buttons and a slider to adjust history graph settings. You use the radio buttons to specify how the CPU axis, the vertical axis, behaves; whether it displays absolute or relative weights. You use the slider to set a maximum displayed value for the graph.
Options for application preview and performance overlay
The Control Options section contains three toggle buttons that perform the following actions.
Click the first toggle button to pause or start the Visual Profiler data collection.
Click the Live Preview toggle button to display a live preview of the application in the Preview section.
Click the Overlay Window toggle button to add a yellow border around the selected visual element. Also, for elements that consume the most CPU time, a red overlay is added. The same red color is used for the element in the Element Tree section. The intensity of the red correlates to the CPU usage.
See Also
Concepts
Optimizing WPF Application Performance
WPF Graphics Rendering Overview