Eclipse3.3.1とTPTP4.4.0.3でTomcatをプロファイリング
Eclipse2.xとか3.0の時代にはEclipse profiler pluginをつかってTomcatのプロファイリングした経験はあったけど、最近はもうなくなっちゃったんですね。かといって、標準の-agent:hprofではやはり使いにくい。ということでEclipseとTPTP(Test and Performance Tools Platform)でTomcatのプロファイリングをしてみることに。
ダウンロード
- Eclipse Downloads | The Eclipse FoundationのEclipse Classic(140MBのやつ)
- Test and Performance Tools Platform All TPTP pluginsのRuntime
tptp.runtime.allInOne.win32.win32.x86-TPTP-4.4.0.3.zip
emf-sdo-xsd-SDK-2.3.1.zip
- Test and Performance Tools Platform Agent ControllerのRuntime
agntctrl.win_ia32-TPTP-4.4.0.3.zip
インストール
>unzip eclipse-SDK-3.3.1-win32.zip >unzip tptp.runtime.allInOne.win32.win32.x86-TPTP-4.4.0.3.zip >mv eclipse c:\eclipse331 >unzip agntctrl.win_ia32-TPTP-4.4.0.3.zip >mv agntctrl.win_ia32-TPTP-4.4.0.3 c:\agntctrl >c:\agntctrl\bin\SetConfig.bat ※すべてENTER >set PATH=%PATH%;c:\agntctrl\bin
動作確認
>c:\agntctrl\bin\ACServer.exe ※別のDOS窓で、 >c:\agntctrl\bin\SampleClient.exe OKならずらずらっと表示される、NGならレスポンスなし
ACSServerはプロファイリングをするときにだけ起動してもよいし、Windowsサービスとして登録することもできる。
Eclipse内のJavaアプリのプロファイリング
これは簡単、
- Eclipse内でプロジェクトを作成してJavaアプリを作成
- メニューからRun→Profile...を選択
- Java Applicationを選択した状態でダイヤログ左上の新規作成アイコンをクリック
- 右ペインのMainタブにプロジェクト名をBrowseして選択、メインクラスをSearchで選択
- 右ペインのMonitorタブにJava Profiling - JRE 1.5 or newerをチェック、サブ項目を適当にチェック(なぜか排他的にしか選択できない。仕様?)
- Applyボタン押し、Profileボタン押すと、Profile用のパースペクティブに自動的に切り替わり、Javaアプリが起動する
- Javaアプリが終わるとプロファイルが停止する。
- 適当にプロファイル結果を見る
リモートでのプロファイリング
本来のやりたかったことはこれ。リモートはTomcatなんかのWebコンテナ上のアプリのプロファイリング。
TPTPのバージョンによってちょこちょこやり方が変わっているのか、モニタリングする対象のJavaアプリ(Tomcatなど)を起動するときのオプションやら環境変数やらの設定に関して、検索で見つけた情報ではなかなかうまくいかない。。。と思っていたら本家のドキュメントにちゃんと書いあった
Archived Projects | The Eclipse Foundation
To run the Java Profiling Agent in standalone mode on Windows, perform the following steps:1. Set TPTP_AC_HOME=<
>
2. Set JAVA_PROFILER_HOME=%TPTP_AC_HOME%\plugins\org.eclipse.tptp.javaprofiler
3. Set PATH=%JAVA_PROFILER_HOME%;%PATH%;%TPTP_AC_HOME%\bin
4. Set PATH=%PATH%;%JAVA_HOME%\bin
5. Execute the Java application with the -agentlib parameter as described above.
手順としては
- ACServer.exeを起動
- Eclipseを起動
- 上記環境変数を設定。
- Tomcatのcatalina.batに以下を追記
set JAVA_OPTS=%JAVA_OPTS% -agentlib:JPIBootLoader=JPIAgent;CGProf
その他設定例として、
-agentlib:JPIBootLoader=JPIAgent;HeapProf:allocsites=true
とかでもよい。AgentContolerのドキュメント参照
- bin\startup.bat
- Tomcatが起動する(通常よりかなり遅い&CPUは起動するまでの間100%)
- メニューからRun→Profile...を選択
- Attach to Agentを選択した状態でダイヤログ左上の新規作成アイコンをクリック
- 右ペインのHostでタブでTest Connectionボタンを押し、一応接続性確認
- 右ペインのAgentsタブでJava Profiling - JRE 1.5 or newerをチェック、サブ項目を適当にチェック(やっぱり排他的にしか選択できない。)
- Applyボタン押し、Profileボタン押すと、Profile用のパースペクティブに自動的に切り替わり、Javaアプリが起動する
- 停止ボタンを押すとプロファイルが停止する。
- 適当にプロファイル結果を見る
まとめ
プロファイリングはさすがに重いです(Tomcatの起動が2秒だったのが1分2分とかかるようになります)。エージングしながらプロファイリングをとるというよりも、特定のシーケンスを1パスでとってみて、どこがボトルネックか調査するという目的だったら、便利に使えそう。それから、TPTPはプロファイリングだけじゃなく、自動的にシーケンス図とか開発とテストに役に立つツールみたいなので、しばらく使ってみようと思います。
参考
以下は残骸
Java6だとどうもうまくいかない。JDKのデモのNotepad.jarでためしてみる。
java -XrunpiAgent:server=enabled -jar Notepad.jar Error occurred during initialization of VM Could not find agent library on the library path or in the local directory: piAgent
ライブラリが参照できない?
set PATH=%PATH%;c:\agntctrl\bin java -XrunpiAgent:server=enabled -jar Notepad.jar FATAL ERROR: JVMPI, an experimental interface, is no longer supported. Please use the supported interface: the JVM Tool Interface (JVM TI). For information on temporary workarounds contact: jvmpi_eol@sun.com Could not resolve to JVMPI interface Error occurred during initialization of VM -Xrun library failed to init: piAgent
JVMPIはダメ、JVMTIを使え?
java -agentlib:JPIBootLoader=JPIAgent:server=enabled -jar Notepad.jar Error occurred during initialization of VM Could not find agent library on the library path or in the local directory: JPIBootLoader
ライブラリが参照できない?
set PATH=%PATH%;c:\agntctrl\bin;c:\agntctrl\plugins\org.eclipse.tptp.javaprofiler java -agentlib:JPIBootLoader=JPIAgent -jar Notepad.jar Error occurred during initialization of VM agent library failed to init: JPIBootLoader
ぜんぜんダメっぽい。JDK1.5だとどうだろう?
set PATH=%PATH%;c:\agntctrl\bin;c:\agntctrl\plugins\org.eclipse.tptp.javaprofiler c:\Program Files\Java\jdk1.5.0_05\bin\java.exe" -XrunpiAgent:server=enabled -jar Notepad.jar 正常起動!
でもeclipseからはモニタリングうまくつながらない感じ。。。