我怎么知道为什么g ++需要很长的时间在一个特定的文件? [英] How do I find out why g++ takes a very long time on a particular file?
问题描述
我建立了许多自动生成的代码,包括一个特别大的文件(〜15K行),在linux上使用mingw32交叉编译器。大多数文件都非常快,但是这个大文件需要非常长的时间(〜15分钟)来编译。
I am building a lot of auto-generated code, including one particularly large file (~15K lines), using a mingw32 cross compiler on linux. Most files are extremely quick, but this one large file takes an unexpectedly long time (~15 minutes) to compile.
我试图操纵各种优化标志,有任何效果,没有任何运气。我真正需要的是一些方法来确定g ++在做这是花费这么长时间。是否有任何(相对简单的)g ++生成关于不同编译阶段的输出,以帮助我缩小挂起的可能性。
I have tried manipulating various optimization flags to see if they had any effect, without any luck. What I really need is some way of determining what g++ is doing that is taking so long. Are there any (relatively simple) ways to have g++ generate output about different phases of compilation, to help me narrow down what the hang-up might be?
很遗憾,没有重建这个交叉编译器的能力,所以添加调试信息到编译器,并且不可能通过它。
Sadly, I do not have the ability to rebuild this cross-compiler, so adding debugging information to the compiler and stepping through it is not a possibility.
文件中有什么:
- 一堆包括
- 一串字符串比较
- 一堆if-then检查和构造函数调用
该文件是一个工厂,用于生产某一特定子类父类。
The file is a factory for producing a ton of different specific subclasses of a certain parent class. Most of the includes, however, are nothing terribly fancy.
根据Neil的建议,-ftime-report的结果巴特沃思,表明生命分析阶段需要921秒,占用了15分钟的大部分时间。
The results of -ftime-report, as suggested by Neil Butterworth, indicate that the "life analysis" phase is taking 921 seconds, which takes up most of the 15 minutes.
看起来这是在数据流分析期间发生的。文件本身是一组条件字符串比较,通过作为字符串提供的类名构造一个对象。
It appears that this takes place during data flow analysis. The file itself is a bunch of conditional string comparisons, constructing an object by class name provided as a string.
我们认为更改这一点可以指向一个名称到函数指针的映射可能会改善一些东西,所以我们要尝试一下。
We think changing this to point into a map of names to function pointers might improve things a bit, so we're going to try that.
实际上,生成一堆工厂函数(每个对象)并创建一个从对象的字符串名称到指向其工厂函数的指针减少编译时间从原来的15分钟到约25秒,这将节省大量的时间在他们的建设。
Indeed, generating a bunch of factory functions (per object) and creating a map from the string name of the object to a pointer to its factory function reduced compile time from the original 15 minutes to about 25 seconds, which will save everyone tons of time on their builds.
再次感谢Neil Butterworth关于-ftime -report。
Thanks again to Neil Butterworth for the tip about -ftime-report.
推荐答案
不会提供所有你想要的细节,但尝试使用 v
(详细)和 -ftime-report
标志。后者产生了编译器所做的工作的总结。
Won't give all the details you want, but try running with the -v
(verbose) and -ftime-report
flags. The latter produces a summary of what the compiler has been up to.
这篇关于我怎么知道为什么g ++需要很长的时间在一个特定的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!