如何分析WPF 4.5 UI性能? [英] How to profile WPF 4.5 UI performance?

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

问题描述

我正在开发.NET 4.5 WPF应用程序,并且存在UI渲染性能问题.

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.

唯一的问题是该页面指出该工具包含在针对Windows 7和.NET 4.0的Microsoft Windows SDK v7.1中.

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.

由于我的应用程序适用于.NET 4.5,并且我位于Windows 8.1上,因此我已经安装了适用于Windows 8.1的Windows SDK .令我惊讶的是,它似乎根本没有包含WPF Performance Suite,尤其是该工具.

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.

然后,我尝试通过答案安装 WPF Performance Suite . 但它仅适用于.NET 4.0应用.

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

那么,在哪里可以得到.NET 4.5应用程序的WPF Performance Suite?
或者,更笼统地说,如何分析.NET 4.5应用程序的WPF UI渲染性能,以找出树中的哪些元素在复杂的UI中对性能的影响最大?

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.

要了解呈现WPF布局的瓶颈到底在哪里,您想要:

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

  1. 如果还没有安装 Visual Studio 2015 :)
  2. 转到调试-> 无需调试即可启动诊断工具
    (注意:这似乎已更改为 Debug -> Profiler -> Performance Profiler ... ).
  3. 检查应用程序时间轴工具,然后在此视图中点击开始:
  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. 启动应用时,请执行引起您感兴趣的问题的操作 内.
  2. 然后点击停止录制,您最终将获得自己的元素 渲染每个节点所花费时间的树. 然后,您只需要按持续时间(总计)进行排序,并展开最慢的节点,直到发现问题为止:
  1. When your app starts, do the actions causing issues you're interested in.
  2. Then hit Stop recording and you'll eventually get your elements tree 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:

最后,如果使用Name属性为控件设置名称,如下所示,将上方树中的节点与布局关联起来会容易得多:

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性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆