Skip to content

About

C/C++ build profiler based on clang time tracing.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

clang-build-profiler

clang-build-profiler is a CLI tool that analyzes timings generated by clang++ -ftime-trace and generates a human-readable report, summarizing which parts of the build took the longest.

Quick showcase

  1. Build your project using clang++ with -ftime-trace flag enabled

  2. Point the CLI tool at the CMake build directory and select its desired output:

  1. Open the generated report:

  1. Available output formats include:
--output Description Requirements
mkdocs Nicest output for viewing, it uses MkDocs Material to serve an interactive GUI in browser pip install mkdocs-material
html Stand-alone HTML report, not as fancy, but doesn't require MkDocs None
terminal Colored in-terminal output, useful for small projects or with high level of pruning None
json JSON dump of profiling data, useful for custom analysis pipelines None
text Text file output, useful for saving human-readable build artifacts with profiling data None

Features

  • Builds a tree of includes and their parse timings
  • Builds a tree of template instantiations and their timings
  • Summarizes the information above into a digestible format
  • Prettifies standard templates and their expansion (e.g. std::basic_string<char, ...> ➜ std::string)
  • Automatically analyzes CMake builds with multiple targets

Documentation

The project website serves as its main form of documentation.

The docs can also be viewed directly from GitHub:

A shorter built-in documentation can be accessed with clang-build-profiler --help.

Motivation

In many cases, build times can be noticeably improved through a relatively minor reorganization. To make this feasible, however, one would need a proper tool capable of profiling the build process.

clang++ -ftime-trace introduced in version 9.0 provides a perfect backend for such a tool, it generates traces in the Chrome tracing format, which can be even opened directly using Chrome about:tracing. However, raw traces are quite cumbersome to analyze in respect to the things that we actually care about, so I implemented a tool to summarize the key information.

Dependencies

The source code of this project embeds several dependencies:

Library Version License Used for
UTL v8.3.3 MIT Formatting
fmt v12.1.0 MIT Formatting & terminal IO
glaze v6.0.0 MIT JSON parsing & serialization
argparse v3.2 MIT CLI argument parsing
fkYAML v0.4.2 MIT YAML parsing
Boost.Regex v7.0.1 Boost Regular expressions
cmrc #952ffdd MIT Embedding resources

Roadmap

  • Possibly a native GUI output with --output=gui
  • Refinements in template prettification
  • Tests on larger codebases
  • A better selection of summaries
  • Performance improvements

License

This project is licensed under the MIT License - see the LICENSE.md for details.

About

C/C++ build profiler based on clang time tracing.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages