简体   繁体   English

测量(配置文件)在Makefile的每个目标中花费的时间

[英]Measure (profile) time spent in each target of a Makefile

Is there a way to echo the (system, user, real) time spent in each target of a Makefile recursively when I do make all ? 有没有办法在我完成make all时以递归方式回显Makefile中每个目标所花费的时间(系统,用户,实际)?

I'd like to benchmark the compilation of a project in a more granular way than just time make all . 我想以更精细的方式对项目的编译进行基准测试,而不仅仅是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). 如果它可以与-j (并行make)一起使用也会很棒。 And by the way my Makefile is non-recursive (doesn't spawn another make instance for each main targets). 顺便说一句,我的Makefile是非递归的(不会为每个主要目标生成另一个make实例)。

Thanks! 谢谢!

Gnu Make uses the $(SHELL) variable to execute commands in the targets. Gnu Make使用$(SHELL)变量在目标中执行命令。

By default it is set to /bin/sh. 默认情况下,它设置为/ bin / sh。

You can set this variable to a script that will execute the command given with the "time" command. 您可以将此变量设置为将执行使用“time”命令指定的命令的脚本。 Something like this: 像这样的东西:

In your makefile specify the SHELL variable, somewhere at the top: 在你的makefile中,在顶部的某处指定SHELL变量:

SHELL = ./report_time.sh

and in the file ./report_time.sh: 并在文件./report_time.sh中:

#!/bin/sh
shift  # get rid of the '-c' supplied by make.
time sh -c "$*"

The replace the 'sh' command with the original SHELL specified in the Makefile if any. 将'sh'命令替换为Makefile中指定的原始SHELL(如果有)。

This will report the timings. 这将报告时间。

However This will not tell you what target the report_time.sh script is running. 但是,这不会告诉您report_time.sh脚本正在运行的目标。 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. 对此的一个解决方案是在makefile中的每个目标条目中添加目标名称($ @),以便它也将传递给report_time.sh脚本。

remake --profile is a drop-in replacement for make . 翻拍--profilemake替代品。 It generates a target call tree in a callgrind format. 它以callgrind格式生成目标调用树。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM