开发者

How to performance analyse GNU Make files

We have a lot of GNU Make-files. I´d like to time each target used during build to identify any performance bottlenecks. Is there a tool or technique to do this in a convenient and automatic way?

I might like to parse these results to keep tabs on the performance factor as the build c开发者_如何转开发hanges and grows (but it´s already quite large and complex).


I think I've seen this question here before ...

You can replace the shell with something that calls a shell but times its execution, and writes the result somewhere together with the target name. Each target will be built only once (or make would refuse to run) so all you'll have to do is add the times together.

Very crude example: replace

make

with

make SHELL='echo $@: && time sh'

If you don't want to add the times together, you also have to somehow join the commands for each target into a single command. One way to do that is by preprocessing the Makefile, but for various reasons, that is not going to work well for any but the simplest of Makefiles.

E.g. trying something like

perl -0pe 's/([^:])\s*\n\t[@-]?/$1; /g' Makefile | make -f - SHELL='echo $@: && time sh'

is a very crude stab in that direction.

There are various alternative approaches, but I think the only real solution is to add this feature to make; GNU make is written in very portable C so that shouldn't be very hard to do.


Thinking outside the box: are you by chance wasting precious electrons by using recursive make, i.e. where rules cd into subdirectories and call make again? Then that is your problem. A nonrecursive make can be faster by 2 orders of magnitude.

For details see Recursive make considered harmful


If you are trying to profile a static Makefile, have a look at make-profiler:

https://github.com/gojuno/make-profiler

It acts like a wrapper around make that preprocesses Makefile, collects logs and draws a call-graph with timing information. It is especially useful if you are making a long-running data-processing pipeline.


The following will help you understand how each command is running, and how many times because of wrongly used variables :, :=

make SHELL='/bin/sh -x'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜