问题描述
我过去使用过一些分析器,但从未发现它们特别容易.也许我挑了不好的,也许我真的不知道我在期待什么!但我想知道是否有任何标准"分析器可以简单地插入并工作?我不相信我需要大量详细的报告,只是为了找出主要的黑点.在这一点上,易用性对我来说更重要.
I've used a few profilers in the past and never found them particularly easy. Maybe I picked bad ones, maybe I didn't really know what I was expecting! But I'd like to know if there are any 'standard' profilers which simply drop in and work? I don't believe I need massively fine-detailed reports, just to pick up major black-spots. Ease of use is more important to me at this point.
我们使用的是 VC++ 2008(我个人运行标准版).我不认为 IDE 中有任何用于此的工具,从主菜单中看不到任何工具?
It's VC++ 2008 we're using (I run standard edition personally). I don't suppose there are any tools in the IDE for this, I can't see any from looking at the main menus?
推荐答案
VS 内置:
如果您有团队版,则可以使用 Visual Studio 分析器.
If you have team edition you can use the Visual Studio profiler.
其他选项:
否则检查此线程.
轻松创建自己的:
我个人使用基于 Win32 API 的内部构建的查询性能计数器.您可以在一百行或更少的代码中制作出漂亮且易于使用的东西.
I personally use an internally built one based on the Win32 API QueryPerformanceCounter. You can make something nice and easy to use within a hundred lines of code or less.
过程很简单:在您要分析的每个函数的顶部创建一个宏,称为 PROFILE_FUNC(),并将添加到内部管理的统计信息中.然后有另一个名为 PROFILE_DUMP() 的宏,它将输出转储到文本文档.
The process is simple: create a macro at the top of each function that you want to profile called PROFILE_FUNC() and that will add to internally managed stats. Then have another macro called PROFILE_DUMP() which will dump the outputs to a text document.
PROFILE_FUNC() 创建一个对象,该对象将使用 RAII 来记录该对象被销毁之前的时间量.此 RAII 对象的构造函数和析构函数都将调用 QueryPerformanceCounter
.您也可以在代码中保留这些行并通过 #define PROFILING_ON
PROFILE_FUNC() creates an object that will use RAII to log the amount of time until the object is destroyed. Both the constructor of this RAII object and the destructor will call QueryPerformanceCounter
. You could also leave these lines in your code and control the behavior via a #define PROFILING_ON
这篇关于什么是非常简单的 C++ 分析器 (VC++)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!