简体   繁体   English

如何衡量C ++(MFC)应用程序的性能?

[英]How to measure performance in a C++ (MFC) application?

What good profilers do you know? 你知道什么好的个人资料?

What is a good way to measure and tweak the performance of a C++ MFC application? 测量和调整C ++ MFC应用程序性能的好方法是什么?

Is Analysis of algorithms really neccesary? 算法的分析真的是必要的吗? http://en.wikipedia.org/wiki/Algorithm_analysis http://en.wikipedia.org/wiki/Algorithm_analysis

I strongly recommend AQTime if you are staying on the Windows platform. 如果你住在Windows平台上,我强烈推荐AQTime It comes with a load of profilers, including static code analysis, and works with most important Windows compilers and systems, including Visual C++, .NET, Delphi, Borland C++, Intel C++ and even gcc. 它配备了大量的分析器,包括静态代码分析,并与最重要的Windows编译器和系统配合使用,包括Visual C ++,.NET,Delphi,Borland C ++,Intel C ++甚至gcc。 And it integrates into Visual Studio, but can also be used standalone. 它集成到Visual Studio中,但也可以单独使用。 I love it. 我喜欢它。

If you're (still) using Visual C++ 6.0, I suggest using the built-in profiler. 如果您(仍)使用Visual C ++ 6.0,我建议使用内置的分析器。 For more recent versions you could try Compuware DevPartner Performance Analysis Community Edition . 对于更新版本,您可以尝试使用Compuware DevPartner Performance Analysis Community Edition

For Windows, check out Xperf which ships free with the Windows SDK. 对于Windows,请查看随Windows SDK免费提供的Xperf It uses sampled profile, has some useful UI, & does not require instrumentation. 它使用采样配置文件,具有一些有用的UI,并且不需要检测。 Quite useful for tracking down performance problems. 对于跟踪性能问题非常有用。 You can answer questions like: 你可以回答以下问题:

Who is using the most CPU? 谁使用最多的CPU? Drill down to function name using call stacks. 使用调用堆栈深入查看函数名称。 Who is allocating the most memory? 谁分配的内存最多? Who is doing the most registry queries? 谁在进行大多数注册表查询? Disk writes? 磁盘写? etc. You will be quite surprised when you find the bottlenecks, as they are probably not where you expected! 当你发现瓶颈时,你会感到非常惊讶,因为它们可能不是你想象的那样!

It's been a while since I profiled unmanaged code, but when I did I had good results with Intel's vtune. 自从我分析了非托管代码以来已经有一段时间了,但是当我这样做时,我在英特尔的vtune上取得了不错的成绩。 I'm sure somebody else will tell us if that's been overtaken. 我相信别人会告诉我们这是否被超越了。

Algorithmic analysis has the potential to improve your performance more profoundly than anything you'll find with a profiler, but only for certain classes of application. 算法分析有可能比使用分析器找到的任何东西更深刻地改善您的性能,但仅适用于某些类别的应用程序。 If you operate over reasonably large sets of data, algorithmic analysis might find ways to be more efficient in CPU/Memory/both, but if your app is mainly form-fill with a relational database for storage, it might not offer you much. 如果您对相当大的数据集进行操作,算法分析可能会找到提高CPU /内存/两者的效率的方法,但如果您的应用程序主要使用关系数据库进行存储填充,则可能不会为您提供太多帮助。

Intel Thread Checker via Vtune performance analyzer- Check this picture for the view i use the most that tells me which function eats up the most of my time. 英特尔线程检查器通过Vtune性能分析器 - 检查此图片以查看我使用最多的视图,告诉我哪个功能占用了我大部分时间。

替代文字

I can further drill down inside and decompose which functions inside them eats up more time etc. There are different views based on what you are watching (total time = time within fn + children), self time (time spent only in code running inside the function etc). 我可以进一步向内钻取并分解其中的哪些函数占用更多时间等。根据您正在观看的内容(总时间= fn +儿童中的时间),自我时间(仅在代码运行中花费的时间)有不同的视图功能等)。

This tool does a lot more than profiling but i haven't explored them all. 这个工具比分析更多,但我还没有探索过它们。 I would definitely recommend it. 我肯定会推荐它。 The tool is also available for downloading as a fully functional trial version that can run for 30 days. 该工具也可作为可运行30天的全功能试用版下载。 If you have cost constraints, i would say this window is all that you require to pin point your problem. 如果你有成本限制,我会说这个窗口就是你需要解决问题所需的全部内容。

Trial download here - https://registrationcenter.intel.com/RegCenter/AutoGen.aspx?ProductID=907&AccountID=&ProgramID=&RequestDt=&rm=EVAL&lang= 试用版下载 - https://registrationcenter.intel.com/RegCenter/AutoGen.aspx?ProductID=907&AccountID=&ProgramID=&RequestDt=&rm=EVAL&lang=

ps : I have also played with Rational Rational but for some reason I did not take much to it. ps:我也玩过Rational Rational,但由于某种原因,我没有花太多钱。 I suspect Rational might be more expensive than Intel too. 我怀疑Rational也可能比英特尔更贵。

Tools (like true time from DevPartner) that let you see hit counts for source lines let you quickly find algorithms that have bad 'Big O' complexity. 工具(如DevPartner的真实时间)让您可以看到源代码行的命中数,这样您就可以快速找到具有糟糕“大O”复杂度的算法。 You still have to analyse the algorithm to determine how to reduce the complexity. 您仍然需要分析算法以确定如何降低复杂性。

I second AQTime, having both AQTime and Compuwares DevPartner, for most cases. 在大多数情况下,我的第二个AQTime,包括AQTime和Compuwares DevPartner。 The reason being that AQTime will profile any executable that has a valid PDB file, whereas TrueTime requires you to make an instrumented build. 原因是AQTime将分析具有有效PDB文件的任何可执行文件,而TrueTime要求您进行检测构建。 This greatly speeds up and simplifies ad hoc profiling. 这极大地加速并简化了临时分析。 DevPartner is also quite a bit more expensive if this is an issue. 如果这是一个问题,DevPartner也会相当昂贵。 Where DevPartner comes into its own is with BoundsChecker, which I still rate as a better tool for catching leaks and overwrites than AQTimes execution profiler. DevPartner自成一体的地方就是BoundsChecker,我仍然认为这是一个比AQTimes执行分析器更好的捕获泄漏和覆盖的工具。 TrueTime can be slighly more accurate than AQTime, but I have never found this to be an issue. TrueTime可以比AQTime更准确,但我从来没有发现这是一个问题。

Is profiling worthwhile, IMO yes, if you need performance gains on a local application. 如果您需要在本地应用程序上获得性能提升,那么分析是否值得,IMO是的。 I think you also learn a lot about how your program and algorithms really work, and the cost implications of using certain types of object classes for storing and iterating through your data. 我想你也学到了很多关于你的程序和算法是如何工作的,以及使用某些类型的对象类来存储和迭代数据的成本含义。

Glowcode is a very nice profiler (when it works). Glowcode是一个非常好的分析器(当它工作时)。 It can attach to a running program and requires only symbol files - you don't need to rebuild. 它可以附加到正在运行的程序,只需要符号文件 - 您不需要重建。

Some versions pf visual studio 2005 (and maybe 2008) actually come with a pretty good performance profiler. 有些版本的视觉工作室2005(也许是2008年)实际上有一个非常好的性能分析器。
if you have it it should be available under the tools menu 如果你有它,它应该在工具菜单下可用
or you can search for a way to open the "performance explorer" window to start a new performance session. 或者您可以搜索打开“性能浏览器”窗口以启动新的性能会话的方法。
A link to MSDN MSDN的链接

FYI, Some versions of Visual Studio only come with a non-optimizing compiler. 仅供参考,某些版本的Visual Studio仅提供非优化编译器。 For one of my my MFC apps if I compile it with MINGW/MSYS ( gcc compiler ) with -o3 then it runs about 5-10x as fast as my release compile with Visual Studio. 对于我的一个MFC应用程序,如果我使用MINGW / MSYS(gcc编译器)和-o3编译它,那么它运行速度大约是我使用Visual Studio编译版本的5-10倍。

For example I have an openstreetmap xml compiler and it takes about 3 minutes ( the gcc compiled version) to process a 2.7GB xml file. 例如,我有一个openstreetmap xml编译器,它需要大约3分钟(gcc编译版本)来处理一个2.7GB的xml文件。 My visual studio compile of the same code takes about 18 minutes to run. 我的Visual Studio编译相同的代码大约需要18分钟才能运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM