GNU Make-如何添加时间戳输出(只需最少的makefile修改) [英] GNU Make - how to add timestamp output (with minimal makefile modification)
问题描述
我想更好地了解自己的构建作业指标,但不幸的是,make
本身并不输出时间戳.
I want to get a better idea of my build job metrics but unfortunately, make
doesn't output timestamps per se.
如果我运行make --print-data-base
,对于给定的目标,它将输出一行
If I run make --print-data-base
, for a given target it outputs a line
# Last modified 2016-08-15 13:53:16
但是那没有给我持续时间.
but that doesn't give me the duration.
问题
有没有办法在不修改每个目标的情况下获得建立目标的持续时间?有些目标位于makefile中,这些文件是在构建过程中生成的,因此无法修改其配方.
Is there a way to get duration of building a target without modifying each target? Some targets are inside makefiles which are generated DURING the build so not feasible to modify their recipes.
可能的解决方案
我可以执行预-并为每个目标添加后记,并以这种方式输出时间戳.
I could implement a pre- and post-recipe for every target and output a timestamp that way.
鉴于这是并行make
,这是一个好主意吗?显然,通过为每个目标调用前后食谱会增加构建时间,但我对此表示满意.
Is that a good idea given this is parallel make
? Obviously there would be increased build time from calling a pre- and post-recipe for every target but I'd be fine with that.
推荐答案
如果这是并行生成,则可以交错插入"preactions","actions"和"postactions".也就是说,您可能会得到如下输出:
If this is a parallel make, then the "preactions", "actions" and "postactions" may be interleaved. That is, you might get output like:
Pre-action 12:03:05
Pre-action 12:03:06
building foo...
building bar...
Post-action 12:04:17
Post-action 12:04:51
因此,您应该将TARGETNAME变量传递给操作前和操作后脚本.
So it would behoove you to pass a TARGETNAME variable to the pre-action and post-action scripts.
此外,当您并行运行事物时,还不需要知道开始和结束时间就知道操作需要多长时间.规则A可能比规则B花费更长的时间,这仅仅是因为规则B是单独运行,而规则A通过J与规则C共享处理器.
Also, start and end times are not all there is to know about how long an action takes, when you are running things in parallel; rule A might take longer that rule B, simply because rule B is running alone while rule A is sharing the processor with rules C through J.
除此之外,我认为这种方法没有问题.
Other than that, I see no problem with this approach.
这篇关于GNU Make-如何添加时间戳输出(只需最少的makefile修改)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!