如何对 GNU Make 文件进行性能分析

发布于 2024-12-01 13:10:57 字数 131 浏览 2 评论 0原文

我们有很多 GNU Make 文件。我想对构建过程中使用的每个目标进行计时,以识别任何性能瓶颈。是否有一种工具或技术可以方便且自动地执行此操作?

我可能想解析这些结果,以随着构建的变化和增长密切关注性能因素(但它已经相当大和复杂)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谎言 2024-12-08 13:10:57

我想我以前在这里见过这个问题......

您可以用调用 shell 但对其执行进行计时的东西来替换 shell,并将结果与​​目标名称一起写入某处。每个目标只会构建一次(否则 make 将拒绝运行),因此您所要做的就是将时间加在一起。

非常粗略的示例:替换

make

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

如果您不想将时间加在一起,则还必须以某种方式将每个目标的命令连接到单个命令中。一种方法是预处理 Makefile,但由于各种原因,除了最简单的 Makefile 之外,这对于任何其他 Makefile 都不起作用。

例如,尝试类似的事情

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

是朝这个方向非常粗暴的尝试。

有多种替代方法,但我认为唯一真正的解决方案是添加此功能; GNU make 是用非常可移植的 C 语言编写的,因此应该不难做到。

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.

画尸师 2024-12-08 13:10:57

跳出框框思考:您是否偶然通过使用递归 make(即规则 cd 到子目录并再次调用 make)而浪费了宝贵的电子?那就是你的问题了。非递归 make 可以快 2 个数量级。

有关详细信息,请参阅被认为有害的递归 make

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

孤城病女 2024-12-08 13:10:57

如果您尝试分析静态 Makefile,请查看 make-profiler:

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

它的作用就像是 make 的包装器,预处理 Makefile、收集日志并绘制调用 -带有时序信息的图表。如果您正在创建长期运行的数据处理管道,它尤其有用。

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.

杀お生予夺 2024-12-08 13:10:57

下面将帮助您了解每个命令是如何运行的,以及由于错误使用变量而运行了多少次:, :=

make SHELL='/bin/sh -x'

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文