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

牧云@^-^@ 提交于 2019-11-28 20:36:59

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:

SHELL = ./report_time.sh

and in the file ./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.

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 is a drop-in replacement for make. It generates a target call tree in a callgrind format.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!