Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know the time taken by a target to execute in ant [duplicate]

Tags:

java

ant

Is there a way to know the time taken by a target to execute and store that time in a property in ant script. I have gone through tstamp and stopwatch but I am not getting the proper result. Example:

 <target name ="test">
   .....
   .....
  </target>

I want to know the time taken to execute by the target "test".

like image 642
izhar Avatar asked Nov 16 '25 22:11

izhar


1 Answers

You mentioned the stopwatch task contained in Ant Contrib.

I had no problems to use it. First you define a stopwatch assigning a name. At the end of the target you use the total stopwatch action. The elapsed time is then stored into a property with the same name you used for creating the stopwatch.

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

Output is:

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
like image 177
vanje Avatar answered Nov 19 '25 11:11

vanje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!