我在 ant-contrib 中找到了 ant任务 stopwatch
,但我在那里缺少echo level
和duration format
个参数。
所以我需要以非安静模式启动 ant 来获取stopwatch elapsed
输出(另外还会看到不需要的 ant echo
消息):
<target name="build">
<stopwatch name="foo"/>
<sleep milliseconds="50"/> <!-- do something -->
<echo level="info" message="message not wanted to see normally"/>
<stopwatch name="foo" action="elapsed"/>
</target>
或者我只看到写自己的目标或宏像
<macrodef name="echo-with-time">
<attribute name="message" default="" />
<attribute name="level" default="warning" />
<sequential>
<local name="now"/>
<tstamp><format property="now" pattern="yyyy-MM-dd HH:mm:ss,SSS"/> </tstamp>
<echo level="@{level}" message="[${now}] @{message}" />
</sequential>
</macrodef>
问题:有没有办法仅输出持续时间(比如用时间属性计算)?
答案 0 :(得分:0)
您可以在要计时的事物的开头和结尾使用自定义<scriptdef>
读取当前时间戳,然后使用math
任务计算差异。
这样的事情:
<var name="start" unset="true"/>
<var name="stop" unset="true"/>
<var name="duration" unset="true"/>
<unix-timestamp property="start" />
<!-- Do something to be timed -->
<unix-timestamp property="stop" />
<math result="duration" operand1="${stop}" operation="-" operand2="${start}" datatype="int"/>
<echo message="Task took ${duration} seconds"/>
<unix-timestamp>
在任何受支持的语言中为<scriptdef>
<scriptdef name="unix-timestamp" language="javascript">
<attribute name="property" />
<![CDATA[
var property = attributes.get("property");
var nowSeconds = Math.round(new Date().getTime()/1000);
project.setProperty(property, nowSeconds);
]]>
</scriptdef>