Profiling the C++ compilation process(剖析 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使编译器在编译时打印出每个函数名称,并在完成时打印有关每次传递的一些统计信息.
-Q Makes the compiler print out each function name as it is compiled, and print some statistics about each pass when it finishes.
-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 比/gcc/Debugging-Options.html">3.3.6) 查看此线程中的其他选项.
For compilers other than GCC (or GCC more ancient than 3.3.6) see the other options in this thread.
这篇关于剖析 C++ 编译过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:剖析 C++ 编译过程
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
