GNU Make - how to add timestamp output (with minim

2019-07-29 06:37发布

问题:

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.