本文介绍了如何分析 WPF 4.5 UI 性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 .NET 4.5 WPF 应用,但遇到了 UI 渲染性能问题.

在谷歌搜索之后,我发现了

  1. 当您的应用启动时,执行引起您感兴趣的问题的操作
  2. 然后点击停止录制,你最终会得到你的元素树与渲染每个节点所花费的时间.然后,你只需要按Duration (total)排序,展开最慢的节点,直到找到问题:

总而言之,如果您使用 Name 属性为控件设置名称,则将上面树中的节点与您的布局相关联会容易得多,如下所示:

I'm developing a .NET 4.5 WPF app and having UI rendering performance issues.

After some googling, I came across WPF Performance Suite page which describes exactly the tool I need - Visual Profiler. It allows to view WPF elements tree and analyze the contribution of each element to the total rendering time.

The only problem is that the page states that the tool is contained in Microsoft Windows SDK v7.1 which is targeting Windows 7 and .NET 4.0.

Since my app is for .NET 4.5 and I'm on Windows 8.1, I've installed Windows SDK for Windows 8.1. To my surprise, it doesn't seem to contain the WPF Performance Suite at all and that tool in particular.

Then, I've tried to install the WPF Performance Suite from this answer, but it works only with .NET 4.0 apps.

So, where do you get the WPF Performance Suite for .NET 4.5 apps?
Or, to be more general, how do you profile WPF UI rendering performance of .NET 4.5 apps to find out which elements in the tree have highest performance impact in complex UIs?

解决方案

Eventually, I've found a tool that I was looking for and that was really helpful for me.

To get an idea of where exactly is the bottleneck in rendering your WPF layout, you want to:

  1. Install the Visual Studio 2015, if you don't have one yet :)
  2. Go to Debug -> Start Diagnostic Tools Without Debugging
    (NOTE: This seems to be changed to Debug -> Profiler -> Performance Profiler...).
  3. Check Application Timeline tool and hit Start in this view:
  1. When your app starts, do the actions causing issues you're interestedin.
  2. Then hit Stop recording and you'll eventually get your elementstree with times spent for rendering every node.Then, you only need to sort it by Duration (total) and expand slowest nodes until you find the problem:

In conclusion, it would much easier to correlate the nodes from tree above with your layout if you set names for your controls using the Name attribute like the following:

<TextBlock Name="OwnerContact">

这篇关于如何分析 WPF 4.5 UI 性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 08:54