Profiling the C++ compilation process

前端 未结 7 939
栀梦
栀梦 2020-11-28 19:48

I tend to write rather large templated header-only C++ libraries and my users commonly complain about compilation times. After thinking about the matter, it occurred to me t

7条回答
  •  离开以前
    2020-11-28 20:02

    Clang 9 (and newer) has a -ftime-trace flag, which makes it output a profiling report as JSON (in addition to an object file).

    You can import this file into a profiler that comes with Chrome (chrome://tracing) to get a nice visualisation:

    The bars correspond to headers that had to be parsed, and for each header, specific classes (and probably other constructs) that had to be parsed. It also reports time spent on instantiating specific templates.

提交回复
热议问题