Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 changes and grows (but it´s already quite large and complex).

like image 883
Deleted Avatar asked Aug 24 '11 12:08

Deleted


2 Answers

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.

like image 76
reinierpost Avatar answered Sep 28 '22 23:09

reinierpost


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

like image 45
Jens Avatar answered Sep 28 '22 23:09

Jens