JProfiler Help

Ant Tasks


The Ant tasks provided by JProfiler are very similar to the Gradle tasks. This chapter highlights the differences to the Gradle tasks and shows examples for each Ant task.

All Ant tasks are contained in the archive bin/ant.jar. In order to make a task available to Ant, you must first insert a taskdef element that tells Ant where to find the task definition. All examples below include that taskdef. It must occur only once per build file and can appear anywhere on the level below the project element.

It is not possible to copy the ant.jar archive to thelib folder of your Ant distribution, you have to reference a full installation of JProfiler in the task definition.

Profiling from Ant

The com.jprofiler.ant.ProfileTask is derived from the built-in Java task and supports all its attributes and nested elements. The additional attributes are the same as for the ProfileJava Gradle task. Ant attributes are case-insensitive and usually written in lower case.

<taskdef name="profile"
         classname="com.jprofiler.ant.ProfileTask"
         classpath="<path to JProfiler installation>/bin/ant.jar"/>

<target name="profile">
  <profile classname="MyMainClass" offline="true" sessionid="80">
    <classpath>
      <fileset dir="lib" includes="*.jar" />
    </classpath>
  </profile>
</target>

Exporting data from snapshots

With the com.jprofiler.ant.ExportTask you can export view from snapshots, just like with the Export Gradle task. Views are specified differently than in the Gradle task: they are nested directly below the task element and options are specified with nested option elements.

<taskdef name="export"
         classname="com.jprofiler.ant.ExportTask"
         classpath="<path to JProfiler installation>/bin/ant.jar"/>

<target name="export">
  <export snapshotfile="snapshots/test.jps">
    <view name="CallTree" file="calltree.html"/>
    <view name="HotSpots" file="hotspots.html">
      <option name="expandbacktraces" value="true"/>
      <option name="aggregation" value="class"/>
    </view>
  </export>
</target>

Comparing snapshots

The com.jprofiler.ant.CompareTask corresponds to the Compare Gradle task and performs comparisons between two ore more snapshots. Like for the com.jprofiler.ant.ExportTask, comparisons are directly nested below the element and options are nested for each comparison element. The snapshot files are specified with a nested file set.

<taskdef name="compare"
         classname="com.jprofiler.ant.CompareTask"
         classpath="<path to JProfiler installation>/bin/ant.jar"/>

<target name="compare">
  <compare sortbytime="true">
    <fileset dir="snapshots">
      <include name="*.jps" />
    </fileset>
    <comparison name="TelemetryHeap" file="heap.html"/>
    <comparison name="TelemetryThreads" file="threads.html">
      <option name="measurements" value="inactive,active"/>
      <option name="valuetype" value="bookmark"/>
      <option name="bookmarkname" value="test"/>
    </comparison>
  </compare>
</target>

Analyzing heap snapshots

Like the Analyze Gradle task, the equivalent com.jprofiler.ant.AnalyzeTask for Ant prepares the heap snapshot analysis in snapshots that have been saved with offline profiling for faster access in the GUI. The snapshots that should be processed are specified with a nested file set.

<taskdef name="analyze"
         classname="com.jprofiler.ant.AnalyzeTask"
         classpath="<path to JProfiler installation>/bin/ant.jar"/>

<target name="analyze">
  <analyze>
    <fileset dir="snapshots" includes="*.jps" />
  </analyze>
</target>