简体   繁体   English

分析编译时间

[英]Profiling compilation time

I have a C++ code which I am compiling using VC7 and it is taking a lot of time to build it.我有一个 C++ 代码,我正在使用 VC7 编译它,构建它需要很多时间。 Is there any way I could profile it and find why it is taking time to build ?有什么方法可以分析它并找出构建它需要时间的原因吗?

In Visual Studio 2008, there's a setting for turning on build timing.在 Visual Studio 2008 中,有一个用于打开构建计时的设置。 It might be there in VC7 as well...它可能也存在于 VC7 中......

Tools / Options / Projects and Solutions / VC++ Project Settings / Build Timing: Yes Tools / Options / Projects and Solutions / VC++ Project Settings / Build Timing: Yes

This applies to C++ projects, which (as of VS2008) don't use MSBuild.这适用于不使用 MSBuild 的 C++ 项目(从 VS2008 开始)。 For MSBuild-based projects (such as C#), you want to increase the verbosity:对于基于 MSBuild 的项目(例如 C#),您希望增加详细程度:

Tools / Options / Projects and Solutions / Build and Run / MSBuild project build output verbosity Tools / Options / Projects and Solutions / Build and Run / MSBuild project build output verbosity

By default, it's set to "Minimal".默认情况下,它设置为“最小”。

If the code is template-intensive, then you could try doing the template instantiation profiling.如果代码是模板密集型的,那么您可以尝试进行模板实例化分析。 Steven Watanabe came up with theprofiler and if I remember correctly it was supposed to work with VS (don't know the version). Steven Watanabe 想出了分析器,如果我没记错的话,它应该可以与 VS 一起使用(不知道版本)。

Is the source code on a network?源代码在网络上吗? This sometimes slows the compilation a lot.这有时会大大减慢编译速度。

Recent Microsoft's C++ Build Insights SDK has introduced an option /timetrace to its vcperf which allows you to profile your build and visualise the build times of specific components in form of a flame graph inside of any chromium-based browser.最近,Microsoft 的C++ Build Insights SDK为其vcperf引入了一个选项/timetrace ,它允许您在任何基于铬的浏览器中以火焰图的形式分析您的构建并可视化特定组件的构建时间。

Assuming you have vcperf downloaded and installed, you need to:假设您已经下载并安装了vcperf ,您需要:

  1. Start its session by executing通过执行启动它的会话
vcperf /start SessionName
  1. Run your build (the events are captured system-wide by vcperf)运行您的构建(事件由 vcperf 在系统范围内捕获)
  2. Stop the session停止会话
vcperf /stop SessionName /timetrace output.json

You can now run your chromium-based browser, type in <browser_name>://tracing , (for example chrome://tracing ) and load up the output.json file for visualisation.您现在可以运行基于铬的浏览器,输入<browser_name>://tracing ,(例如chrome://tracing )并加载output.json文件以进行可视化。

Example visualisation taken from here .此处获取的示例可视化

If your code makes extensive use of template, you might be interested in Templight , a tool developed by a hungarian research team for debugging and profiling C++ template metaprograms ( paper ).如果您的代码大量使用模板,您可能会对Templight感兴趣,这是由匈牙利研究团队开发的用于调试和分析 C++ 模板元程序的工具(论文)。 It seems very promising, but I'm not sure the tool is available for download...看起来很有前途,但我不确定该工具是否可供下载...

My guess is that it would be difficult to get useful results from profiling.我的猜测是很难从分析中获得有用的结果。 You could look at the create times of each .obj file and check if there are any files that are particularly slow, but I doubt this would be the case.您可以查看每个 .obj 文件的创建时间并检查是否有任何文件特别慢,但我怀疑情况是否如此。

Have you gone through the compiler options such as pre-compiled headers to see what improvements ths provides?您是否浏览过编译器选项(例如预编译头文件)以查看其提供了哪些改进? Similarly, turning off the optimizer where it is not required can speed the build up significantly.同样,关闭不需要的优化器可以显着加快构建速度。 My advice would be to take some time to try out a few 'what if' scenarios.我的建议是花一些时间尝试一些“假设”场景。

如果可能,您可以在您的情况下尝试#include 所有 .cpp 文件到单个编译单元中的技巧,只是为了检查是否有很多文件和许多包含的开销。

使用预编译头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM