测量在Makefile的每个目标中花费的时间(配置文件) [英] Measure (profile) time spent in each target of a Makefile

查看:121
本文介绍了测量在Makefile的每个目标中花费的时间(配置文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行make all时,是否可以递归地回荡在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?

我想用比time make all更细化的方式对项目的编译进行基准测试.理想情况下,它将回显已执行目标的一棵树,每个目标都包含花费在其所有依赖项上的时间.如果它可以与-j(并行make)一起使用,那就太好了.顺便说一下,我的Makefile是非递归的(不会为每个主要目标生成另一个make实例).

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

谢谢!

推荐答案

Gnu Make使用$(SHELL)变量在目标中执行命令.

Gnu Make uses the $(SHELL) variable to execute commands in the targets.

默认情况下,它设置为/bin/sh.

By default it is set to /bin/sh.

您可以将此变量设置为脚本,该脚本将执行"time"命令给定的命令.像这样:

You can set this variable to a script that will execute the command given with the "time" command. Something like this:

在您的makefile文件中,在顶部某处指定SHELL变量:

In your makefile specify the SHELL variable, somewhere at the top:

SHELL = ./report_time.sh

并在文件./report_time.sh中:

and in the file ./report_time.sh:

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

用Makefile中指定的原始SHELL替换"sh"命令(如果有的话).

The replace the 'sh' command with the original SHELL specified in the Makefile if any.

这将报告计时.

但是,这不会告诉您report_time.sh脚本正在运行的目标.一种解决方案是在makefile中的每个目标条目中添加目标名称($ @),以便将其也传递到report_time.sh脚本.

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.

这篇关于测量在Makefile的每个目标中花费的时间(配置文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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