Skip to content

generate headers include tree of whole C++ project in form of GraphViz graphs

License

Notifications You must be signed in to change notification settings

anetczuk/cpp-include-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ headers include graph

Do you want to see how looks headers include tree in your project? Then this tool is for You.

Generate headers include tree of whole C++ project in form of GraphViz graphs. Tool parses output of g++ and clang compiler and presents it in form of graph.

Key features:

  • generate include graphs
  • count number of includes in objects per header
  • estimate size of header with it's includes
  • rank headers per total size
  • generate HTML page with clickable graphs and statistics

Generator works with Makefile, make, cmake and catkin projects.

How to use?

Generator as input needs build log of gcc or clang compiler. Compilation have to be done using -H flag informing compiler to print include tree to stderr. Passing the flag to cmake and obtaining build log can be done in following way:

    cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \
          -DCMAKE_C_FLAGS="-H" \
          -DCMAKE_CXX_FLAGS="-H" \
          ...
    cmake --build . -- -j 1 2>&1 | tee build_log.txt

Similarly, running make can be done like this:

    make CXX_FLAGS="-H" -j1 2>&1 | tee build_log.txt

Following command works for Makefile-s generated by cmake (it's impossible to change compiler settings without calling cmake). For custom made Makefile-s investigate the file (try standarized CXX="g++" and CXXFLAGS="-H").

Note that cmake and make have to be executed with one job only (-j 1), because otherwise compiler output will be interweaved and impossible to parse.

When build log is collected then it's time to execute the generator. There is example of generating graph for cmake output:

    cppincludegraphgen -lf build_log.txt --reduce_dirs "/opt" "/usr" --outdir include_graph_reduced

Whole commands list can be found here. List is produced by calling cppincludegraphgen --help. Highlighted arguments:

  • --files_info information about source and compiled files. Parameter is helpful when compilation is done in containers or remote locations. File can be generated using cppincludegraphdump script.
  • --reduce_dirs informeds generator to cut subtree of headers in given directories amd present graph in reduced form (see examples).

Other arguments seems to be straightforward.

For more details see examples below.

Makefile example

In examples/cpp-makefile there is example of include tree generated based on Makefile project.

Generator is executed with following command for reduced and full graph respectively:

cppincludegraphgen -lf build_log.txt --build_regex "^g\+\+.*-o (\S*)$" --markhotpath --reduce_dirs "/opt" "/usr" --outdir include_graph_reduced

cppincludegraphgen -lf build_log.txt --build_regex "^g\+\+.*-o (\S*)$" --markhotpath --outdir include_graph_full

Note that there is --build_regex passed through command line. It highly depends on configuration of Makefile file and it's output to stdout.

include reduced graph

CMake example

In examples/cpp-cmake there is example of include tree generated based on CMake project.

Generator is executed with following command for reduced and full graph respectively:

cppincludegraphgen -lf cmake-tutorial.txt --namefromlogfile --nohighlight --reduce_dirs "/opt" "/usr" --outdir include_graph_reduced

cppincludegraphgen -lf cmake-tutorial.txt --namefromlogfile --nohighlight --outdir include_graph_full

include reduced graph

catkin example

Generator is executed with following command for reduced and full graph respectively:

cppincludegraphgen --log_dir "/path/to/catkin/log/dir" --log_name "build.make.log" --outdir catkin_include_graph

Generator will search for catkin log files in given directory, parse it and produce the graph. Alternatively list of log files can be passed as command line argument:

--log_files /path_01/build.log /path_02/build.log ...

References

License

BSD 3-Clause License

Copyright (c) 2022, Arkadiusz Netczuk <dev.arnet@gmail.com>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

About

generate headers include tree of whole C++ project in form of GraphViz graphs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published