测量(分析)Makefile 的每个目标所花费的时间
当我执行 make all
时,有没有办法递归地回显在 Makefile
的每个目标中花费的(系统、用户、实际)时间?
我想以更精细的方式对项目的编译进行基准测试,而不仅仅是 time make all
。理想情况下,它会回显已执行目标的树,每个目标都包含其所有依赖项所花费的时间。如果它可以与 -j
(并行 make)一起使用,那就太好了。顺便说一句,我的 Makefile 是非递归的(不会为每个主要目标生成另一个 make 实例)。
谢谢!
Is there a way to echo the (system, user, real) time spent in each target of a Makefile
recursively when I do make all
?
I'd like to benchmark the compilation of a project in a more granular way than just time make all
. Ideally, it would echo a tree of the executed target, each one with the time spent in all its dependencies. It'd be great also if it could work with -j
(parallel make). And by the way my Makefile
is non-recursive (doesn't spawn another make
instance for each main targets).
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Gnu Make 使用 $(SHELL) 变量来执行目标中的命令。
默认情况下它设置为/bin/sh。
您可以将此变量设置为将执行“time”命令给出的命令的脚本。像这样的事情:
在你的makefile中指定SHELL变量,在顶部的某个位置:
并在文件./report_time.sh中:
将'sh'命令替换为Makefile中指定的原始SHELL(如果有)。
这将报告时间。
但是,这不会告诉您 report_time.sh 脚本正在运行的目标。一种解决方案是在 makefile 中的每个目标条目中添加目标名称 ($@),以便它也将传递到 report_time.sh 脚本。
Gnu Make uses the $(SHELL) variable to execute commands in the targets.
By default it is set to /bin/sh.
You can set this variable to a script that will execute the command given with the "time" command. Something like this:
In your makefile specify the SHELL variable, somewhere at the top:
and in the file ./report_time.sh:
The replace the 'sh' command with the original SHELL specified in the Makefile if any.
This will report the timings.
However This will not tell you what target the report_time.sh script is running. One solution for this is to prepend the target name ($@) in each target entry in the makefile so that it will be passed to the report_time.sh script as well.
remake --profile 是
make 的直接替代品
。它生成 callgrind 格式的目标调用树。remake --profile is a drop-in replacement for
make
. It generates a target call tree in a callgrind format.