Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

ClangBuildAnalyzer

> 编程语言
Open source

Clang build analysis tool using -ftime-trace

1.3K stars0 likes1 views
WebsiteGitHub

About

Clang build analysis tool using -ftime-trace

Clang Build Analyzer

Clang C/C++ build analysis tool when using Clang 9+ -ftime-trace. The -ftime-trace compiler flag (see blog post or Clang 9 release notes) can be useful to figure out what takes time during compilation of one source file. This tool helps to aggregate time trace reports from multiple compilations, and output "what took the most time" summary:

  • Which files are slowest to parse? i.e. spend time in compiler lexer/parser front-end
  • Which C++ templates took the most time to instantiate?
  • Which files are slowest to generate code for? i.e. spend time in compiler backend doing codegen and optimizations
  • Which functions are slowest to generate code for?
  • Which header files are included the most in the whole build, how much time is spent parsing them, and what are the include chains of them?

Usage

  1. Start the build capture: ClangBuildAnalyzer --start

    This will write current timestamp in a ClangBuildAnalyzerSession.txt file under the given artifacts_folder. The artifacts folder is where the compiled object files (and time trace report files) are expected to be produced by your build.

  2. Do your build. Does not matter how; an IDE build, a makefile, a shell script, whatever. As long as it invokes Clang and passes -ftime-trace flag to the compiler (Clang 9.0 or later is required for this).

  3. Stop the build capture: ClangBuildAnalyzer --stop

    This will load all Clang time trace compatible *.json files under the given artifacts_folder that were modified after --start step was done (Clang -ftime-trace produces one JSON file next to each object file), process them and store data file into a binary capture_file.

  4. Run the build analysis: ClangBuildAnalyzer --analyze

    This will read the capture_file produced by --stop step, calculate the slowest things and print them. If a ClangBuildAnalyzer.ini file exists in the current folder, it will be read to control how many of various things to print.

Aternatively, instead of doing --start and --stop steps, you can do ClangBuildAnalyzer --all after your build; that will include all the compatible *.json files for analysis, no matter when they were produced.

Analysis Output

The analysis output will look something like this:

…

Granularity and amount of most expensive things (files, functions, templates, includes) that are reported can be controlled by having an ClangBuildAnalyzer.ini file in the working directory. Take a look at ClangBuildAnalyzer.ini for an example.

Building it

  • Windows: Visual Studio 2019 solution at projects/vs2019/ClangBuildAnalyzer.sln.
  • Mac: Xcode 10.x project at projects/xcode/ClangBuildAnalyzer.xcodeproj.
  • Linux: Makefile for gcc (tested with 7.4), build with make -f projects/make/Makefile.
  • You can also use provided CMakeLists.txt, if you want to build using CMake.

Limitations

  • Does not capture anything related to linking or LTO right now.
  • May or may not scale to huge builds (I haven't tried on something ginormous like a Chrome build). However I have tried it on Unity editor and Blender builds and it worked fine.

License

License for the Clang Build Analyzer itself is Unlicense, i.e. public domain. However, the source code includes several external library source files (all under src/external), each with their own license:

  • cute_files.h from RandyGaul/cute_headers: zlib or public domain,
  • cwalk from likle/cwalk: MIT,
  • enkiTS, from dougbinks/enkiTS: zlib, version 058150d2 (2024 Apr),
  • flat_hash_map, from skarupke/flat_hash_map: Boost 1.0,
  • inih, from benhoyt/inih: BSD 3 clause,
  • llvm-Demangle, part of LLVM: Apache-2.0 with LLVM-exception,
  • simdjson from lemire/simdjson: Apache-2.0, version 3.10.1 (2024 Aug),
  • sokol_time.h from floooh/sokol: zlib/libpng,
  • xxHash from Cyan4973/xxHash: BSD 2 clause, version 0.8.2 (2023 Jul).

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++build-analysisclang

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言