如何确定 header 被处理的次数?

How can I determine the number of times a header is processed?

目前,我的 C 代码库编译速度相对较快。但是,我想利用 知情 方法来减少给定 header 是 re-processed.

的次数

我想能够查看引用计数会帮助我这样做。我该怎么做?

CLang 和 GCC 都支持 -H 选项。它会将包含的每个头文件转储到控制台中。然后,您可以轻松阅读这些行并分析它们以检测编译器瓶颈。

来自man gcc

-H Print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the #include stack it is.

Precompiled header files are also printed, even if they are found to be invalid; an invalid precompiled header file is printed with ...x and a valid one with ...!.