downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

apd_breakpoint> <apc_store
[edit] Last updated: Mon, 01 Nov 2010

view this page in

IV. Advanced PHP Debugger (APD)

導入

APD は進化した PHP デバッガです。PHP コードのプロファイリングや デバッグの機能を提供すること、また完全なスタックトレースを出力する 機能を提供することを目的として作成されています。APD は対話形式の デバッグもサポートしていますが、デフォルトではデータをトレース ファイルに書き出すようになっています。また、さまざまなレベルの 情報(関数のコール・渡された引数・時間などを含む)をイベント発生時に 記録することができ、それを個々のスクリプト単位で有効にしたり無効に したりできます。

注意

APD は Zend 拡張モジュールで、PHP 内部関数のコール方法に手を加えます。 そのため、他の Zend 拡張モジュール(たとえば Zend Optimizer など)との 相性に注意が必要です。

インストール手順

現在 APD は PECL 拡張モジュールとして公開されており、 http://pecl.php.net/package/apd で入手可能です。CGI 版の PHP がインストールされており、パスの通った場所に phpize スクリプトがあることを確かめてください。

APD の最新安定バージョンをダウンロード・ビルド・インストールするには 以下のコマンドを実行します。

pear install apd

これは、APD Zend モジュールを自動的に PHP の extension ディレクトリに インストールします。必ずこの場所でなければならないわけではありません。 zend_extension パラメータを適切に設定すれば、PHP が 読み込めるディレクトリならどこにでもインストール可能です。

Windows ユーザは http://snaps.php.net/win32/PECL_STABLE/ から php_apd.dll をダウンロードできます。

INI ファイルに以下の行を追加します。

zend_extension = /absolute/path/to/apd.so
apd.dumpdir = /absolute/path/to/trace/directory
apd.statement_tracing = 0

PHP のビルド状況によって、zend_extension ディレクティブは 以下のうちのいずれかひとつとなります。

zend_extension              (非 ZTS, 非 debug ビルド)
zend_extension_ts           (   ZTS, 非 debug ビルド)
zend_extension_debug        (非 ZTS,    debug ビルド)
zend_extension_debug_ts     (   ZTS,    debug ビルド)

Win32 でのビルド

Windows で APD をビルドするには、http://php.net/ で述べられているような PHP コンパイル環境が必要です。 -- 基本的には、Microsoft Visual C++・ win32build.zip・bison/flex・そしてそれらをうまく動かすためのちょっとした コツが必要になります。また adp.dsp の改行コードは必ず DOS 形式に してください。Unix 形式の改行コードだと、Microsoft Visual C++ に文句を言われます。

実行時設定

php.ini の設定により動作が変化します。

表 1. APD の設定オプション

名前デフォルト変更の可否変更履歴
apd.dumpdirNULLPHP_INI_ALL 
apd.statement_tracing"0"PHP_INI_ALL 
PHP_INI_* 定数の詳細および定義については 付録G を参照してください。

以下に設定ディレクティブに関する 簡単な説明を示します。

apd.dumpdir string

APD がプロファイルのダンプファイルを書き出すディレクトリを設定します。 絶対パス・相対パスのどちらも指定可能です。

apd_set_pprof_trace() へ引数を渡すことで、 指定した以外の場所に書き出すことも可能です。

apd.statement_tracing boolean

行単位のトレースをするかしないかを設定します。これを on (1) にすると、アプリケーションのパフォーマンスに衝撃的な影響を与えます。

リソース型

リソース型は定義されていません。

定義済み定数

定数は定義されていません。

スクリプト中で PHP-APD を使用する方法

  1. トレースを開始するには、PHP スクリプトの最初の行で apd_set_pprof_trace() 関数をコールします。

    apd_set_pprof_trace();

    この行はスクリプト内のどの場所にでも挿入可能ですが、もしスクリプトの 最初からトレースを始めなければ、あなたをパフォーマンスのボトルネックに 導いてくれるかもしれないデータを捨てることになってしまいます。

  2. さあ、スクリプトを実行しましょう。ダンプ結果は apd.dumpdir/pprof_pid.ext に出力されます。

    ティップ: CGI 版の PHP を使用している場合は、apd が正しく動作するように '-e' フラグつきで実行し、拡張情報を有効にしてください。たとえば php -e -f script.php のように実行します。

  3. プロファイルデータを整形して表示するには、お好みの並べ替えオプション・ 表示オプションを指定して pprofp コマンドを実行 してください。整形された出力は以下のようになります。

    bash-2.05b$ pprofp -R /tmp/pprof.22141.0
    
    Trace for /home/dan/testapd.php
    Total Elapsed Time = 0.00
    Total System Time  = 0.00
    Total User Time    = 0.00
    
    
    Real         User        System             secs/    cumm
    %Time (excl/cumm)  (excl/cumm)  (excl/cumm) Calls    call    s/call  Memory Usage Name
    --------------------------------------------------------------------------------------
    100.0 0.00 0.00  0.00 0.00  0.00 0.00     1  0.0000   0.0009            0 main
    56.9 0.00 0.00  0.00 0.00  0.00 0.00     1  0.0005   0.0005            0 apd_set_pprof_trace
    28.0 0.00 0.00  0.00 0.00  0.00 0.00    10  0.0000   0.0000            0 preg_replace
    14.3 0.00 0.00  0.00 0.00  0.00 0.00    10  0.0000   0.0000            0 str_replace

    この例で使われている -R オプションは、その関数を実行するのにかかった時間の 順でプロファイルテーブルを並べ替えます。"cumm call" 列には個々の関数が 何回コールされたか、そして "s/call" 列には 1 回のコールあたりの 平均所要時間が表示されます。

  4. KCacheGrind にインポートできる形式のファイルを作成するには、 pprof2calltree コマンドを実行してください。

連絡先の情報

コメント・バグフィックス・機能拡張・あるいは開発を手伝いたいなどの場合は、 メールを apd@mail.communityconnect.com に送ってください。大歓迎します。

目次
apd_breakpoint -- インタプリタの処理を停止し、ソケットからの CR を待つ
apd_callstack -- 現在のコールスタックを配列で返す
apd_clunk -- 警告とコールスタックをスローする
apd_continue -- インタプリタを再開する
apd_croak -- エラーとコールスタックをスローし、終了する
apd_dump_function_table -- 現在の関数テーブルを出力する
apd_dump_persistent_resources -- すべての持続的なリソースを配列で返す
apd_dump_regular_resources -- 現在のすべての一般リソースを配列で返す
apd_echo -- デバッグ用ソケットに表示する
apd_get_active_symbols -- ローカルスコープ内のカレントの変数名を配列で取得する
apd_set_pprof_trace -- セッションのデバッグを開始する
apd_set_session_trace -- セッションのデバッグを開始する
apd_set_session -- 現在のデバッグレベルを変更あるいは設定する
apd_set_socket_session_trace -- リモートセッションのデバッグを開始する
override_function -- 組み込みの関数を上書きする
rename_function -- グローバルの関数テーブルで関数名を変更する


apd_breakpoint> <apc_store
[edit] Last updated: Mon, 01 Nov 2010
 
add a note add a note User Contributed Notes Advanced PHP Debugger (APD)
northon_patrick3 at yahoo dot ca 26-Jun-2008 08:36
There seem to be a mistake with the name of the apd_set_socket_session_trace function. In the latest build (version 1.0.1) of apd for PHP, the function is called apd_set_session_trace_socket.

The APD pecl page also have some problems. Some of the links direct you to some adt pages.
judas dot iscariote at gmail dot com 07-May-2006 10:52
if you are looking for better/different alternatives to APD, check the xdebug website http://www.xdebug.org or download it from PECL http://pecl.php.net/xdebug
bugbuster at darrencampbell dot com dot au 22-May-2005 01:53
Locate the root-cause of defects, fast.

If you need to locate the source of a defect in complicated web-based PHP applications with lots of conditional includes (osCommerce and Zen-Cart are reasonably complex), use APD to create a profile dump.

Then filter the dump for lines containing "!" to produce a list of included (required) files in the order they were included.

On my Win98 dev box I use: find "!" dumpfile > trace_program.txt

I use the trace_program.txt to backtrack to the root-cause of defects appearing in the browser.  Great for maintaining systems you did not build yourself.
ng4rrjanbiah at rediffmail dot com 05-Apr-2005 10:52
Some useful links on APD:
1. Profiling PHP Applications ( http://www.schlossnagle.org/~george/talks/Profiling-phpworks-2004.pdf ), [1.40 MB], George Schlossnagle, 2004-09-23
2. PHP Performance Profiling ( http://www.linuxjournal.com/article/7213 ), [13.16 KB], Jonathan Oxer, 2003-10-21
3. APD Wiki ( http://www.wiki.cc/php/Apd )

HTH,
R. Rajesh Jeba Anbiah
yoghurtmetperzik at gmail dot com 25-Jan-2005 07:15
If pprofp reports 'No such file or directory', it's probably because it contains an incorrect path to your php client. Open pprofp in your fav editor, edit the first line, and try again.

 
show source | credits | sitemap | contact | advertising | mirror sites