使用 Eclipse 时在 Windows 上分析 C 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2302425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Profiling C code on Windows when using Eclipse
提问by Pieter
I know I can profile my code with gprof
and kprof
on Linux. Is there a comparable alternative to these applications on Windows?
我知道我可以使用Linuxgprof
和kprof
在 Linux 上分析我的代码。Windows 上是否有这些应用程序的类似替代方案?
采纳答案by Patrick
Commercial software:
商业软件:
- Rational Quantify (expensive, slow, but very detailed)
- AQTime (less expensive, less slow, a bit detailed)
- Rational Quantify(昂贵、缓慢但非常详细)
- AQTime(更便宜,更慢,有点详细)
Free software:
免费软件:
- Very sleepy (www.codersnotes.com)
- Luke StackWalker (lukestackwalker.sourceforge.net)
These commercial alternatives change the compiled code by 'instrumenting' (adding instructions) to it and perform the timing withing the added instructions. This means that they cause your application to slow down seriously.
这些商业替代品通过“检测”(添加指令)来更改编译后的代码,并使用添加的指令执行计时。这意味着它们会导致您的应用程序严重变慢。
These free alternatives use sampling, meaning they are less detailed, but very fast. In practice I found that especially Very Sleepy is very good to have a quick look at performance problems in your application.
这些免费替代品使用抽样,这意味着它们不太详细,但速度非常快。在实践中,我发现尤其非常困是非常好的快速查看应用程序中的性能问题。
回答by AndiDog
There's a MinGW port of gprof that works just about the same as the Linux variant. You can either get a full MinGW installation(I think gprof is included but not sure) or get gprof from the MinGW binutils package.
gprof 有一个 MinGW 端口,其工作方式与 Linux 变体几乎相同。您可以获取完整的MinGW 安装(我认为包含 gprof 但不确定)或从MinGW binutils 包中获取 gprof 。
For Eclipse, there's TPTPbut it doesn't support profiling C/C++ as far as I know.
对于 Eclipse,有TPTP,但据我所知,它不支持分析 C/C++。
回答by Mike Dunlavey
What's the reason for profiling? Do you want to a) measure times and get a call graph, or b) find things to change to make the code faster? (These are not the same.)
分析的原因是什么?您想 a) 测量时间并获得调用图,还是 b) 找到要更改的内容以使代码更快?(这些不一样。)
If (b) you can use this trick, using the Pause button in Eclipse.
如果 (b) 你可以使用这个技巧,使用 Eclipse 中的暂停按钮。
Added: Maybe it would help to convey some experience of what performance problems are actually like, and where you can expect to find them. Here are some simple examples:
补充:也许这有助于传达一些关于性能问题实际是什么样的体验,以及您可以在哪里找到它们。下面是一些简单的例子:
An insertion sort (order n^2) where the items being sorted are strings, and are compared by a string-compare function. Where is the hot-spot? in string-compare. Where is the problem? In the sort where string-compare is called. If n=10 it's not a problem, but if n=1000, suddenly it takes a long time. The point where string-compare is called is "cold", but that's where the problem is. A small number of samples of the call stack pinpoint it with certainty.
An app that loads plugins takes a long time to start up. A profiler says basically everything in it is "cold". Something that measures I/O time says it is almost all I/O time, which seems like what you might expect, so it might seem hopeless. But, stack samples show a large percentage of time is spent with the stack about 20 layers deep in the process of reading the resource part of plugin dlls for the purpose of translating string constants into the local language. Investigating further, you find that most of the strings being translated are not the the kind that actually needtranslation. They were just put in "in case" they might need translation, and were never thought to be something that could cause a performance problem. Fixing that issue brings a hefty time savings.
一种插入排序(顺序 n^2),其中被排序的项目是字符串,并由字符串比较函数进行比较。热点在哪里?在字符串比较中。问题出在哪儿?在调用字符串比较的排序中。如果 n=10 没有问题,但是如果 n=1000,突然就需要很长时间。调用 string-compare 的点是“冷的”,但这就是问题所在。调用堆栈的少量样本可以肯定地指出它。
加载插件的应用程序需要很长时间才能启动。分析器基本上说里面的所有东西都是“冷的”。测量 I/O 时间的东西说它几乎是所有的 I/O 时间,这看起来像你所期望的那样,所以它可能看起来没有希望。但是,堆栈示例显示,在读取插件 dll 的资源部分以将字符串常量转换为本地语言的过程中,大约 20 层深度的堆栈花费了大量时间。进一步调查,您会发现大多数被翻译的字符串并不是真正需要翻译的那种。他们只是被放在“以防万一”他们可能需要翻译,并且从未被认为是可能导致性能问题的东西。解决这个问题可以节省大量时间。
So it is common to think in terms of "hotspots" and "bottlenecks", but most programs, especially the larger ones, tend to have performance problems in the form of function calls requesting work that doesn't really need to be done. Fortunately they display themselves on the call stack during the time that they are spending.
因此,通常会根据“热点”和“瓶颈”进行思考,但大多数程序,尤其是较大的程序,往往会以函数调用的形式出现性能问题,请求的工作实际上并不需要完成。幸运的是,他们在花费的时间里将自己显示在调用堆栈上。
回答by Eli Bendersky
Yes, you can profile code with Visual Studio
是的,您可以使用 Visual Studio分析代码