本文介绍了剖析 C++ 编译过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倾向于编写相当大的模板化头文件 C++ 库,我的用户通常会抱怨编译时间.想了想之后,我突然想到我不知道时间都去哪儿了.是否有一些简单的方法可以使用通用编译器(例如 g++、icc 和 xlC)来分析 C++ 编译过程?例如,是否有可能了解在 C++ 编译的每个阶段中花费了多少时间??

I tend to write rather large templated header-only C++ libraries and my users commonly complain about compilation times. After thinking about the matter, it occurred to me that I have no idea where the time is going. Is there some simple way to profile the C++ compilation process with common compilers, such as g++, icc, and xlC? For instance, is it possible to get an idea of how much time is spent within each of the phases of C++ compilation?

推荐答案

对于 GCC调试选项 以查找在 C++ 编译的每个阶段花费了多少时间?

-Q使编译器在编译时打印出每个函数名称,并在完成时打印有关每次传递的一些统计信息.

-ftime-report使编译器在完成时打印一些有关每次传递所消耗的时间的统计信息.

-ftime-report Makes the compiler print some statistics about the time consumed by each pass when it finishes.

通行证在GCCINT 9:编译器的通行证和文件中进行了描述.

Passes are described in GCCINT 9: Passes and Files of the Compiler.

您可以在此处使用 -v -ftime-report 将单个源文件的 g++ 编译输出发布到 讨论它.GCC 邮件列表上可能有一些帮助.

You can post output of g++ compilation of single source file with -v -ftime-report here to discuss it. There could be some help on the GCC mailing list.

对于GCC 以外的编译器(或 GCC 比) 查看此线程中的其他选项.

For compilers other than GCC (or GCC more ancient than 3.3.6) see the other options in this thread.

这篇关于剖析 C++ 编译过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 08:57