Makefile分析 [英] Makefile profiling

查看:84
本文介绍了Makefile分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个基于Makefile的构建系统,我的用户觉得它的工作速度太慢.为了解决这个问题,让我们将性能定义为弄清楚应该实际执行的时间.

So I have this Makefile based build system that my users feel is working too slowly. For the sake of this question lets define performance as the time it takes make to figure out what it should actually do.

我可以看到一些优化的途径-

I can see some avenues for optimization --

  • 由于包含Makefile片段,减少了Makefile的解析次数和DAG的重新计算.
  • 使用make -C
  • 减少转到外部Makefile的次数
  • 减少变量展开
  • Reducing the number of times Makefile is parsed and the DAG recalculated due to including a Makefile fragment.
  • Reducing the number of going to an external Makefile with make -C
  • Reducing variable expansions
  • etc.

-但是我想首先知道我的瓶颈在哪里.由于不进行概要分析而不进行优化会浪费生命,因此我想问一下:如何配置Makefile?

-- however I want to know first where are my bottlenecks. Since optimization without profiling is a waste of life, I want to ask: How to profile a Makefile?

假设我继承的系统设计合理,即它已经实现了交易中最常见的技巧:(主要是)非递归make,ccache,预编译头文件,自动生成的头文件依赖项等.

Assume that the system I inherited is fairly well designed, i.e. it already implements the most common tricks of the trade: (mostly) non recursive make, ccache, precompiled headers, auto generated header dependencies etc).

...只是为了抢先一些可能的答案.我知道可能会有比GNU更快速,更好的构建系统-(就我个人而言,我很想知道CMake员工会对Ninja系统提出什么建议)-但不幸的是,更换构建系统并不在行之列.

... and just to preempt some of the possible answer. I know that there might be faster and better build systems then GNU make - (Personally, I am eagerly waiting to see what the CMake folks will come up with regards to the Ninja system) - but unfortunately swapping build system is not in the cards.

推荐答案

由于您对Make决定要做什么而不是要做的时间感兴趣,因此您应该查看

Since you're interested in the time it takes Make to decide what to do, rather than do it, you should look into options for getting Make to not actually do things:

  • -q(问题)将仅决定要执行的操作,不执行任何操作,不执行任何打印操作,但是返回指示是否必须执行任何操作的退出状态代码.您只需为您感兴趣的任何目标(包括全部")计时.
  • -n(无操作)将使它打印配方,而不是执行它们.看着它们滚动,将使您大致了解Make如何花费时间,并且如果您愿意,可以做一些巧妙的技巧来计时该过程.
  • -t(触摸)将使其触摸需要重建的目标文件,而不是实际重建它们.然后,脚本可以查看文件的更新时间,找出较大的差距,并告诉您需要大量考虑的目标.
  • -q (question) will have it simply decide what has to be done, do nothing, print nothing, but return an exit status code indicating whether anything has to be done. You could simply time this for any target you're interested in (including "all").
  • -n (no-op) will have it print the recipes, rather than execute them. Watching them scroll by will give you a general sense of how Make is spending its time, and if you like you can do clever piping tricks to time the process.
  • -t (touch) will have it touch the target files that need to be rebuilt, instead of actually rebuilding them. A script could then look at the update times on the files, find the big gaps and tell you which targets required a lot of forethought.

我错了.

Make构造DAG并确定在重建任何目标之前必须重建的目标.因此,一旦开始执行规则,打印配方或触摸文件,我们感兴趣的工作部分就结束了,可观察的时间也变得一文不值了,所以-n-t选项并不好,但仍然可用作粗略工具. -d还将告诉您Make的思考过程;它不会告诉您时间安排,但会指出哪些目标需要很多步骤来考虑.

Make constructs the DAG and decides which targets must be rebuilt before it rebuilds any of them. So once it starts executing rules, printing recipes or touching files, the part of the job we're interested in is over, and the observable timing is worthless.So the -n and -t options are no good, but -q is still useful as a coarse tool. Also -d will tell you Make's thought process; it won't tell you timing, but it will indicate which targets require many steps to consider.

这篇关于Makefile分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆