如何测量 scons 构建的每个组件的构建时间?

发布于 2024-09-12 22:38:12 字数 107 浏览 2 评论 0原文

我有一个使用 scons 构建的大型 C++ 项目。 它的构建速度很慢,我想进行一些更改以使其构建速度更快。 现在我想集中时间加速构建中最慢的部分。

如何找出哪些文件的编译时间最长?

I have a big C++ project that is built using scons.
Its building slow and I want to make some changes to try to make it build faster.
Now I'd like to focus my time speeding up the parts of the build that are slowest.

How can I work out which files are taking the longest to compile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

っ〆星空下的拥抱 2024-09-19 22:38:12

我知道这个问题很旧,并且已经被接受,但最近从另一个问题中引用了它。我认为一个更优雅的解决方案是使用 SCons --debug=time 命令行选项,如

I know this question is old, and has already been accepted, but it was recently referenced from another question. I think a much more elegant solution would be to use the SCons --debug=time command line option, as mentioned in this answer.

晌融 2024-09-19 22:38:12

如果您使用的是 LInux,则可以包装 gccg++,以便编译器的调用使用 gtime 实用程序。对编译器的每次调用都类似于:

/usr/bin/time /usr/bin/g++ [rest of command]

BASH 有一些神奇的语法,可以帮助您避免必须重新转义你的参数:

#!/bin/bash -f
PATH_TO_COMPILER_DIR=/usr/bin
/usr/bin/time $PATH_TO_COMPILER_DIR/"$@"

然后将你的 $PATH 变量指向你的编译器包装器。

然后通过选项 -j1 运行仅使用 1 个并行线程的 SCons。

If you're using LInux, you could wrapper gcc or g++ so that invocations of of the compiler use the gtime utility. Every call to the compiler would look like:

/usr/bin/time /usr/bin/g++ [rest of command]

BASH has some magical syntax that helps you avoid having to re-escape your arguments:

#!/bin/bash -f
PATH_TO_COMPILER_DIR=/usr/bin
/usr/bin/time $PATH_TO_COMPILER_DIR/"$@"

Then point your $PATH variable to have your compiler wrapper.

Then run SCons with only 1 parallel thread via option -j1.

空‖城人不在 2024-09-19 22:38:12

我通过在 CXXCOM 变量的开头添加一些额外的内容来解决这个问题。 Scons 使用这个变量来进行实际的编译:

if os.getenv('BUILD_STYLE')=='timing':
  cxxcom = env['CXXCOM']
  env.Replace( CXXCOM = 'time '+cxxcom )

然后我使用类似的东西运行 scons

BUILD_STYLE=timing scons > timing_log.txt

,最后使用一些 vim 宏整理日志。

I solved this by adding some extra stuff to the start of the CXXCOM variable. Scons uses this variable to do the actual compilation:

if os.getenv('BUILD_STYLE')=='timing':
  cxxcom = env['CXXCOM']
  env.Replace( CXXCOM = 'time '+cxxcom )

I then run scons using something like this

BUILD_STYLE=timing scons > timing_log.txt

and finally tidy up the log using some vim macros.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文