JProfilerが提供するAntタスクは、Gradleタスクとよくにています。この章では、GradleタスクとのちがいをまとめてAntタスクごとの例を示します。
すべてのAntタスクはアーカイブbin/ant.jarに含まれています。
タスクをAntで使用できるようにするには、まずタスク定義の場所をAntに伝えるtaskdef
要素を挿入する必要があります。以下のすべての例にはそのtaskdefが含まれています。ビルドファイルごとに1回だけ記述し、
project要素の直下の任意の場所に記述できます。
ant.jarアーカイブをAntディストリビューションのlibフォルダにコピーすることはできません。タスク定義ではJProfilerのフルインストールを参照する必要があります。
Antからのプロファイリング
com.jprofiler.ant.ProfileTaskは組み込みのJavaタスクから派生しており、
そのすべての属性とネスト要素をサポートしています。追加の属性は
JavaProfile Gradleタスクと同じです。
Antの属性は大文字・小文字を区別せず、通常は小文字で記述します。複数の値を受け付ける属性には、区切り文字として:または,を使用してください。
<taskdef name="profile"
classname="com.jprofiler.ant.ProfileTask"
classpath="<path to JProfiler installation>/bin/ant.jar"/>
<target name="profile">
<profile classname="MyMainClass" offline="true"
calltreemode="sampling" profile="com.mycorp.:org.example."
snapshotfile="snapshots/run.jps" recording="cpu:allocation:jdbc"
duration="10m">
<classpath>
<fileset dir="lib" includes="*.jar" />
</classpath>
</profile>
</target>
スナップショットからのデータエクスポート
com.jprofiler.ant.ExportTaskを使用すると、Export Gradleタスクと同様に、スナップショットからビューをエクスポートできます。ビューの指定方法はGradleタスクとは異なり、タスク要素の直下にネストして記述し、オプションはネストされたoption要素で指定します。
<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>
スナップショットの比較
com.jprofiler.ant.CompareTaskはCompare
Gradleタスクに対応し、2つ以上のスナップショット間の比較を実行します。com.jprofiler.ant.ExportTaskと同様に、比較は要素の直下にネストして記述し、各comparison要素にオプションをネストします。スナップショットファイルはネストされたファイルセットで指定します。
<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>
ヒープスナップショットの解析
Analyze
Gradleタスクと同様に、Ant向けのcom.jprofiler.ant.AnalyzeTaskは、オフラインプロファイリングで保存されたスナップショット内のヒープスナップショット解析を準備し、GUIでの高速アクセスを可能にします。処理対象のスナップショットはネストされたファイルセットで指定します。
<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>