头文件包含静态分析工具?

问题描述:

近日透露,我认为我们的一个单一来源文件包括在编译时超过3400头一个同事。我们有获得在构建编过1000翻译单元,产生了巨大的性能损失超过了肯定不是所有的头文件。

A colleague recently revealed to me that a single source file of ours includes over 3,400 headers during compile time. We have over 1,000 translation units that get compiled in a build, resulting in a huge performance penalty over headers that surely aren't all used.

是否有任何静态分析工具,将能够以这样的森林树木阐明,特别是给我们来决定哪些我们应该削出来的工作能力?

Are there any static analysis tools that would be able to shed light on the trees in such a forest, specifically giving us the ability to decide which ones we should work on paring out?

更新

上找到,包括一个头文件的费用一些有趣的信息在这里(和类型,包括警卫,以优化其列入) ,从始发this问题。

Found some interesting information on the cost of including a header file (and the types of include guards to optimize its inclusion) here, originating from this question.

的输出GCC -w -H<文件> 可能是有用的(如果你解析并把一些计数)的 -w 在那里共进晚餐preSS的所有警告,这可能是笨拙的处理。

The output of gcc -w -H <file> might be useful (If you parse it and put some counts in) the -w is there to suppress all warnings, which might be awkward to deal with.

从海合会文档:

-H

打印使用的每个头文件的名称,除了其它正常活动。每名缩进显示在有多深
  的#include 栈是。 precompiled头文件还印,
  即使它们被发现是无效的;无效precompiled头
  文件打印与 ... X 和一个有效的与 ... 。

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 ...!.

输出看起来是这样的:

. /usr/include/unistd.h
.. /usr/include/features.h
... /usr/include/bits/predefs.h
... /usr/include/sys/cdefs.h
.... /usr/include/bits/wordsize.h
... /usr/include/gnu/stubs.h
.... /usr/include/bits/wordsize.h
.... /usr/include/gnu/stubs-64.h
.. /usr/include/bits/posix_opt.h
.. /usr/include/bits/environments.h
... /usr/include/bits/wordsize.h
.. /usr/include/bits/types.h
... /usr/include/bits/wordsize.h
... /usr/include/bits/typesizes.h
.. /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/include/stddef.h
.. /usr/include/bits/confname.h
.. /usr/include/getopt.h
. /usr/include/stdio.h
.. /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/include/stddef.h
.. /usr/include/libio.h
... /usr/include/_G_config.h
.... /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/include/stddef.h
.... /usr/include/wchar.h
... /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/include/stdarg.h
.. /usr/include/bits/stdio_lim.h
.. /usr/include/bits/sys_errlist.h
Multiple include guards may be useful for:
/usr/include/bits/confname.h
/usr/include/bits/environments.h
/usr/include/bits/predefs.h
/usr/include/bits/stdio_lim.h
/usr/include/bits/sys_errlist.h
/usr/include/bits/typesizes.h
/usr/include/gnu/stubs-64.h
/usr/include/gnu/stubs.h
/usr/include/wchar.h