WPF 动画 FPS 与 CPU 使用率 - 我是否期望太多?
为我的妻子制作屏幕保护程序 http://cchearts.codeplex.com/,虽然我已经能够提高低端机器上的 FPS,但 CPU 使用率似乎仍然很高。
以下是我在 5 分钟采样周期中运行的一些数据:
Core 2 Duo T7500 @ 2.2GHz、3GB 内存、NVIDIA Quadro NVS 140M (128MB)、Vista [我的开发笔记本电脑] 上的 CPU 平均约为 60FPS 35%,
平均约为 40FPS 50% Pentium D @ 3.4GHz 上的 CPU,1.5GB 内存,标准 VGA 图形适配器(未知),2003 服务器 [蹩脚的桌面]
我可以理解蹩脚的桌面上较低的帧速率和较高的 CPU 使用率,但它看起来仍然相当高,为 35我的开发笔记本电脑上的 % 似乎也很高。
我真的很想分析该应用程序以获取更多详细信息,但我也遇到了问题,所以我想知道我是否做错了什么(以前从未分析过 WPF)。
WPF Performance Suite:
进程启动错误
无法附加到进程: CCHearts.exe 您想终止它吗?
当我尝试启动后单击“取消”时,会出现此错误消息。如果我不单击“取消”,它就会闲置在那里,我想正在等待附加。
性能资源管理器:
无法启动 C:\Projects2\CC.Hearts\CC.Hearts\bin\Debug (USEVISUAL)\CCHearts.exe。之前对应用程序进行分析的尝试未成功完成。请重新启动应用程序。
性能输出窗口:
分析已开始。 分析进程 ID 5360 (CCHearts)。 进程 ID 5360 已退出。 数据写入 C:\Projects2\CC.Hearts\CCHearts100608.vsp。 分析完成。 PRF0025:未收集数据。 分析完成。
所以我一直想提高性能,但没有具体的方法来确定瓶颈在哪里。在这一点上投掷飞镖已经相对成功,但我现在已经超越了:)
摘要:
到目前为止取得了很多进展...
性能资源管理器
问题:< /em> 不起作用,错误消息模糊。
解决方案:使用命令行版本 以获得一条真实的错误消息,该消息将我指向此 线程 指出这是一个赛门铁克 dll 阻止了我。设置以下注册表项修复了问题:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SysPlant]
"Start"=dword:00000004
WPF Performance Suite
问题: 无法工作,没有错误信息。
解决方案:使用 Windows SDK 7.1 而不是 Windows SDK 7 的先前版本(我觉得很傻:-P)
WPF 动画
问题: 高CPU 使用率与 FPS/感知工作负载的比较。
解决方案:到处都有很多不错的调整。但巨大的改进是缓存组合 正如 Jeremiah Morrill 所指出的。查看变更集。
Working on a screen saver for my wife, http://cchearts.codeplex.com/, and while I've been able to improve FPS on lower end machines the CPU usage still seems very high.
Here's some numbers I ran from a few 5 minute sampling periods:
~60FPS 35% average CPU on Core 2 Duo T7500 @ 2.2GHz, 3GB ram, NVIDIA Quadro NVS 140M (128MB), Vista [My dev laptop]
~40FPS 50% average CPU on Pentium D @ 3.4GHz, 1.5GB ram, Standard VGA Graphics Adapter (unknown), 2003 Server [A crappy desktop]
I can understand the lower frame rate and higher CPU usage on the crappy desktop but it still seems pretty high and 35% on my dev laptop seems high as well.
I'd really like to analyze the application to get more details but I'm having issues there as well so I'm wondering if I'm doing something wrong (never profiled WPF before).
WPF Performance Suite:
Process Launch Error
Unable to attach to process:
CCHearts.exe
Do you want to kill it?
This error message occurs when I click cancel after attempting launch. If I don't click cancel it sits there idle, I guess waiting to attach.
Performance Explorer:
Could not launch C:\Projects2\CC.Hearts\CC.Hearts\bin\Debug (USEVISUAL)\CCHearts.exe. Previous attempt to profile the application finished unsuccessfully. Please restart the application.
Output Window from Performance:
Profiling started.
Profiling process ID 5360 (CCHearts).
Process ID 5360 has exited.
Data written to C:\Projects2\CC.Hearts\CCHearts100608.vsp.
Profiling finished.
PRF0025: No data was collected.
Profiling complete.
So I'm stuck wanting to improve performance but have no concrete way to determine where the bottleneck is. Have been relatively successful throwing darts at this point but I'm beyond that now :)
Summary:
Lot's of progress so far...
Performance Explorer
Problem: Wasn't working, vague error message.
Solution: Used the command line version to get a real error message that pointed me to this thread pointing out that it was a Symantec dll blocking me. Setting the following registry key fixed the problem:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SysPlant]
"Start"=dword:00000004
WPF Performance Suite
Problem: Wasn't working, no error message.
Solution: Use the WPF Performance Suite designed for .NET 4 from the Windows SDK 7.1 instead of the previous version from Windows SDK 7 (I feel silly :-P)
WPF Animation
Problem: High CPU usage compared to FPS/percieved workload.
Solution: Lots ok tweaks here and there. But the HUGE improvement was Cached Composition as pointed out by Jeremiah Morrill. Check out the changesets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我下载了你的代码,发现我的四核 2.6ghz 上的 CPU 使用率约为 20-28%。通过添加缓存合成,我能够将 CPU 降低到约 6-8%。
我使用“DEBUG”而不是“DEBUG(USEVISUAL)”进行编译,并在 Heart.xaml 中将 BitmapCache 添加到路径:
Path CacheMode="BitmapCache" ...
I downloaded your code and saw ~20-28% CPU usage on my quad-core 2.6ghz. By adding cached composition, I was able to get it down to ~6-8% CPU.
I compiled using "DEBUG", not "DEBUG(USEVISUAL)" and in Heart.xaml I added the BitmapCache to the Path:
Path CacheMode="BitmapCache" ...
您不想过度优化。需要回答的第一个问题是大多数屏幕保护程序的性能如何?
如果一切都占用 50% CPU 那么我不会担心(我怀疑情况确实如此)。如果您想在盲目投掷飞镖之前最好地节省周期,请确保您真正了解 WPF 的 3D 方面。
的最佳起点
这是最大化 WPF 3D 性能
You don't want to overlly optimize. The first question that needs to be answered is what are most screensavers performance?
If everything takes 50% CPU then I would not worry (I doubt that is the case). If you want to save cycles the best before just blindly throw darts make sure you really understand the 3D aspects of WPF.
Here is the best place to start
Maximize WPF 3D Performance
我注意到 Celeron 1.1Ghz 上有类似的稳定高 CPU 使用率 (~95%),但我从未注意到打开动画会导致性能下降。我从未量化过 FPS,尽管我怀疑它相当低。我的印象是,WPF 遵循机会主义的资源利用策略,尽其所能获得其所能达到的最佳质量,但又不会干扰其他处理。如果你用其他任务来加载CPU,我怀疑与图形相关的CPU使用率会相应下降。
I noticed a similar steady high CPU usage (~95%) on a Celeron 1.1Ghz, but I never noticed any performance degradation as a result of turning on the animation. I never quantified the FPS, though I suspect it was pretty low. My impression is that WPF follows an opportunistic resource utilization strategy, taking what it can to get the best quality it can muster, but not so much that it interferes with other processing. If you load up the CPU with other tasks, I suspect the CPU usage associated with the graphics will drop accordingly.