TPTPを使ったリモートプロファイリング

Linux上(CentOS5.0)のTomcatで稼働するアプリケーションにリモートでプロファイリングを行う。

  1. エージェントコントローラのインストール

  • 今回はCentOS5.0を使用しているのでagntctrl.linux_ia32-TPTP-4.4.0.2.zipをダウンロードする。

  • #サーバー上で展開し、任意の場所に配置する

mkdir /usr/local/tptp
cp agntctrl.linux_ia32-TPTP-4.4.0.2.zip /usr/local/tptp/
cd /usr/local/tptp
unzip -o agntctrl.linux_ia32-TPTP-4.4.0.2.zip

  • #エージェントコントローラ用の設定ファイル(serviceconfig.xml)の自動生成

cd /usr/local/tptp/bin
./SetConfig.sh

cd /usr/local/tptp/config
ls
> serviceconfig.xml


  • #エージェントコントローラライブラリへパスを通す

LD_LIBRARY_PATH=/usr/local/tptp/lib
export LD_LIBRARY_PATH

  • #エージェントコントローラ実行ディレクトリへパスを通す

PATH=$PATH:/usr/local/tptp/bin
export PATH

※私は面倒なので/etc/profileに以下のように書き換えました。(書き加えました)
JAVA_HOME=/usr/local/jdk
LD_LIBRARY_PATH=/usr/local/tptp/lib
PATH=$PATH:/usr/local/tptp/bin

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME LD_LIBRARY_PATH

  • #Tomcat起動シェルにエージェントコントローラオプションを加える

cd /usr/local/tomcat/bin/
vi catalina.sh
169行目あたりに以下を追記
JAVA_OPTS="$JAVA_OPTS "-XrunpiAgent:server=enabled

  • #エージェントコントローラの起動

/usr/local/tptp/bin/RAStart.sh

./startup.sh





※発生した問題
・ ダウンロードしたagntctrl.linux_ia32-TPTP-4.4.0.2.zipをPC上(windows)のWinRARで解凍してから
 サーバにアップロードしてACStart.shを試したところ以下のエラー発生。

[root@localhost bin]# ./ACStart.sh
Starting Agent Controller.
ACServer: error while loading shared libraries: ../lib/libtptpUtils.so.4: file too short
ACServer failed to start.

 
 どうやらサーバー上でunzipで展開しないとらしい。



Tomcatを起動してもライブラリへの参照がうまくいかない。
試しにエージェントコントローラを指定してテストプログラムを起動してみると

[root@localhost tmp]# /usr/local/jdk/bin/java -XrunpiAgent TestClass
Error occurred during initialization of VM
Could not find agent library on the library path or in the local directory: piAgent

のエラーが出る。

LD_LIBRARY_PATHはセットしているのに・・・
どうやらlibstdc++というライブラリがインストールされていないらしい。
試しにインストールされているライブラリをlibstdcで検索してみる

[root@localhost bin]# yum search libstdc
Loading "installonlyn" plugin
Setting up repositories
Reading repository metadata in from local files



libstdc++.i386 4.1.1-52.el5 base
Matched from:
libstdc++
The libstdc++ package contains a rewritten standard compliant GCC Standard
C++ Library.



compat-libstdc++-296.i386 2.96-138 base
Matched from:
compat-libstdc++-296
The compat-libstdc++-296 package contains 2.96-RH compatibility standard
C++ libraries.



compat-libstdc++-33.i386 3.2.3-61 base
Matched from:
compat-libstdc++-33
The compat-libstdc++ package contains compatibility standard C++ library
from GCC 3.3.4.



libstdc++-devel.i386 4.1.1-52.el5 base
Matched from:
libstdc++-devel



libstdc++-devel.i386 4.1.1-52.el5.2 updates
Matched from:
libstdc++-devel



libstdc++.i386 4.1.1-52.el5.2 updates
Matched from:
libstdc++
The libstdc++ package contains a rewritten standard compliant GCC Standard
C++ Library.



libstdc++.i386 4.1.1-52.el5.2 installed
Matched from:
libstdc++
The libstdc++ package contains a rewritten standard compliant GCC Standard
C++ Library.




compat-libstdc++-33.i386 3.2.3-61 installed
Matched from:
compat-libstdc++-33
The compat-libstdc++ package contains compatibility standard C++ library
from GCC 3.3.4.




compat-libstdc++-296.i386 2.96-138 installed
Matched from:
compat-libstdc++-296
The compat-libstdc++-296 package contains 2.96-RH compatibility standard
C++ libraries.




libstdc++-devel.i386 4.1.1-52.el5.2 installed



ステータスがinstalledになっていない(baseになっている)ライブラリをインストールしてみる。
yum libstdc++.i386 install
他省略

これで解決しました。





  1. Eclipse側の設定

実行→構成およびプロファイル
開いたウィンドウの左メニューから「接続-Javaプロセス」を選択し、新規作成し以下を設定する

----------------------------------------------------------
ホストタブにリモートホストの設定を追加する
ホスト名またはIPアドレス:アプリケーションが稼働しているサーバーのIP
AgentControllerポート:10002(デフォルト)
エージェントタブ
エージェント欄にJavaProfilingAgentが表示されているので、それのプロセスID(PID)がサーバで稼働しているTomcatプロセスのPIDと一致していることを確認
一致してたら、>をクリックして選択されたエージェント欄に移動させる
モニタータブ
基本メモリー分析と実行時間分析にチェック
----------------------------------------------------------

以上の設定をしたらプロファイルをクリックする

プロファイルおよびロギングパースペクティブに切り替わるので、プロファイルモニタービューで「モニターの開始」をクリックしてモニタリングを開始する
開始したら、基本メモリー分析か実行時間分析を開いて内容を確認する