<分区>
有没有办法知道目标执行所需的时间并将该时间存储在 ant 脚本的属性中。我已经检查了 tstamp 和秒表,但没有得到正确的结果。 示例:
<target name ="test">
.....
.....
</target>
我想知道目标“测试”执行所花费的时间。
<分区>
有没有办法知道目标执行所需的时间并将该时间存储在 ant 脚本的属性中。我已经检查了 tstamp 和秒表,但没有得到正确的结果。 示例:
<target name ="test">
.....
.....
</target>
我想知道目标“测试”执行所花费的时间。
最佳答案
您提到了 stopwatch
包含在 Ant Contrib 中的任务.
我使用它没有任何问题。首先,您定义一个秒表并为其分配一个名称。在目标结束时,您使用 total
秒表操作。然后将耗时存储到与创建秒表时使用的名称相同的属性中。
<project name="Stopwatch">
<!--
Import Ant Contrib
-->
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!--
Demonstrates the use of the stopwatch task.
Creates a stopwatch named "timer1", do some work and then take the total
time. The time is then stored in property "timer1".
-->
<target name="teststopwatch">
<stopwatch name="timer1"/>
<echo message="Hello" />
<stopwatch name="timer1" action="total" />
<echo message="Total time: ${timer1}" />
</target>
</project>
输出是:
Buildfile: /home/[...]/StopwatchTest/build_stopwatch.xml
teststopwatch:
[echo] Hello
[stopwatch] [timer1: 0.012 sec]
[echo] Total time: 0.012 sec
BUILD SUCCESSFUL
Total time: 564 milliseconds
关于java - 如何知道目标在 Ant 中执行所花费的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20779141/