GNU Make - how to add timestamp output (with minimal makefile modification)

六月ゝ 毕业季﹏ 提交于 2019-12-11 05:16:21

问题


I want to get a better idea of my build job metrics but unfortunately, make doesn't output timestamps per se.

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.

QUESTION

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.

POSSIBLE SOLUTION

I could implement a pre- and post-recipe for every target and output a timestamp that way.

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.


回答1:


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

So it would behoove you to pass a TARGETNAME variable to the pre-action and post-action scripts.

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.



来源:https://stackoverflow.com/questions/39083011/gnu-make-how-to-add-timestamp-output-with-minimal-makefile-modification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!