我正在使用 scons 构建两个项目。一个项目效果很好,而另一个(更复杂)项目则非常令人沮丧。这是我在为第二个项目运行 scons 时看到的内容:
S time scons
scons: Reading SConscript files ...
<<< Generates some code, output seen in console >>>
scons: done reading SConscript files.
scons: Building targets ...
<<< 30+ second delay, with no output >>>
<<< Building occurs, with output, only 2-3 seconds >>>
scons: done building targets.
<<< 15-20 second delay, no output to console >>>
real 0m54.600s
user 0m2.612s
sys 0m9.236s
$
所以它看起来读取 SConscript 文件的速度足够快,但是当它完成时,有一个 30 秒以上的巨大延迟,它似乎什么也没做。如果我在这里按 Ctrl-C,延迟仍然存在;在延迟过去之前,它不会处理 Ctrl-C 并终止运行。同样,在所有事情完成后,还有另一个神秘的延迟;这种延迟也是不可中断的。
我不知道发生了什么,但本应等待 4 秒的时间却等待了 54 秒,这真是令人沮丧!我一直无法找到一种方法让 scons 告诉我在这些延迟期间它在做什么。有谁知道如何获取有关其正在做什么的更多信息?
Update:我使用 profile= 选项运行 scons 来获取分析信息,然后打印出排序列表;以下是前几项:
2016 年 3 月 13 日星期日 17:46:04 scons.profile.data
1253379 function calls (1208007 primitive calls) in 61.303 seconds
排序依据:内部时间、函数名称
ncalls tottime percall cumtime percall filename:lineno(function)
41 32.778 0.799 32.783 0.800 {cPickle.loads}
1 17.691 17.691 17.691 17.691 {cPickle.dump}
456 5.337 0.012 5.337 0.012 {method 'read' of 'file' objects}
24 2.844 0.118 2.844 0.118 {posix.waitpid}
5 0.245 0.049 0.245 0.049 {built-in method poll}
. . .
230 0.016 0.000 0.029 0.000 {cPickle.dumps}
其余 1000 多个条目的总时间均小于 0.1 秒。请注意,前两个条目与两个神秘延迟相匹配! (为了完整起见,我还显示了另一个 cPickle 调用,尽管它非常小。)是什么导致 cPickle 使用如此多的时间?
Update 2: 今天又跑了一次,得到的时间如下:
real 1m42.446s
user 0m4.104s
sys 0m11.648s
请注意,这只是编译两个小 .c 文件!然后,我重命名了.sconsign.dblite并再次运行它;当然,它重建了一切,但速度已经快得多:
real 0m34.229s
user 0m28.392s
sys 0m2.932s
好多了!所以现在,我使用需要编译的相同两个文件再次运行它,我得到了:
real 0m3.494s
user 0m2.556s
sys 0m0.460s
现在,那很好!我决定查看 .sconsign.dblite 和旧版本,并发现以下内容:
$ ls -la .scons*
-rw-rw-r-- 1 rsg rsg 189513 Mar 14 20:31 .sconsign.dblite
-rw-rw-r-- 1 rsg rsg 1440507770 Mar 14 20:23 .sconsign.dblite.save
相差7600倍!!!所以现在看来这个问题已经解决了,不过很高兴知道 .sconsign.dblite 发生了什么,以及如何防止它再次发生。
环境:
$ scons --version
SCons by Steven Knight et al.:
script: v2.1.0.r5357[MODIFIED], 2011/09/09 21:31:03, by bdeegan on ubuntu
engine: v2.1.0.r5357[MODIFIED], 2011/09/09 21:31:03, by bdeegan on ubuntu
engine path: ['/usr/lib/scons/SCons']
Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 The SCons Foundation
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
$ python --version
Python 2.7.3
此外,Ubuntu 正在虚拟机中运行,在一台像样的 Windows 7 机器上的 VirtualBox v5.0.16 下。