Devel::NYTProf::Apacheでmod_perl下のCatalystアプリのプロファイリング

mod_perl下でのcatamooseのprofilingをするために、Devel::NYTProf::Apacheを使ってみました。
http://search.cpan.org/~timb/Devel-NYTProf-2.05/lib/Devel/NYTProf/Apache.pm

以下、使い方です。

Apacheの設定

以下の設定をapacheの設定ファイルに追加。

PerlPassEnv NYTPROF
PerlModule Devel::NYTProf::Apache

以下の設定を追加。

MaxClients 1

全体は、例えば以下のような感じです。

<VirtualHost *:80>
    <Perl>
        use lib qw(/var/www/test.example.org/lib);
    </Perl>
    PerlPassEnv NYTPROF
    PerlModule Devel::NYTProf::Apache
    PerlModule MyApp::Web 
    ServerName test.example.org
    ServerAlias www.example.org
    DocumentRoot /var/www/test.techmemo.org/root
    ErrorLog /var/log/apache2/test_example_org-error_log
    CustomLog /var/log/apache2/test_example_org-access_log combined env=!no_log
    <Location />
        SetHandler perl-script
        PerlHandler MyApp::Web 
    </Location>
    <LocationMatch "/(static|favicon.ico)">
        SetHandler default-handler
    </LocationMatch>
</VirtualHost>

測定したいパスにGETリクエストを複数回

プロセスを殺す

/etc/init.d/apache2 stop

該当のプロセスだけ殺すのでも大丈夫です。PerlChildExitHandlerでprofileの終了処理をやっているので、これをやっとかないとダメです。

解析

nytprofhtmlでの解析

nytprofhtml -f /tmp/nytprof.xxx.out.yyy

xxxが親プロセスのID、yyyが子プロセスのID。

プロファイル結果の表示

open nytprof/index.html